本文分析是基于Spring
SS设计架构是基于Filter过滤器思想,理解SS
如图,对于用户的HTTP请求,首先经过Servlet容器定义的Filter过滤器链进行前处理,然后到达真正进行业务请求处理的Servlet,最后沿反方向通过Filter过滤器链完成后处理后,返回给用户。
Servlet容器级的过滤器在web.xml中定义,由图可看出,web.xml定义了一个特殊的过滤器org.springframework.web.filter.DelegatingFilterProxy(在spring-web
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy<filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain<filter-name>
<url-pattern>/*<url-pattern>
<filter-mapping>
SS最基本配置要素(通常在applicationContext-security.xml中)如下:
<http>
<form-login />
<logout/>
<http>
该配置定义了form表单username/password验证登录方式,登出机制。此时,SS
org.springframework.security.web.context.SecurityContextPersisten
org.springframework.security.web.session.ConcurrentSessionFilter
org.springframework.security.web.authentication.logout.LogoutFilter
org.springframework.security.web.authentication.UsernamePasswordAuthenti
org.springframework.security.web.authentication.ui.DefaultLoginPageGenerati
org.springframework.security.web.savedrequest.RequestCacheAwareFilter
org.springframework.security.web.servletapi.SecurityContextHolderAwa
org.springframework.security.web.authentication.AnonymousAuthenticationF
org.springframework.security.web.session.SessionManagementFilter
org.springframework.security.web.access.ExceptionTranslationFilt
org.springframework.security.web.access.intercept.FilterSecurityIntercepto
每个过滤器都将提供特定的功能,其中比较重要的包括UsernamePasswordAuthenti
SS 3.1总共提供了21个filter,这些filter在SS filter过滤器链中的缺省顺序由org.springframework.security.config.http.SecurityFilters枚举类型定义。通过filter机制,SS实现了安全认证和授权等安全相关工作。用户通过配置文件,可以插入、替换或去除已知的filter,搭配自己的SS filter过滤器链,从而实现满足自己特定应用需求的安全处理。