spring security2认证详解说明
2012-04-27 11:50
363 查看
配置登录认证的filter
<!--
和servlet
spec差不多,处理登陆请求 authenticationFailureUrl定义登陆失败时转向的页面
defaultTargetUrl定义登陆成功时转向的页面 filterProcessesUrl定义登陆请求的页面
rememberMeServices用于在验证成功后添加cookie信息
-->
<bean
id="authenticationProcessingFilter"
class="com.platform.security.service.filter.UserAuthenticationProcessingFilter">
<property
name="authenticationManager"
ref="authenticationManager"
/>
<property
name="authenticationFailureUrl">
<value>/login.jsp?login_error=user_psw_error</value>
</property>
<property
name="filterProcessesUrl">
<value>/j_spring_security_check</value>
</property>
<property
name="defaultTargetUrl">
<value>/security/index.do</value>
</property>
<property
name="alwaysUseDefaultTargetUrl">
<value>true</value>
</property>
<property
name="userManager"ref="userManager"
/>
<property
name="loginDao"ref="loginLogDao"></property>
<property
name="rememberMeServices"ref="rememberMeServices"
/>
<property
name="exceptionMappings">
<value>
org.springframework.security.AuthenticationException=/login.jsp?login_error=user_psw_error
org.springframework.security.concurrent.ConcurrentLoginException=/login.jsp?login_error=too_many_user_error
</value>
</property>
</bean>
在这个bean中定义了authenticationManager,具体的是否能够登录的判断就是由authenticationManager来进行的:
authenticationManager的定义如下:
<bean
id="authenticationManager"
class="org.springframework.security.providers.ProviderManager">
<property
name="providers">
<list>
<ref
local="daoAuthenticationProvider"/>
<ref
local="anonymousAuthenticationProvider"/>
<ref
local="rememberMeAuthenticationProvider"/>
</list>
</property>
<property
name="sessionController">
<ref
bean="concurrentSessionController"/>
</property>
</bean>
在这个中定义了具体的认证管理器实现,而其中的
<ref
local="daoAuthenticationProvider"/>
<ref
local="anonymousAuthenticationProvider"/>
<ref
local="rememberMeAuthenticationProvider"/>
是用来进行从数据库里面读取用户等信息进行判断的:
<bean
id="daoAuthenticationProvider"
class="org.springframework.security.providers.dao.DaoAuthenticationProvider">
<property
name="userDetailsService"ref="jdbcDaoImpl"
/>
<property
name="userCache"ref="userCache"
/>
<property
name="passwordEncoder"ref="passwordEncoder"
/>
</bean>
DaoAuthenticationProvider类继承了AbstractUserDetailsAuthenticationProvider类,而进行具体判断的时候,是调用AbstractUserDetailsAuthenticationProvider类中的public
Authenticationauthenticate(Authentication authentication) throws AuthenticationException方法,在该方法中首先会从缓存中去获取用户信息:
UserDetails user = this.userCache.getUserFromCache(username);
如果没有获取到,那么就在调用方法:
user = retrieveUser(username,(UsernamePasswordAuthenticationToken) authentication);去获取用户,在这个方法中会调用在xml文件中配置的userDetailsService来实现获取用户,所以这个userDetailsService也是可以进行自定义的,默认是使用jdbcDaoImpl。
<!--
和servlet
spec差不多,处理登陆请求 authenticationFailureUrl定义登陆失败时转向的页面
defaultTargetUrl定义登陆成功时转向的页面 filterProcessesUrl定义登陆请求的页面
rememberMeServices用于在验证成功后添加cookie信息
-->
<bean
id="authenticationProcessingFilter"
class="com.platform.security.service.filter.UserAuthenticationProcessingFilter">
<property
name="authenticationManager"
ref="authenticationManager"
/>
<property
name="authenticationFailureUrl">
<value>/login.jsp?login_error=user_psw_error</value>
</property>
<property
name="filterProcessesUrl">
<value>/j_spring_security_check</value>
</property>
<property
name="defaultTargetUrl">
<value>/security/index.do</value>
</property>
<property
name="alwaysUseDefaultTargetUrl">
<value>true</value>
</property>
<property
name="userManager"ref="userManager"
/>
<property
name="loginDao"ref="loginLogDao"></property>
<property
name="rememberMeServices"ref="rememberMeServices"
/>
<property
name="exceptionMappings">
<value>
org.springframework.security.AuthenticationException=/login.jsp?login_error=user_psw_error
org.springframework.security.concurrent.ConcurrentLoginException=/login.jsp?login_error=too_many_user_error
</value>
</property>
</bean>
在这个bean中定义了authenticationManager,具体的是否能够登录的判断就是由authenticationManager来进行的:
authenticationManager的定义如下:
<bean
id="authenticationManager"
class="org.springframework.security.providers.ProviderManager">
<property
name="providers">
<list>
<ref
local="daoAuthenticationProvider"/>
<ref
local="anonymousAuthenticationProvider"/>
<ref
local="rememberMeAuthenticationProvider"/>
</list>
</property>
<property
name="sessionController">
<ref
bean="concurrentSessionController"/>
</property>
</bean>
在这个中定义了具体的认证管理器实现,而其中的
<ref
local="daoAuthenticationProvider"/>
<ref
local="anonymousAuthenticationProvider"/>
<ref
local="rememberMeAuthenticationProvider"/>
是用来进行从数据库里面读取用户等信息进行判断的:
<bean
id="daoAuthenticationProvider"
class="org.springframework.security.providers.dao.DaoAuthenticationProvider">
<property
name="userDetailsService"ref="jdbcDaoImpl"
/>
<property
name="userCache"ref="userCache"
/>
<property
name="passwordEncoder"ref="passwordEncoder"
/>
</bean>
DaoAuthenticationProvider类继承了AbstractUserDetailsAuthenticationProvider类,而进行具体判断的时候,是调用AbstractUserDetailsAuthenticationProvider类中的public
Authenticationauthenticate(Authentication authentication) throws AuthenticationException方法,在该方法中首先会从缓存中去获取用户信息:
UserDetails user = this.userCache.getUserFromCache(username);
如果没有获取到,那么就在调用方法:
user = retrieveUser(username,(UsernamePasswordAuthenticationToken) authentication);去获取用户,在这个方法中会调用在xml文件中配置的userDetailsService来实现获取用户,所以这个userDetailsService也是可以进行自定义的,默认是使用jdbcDaoImpl。
相关文章推荐
- 详解Spring Security进阶身份认证之UserDetailsService(附源码)
- Spring Security 入门(1-4-2)Spring Security - 认证过程之AuthenticationProvider的扩展补充说明
- Spring Security笔记:HTTP Basic 认证
- web.xml文件配置详解以及实例说明
- SSL单向/双向认证详解
- ASP.NET Forms身份认证详解
- WS Security 认证方式详解
- Spring Security笔记:使用数据库进行用户认证(form login using database)
- Spring Security 实现身份认证
- javascript中的prototype方法使用说明(详解)
- AAA之802.1x认证详解(二)
- JAVA-WBE——spring security 3.2 认证-学习笔记2
- 详解Spring Boot实战之Filter实现使用JWT进行接口认证
- mysql服务性能优化—my.cnf配置说明详解(16G内存)
- linux wget 命令用法详解(附实例说明)
- Linux ps命令详解与示例说明
- CSS3选择器详解实例说明
- FTP命令详解以及二进制上传说明
- 浏览器缓存详解详细说明
- squid配置详解+认证教程