spring security2认证详解说明
来源:互联网 发布:python应聘有什么要求 编辑:程序博客网 时间:2024/06/06 05:37
配置登录认证的filter
<!--
和servletspec差不多,处理登陆请求 authenticationFailureUrl定义登陆失败时转向的页面
defaultTargetUrl定义登陆成功时转向的页面 filterProcessesUrl定义登陆请求的页面
rememberMeServices用于在验证成功后添加cookie信息
-->
<beanid="authenticationProcessingFilter"
class="com.platform.security.service.filter.UserAuthenticationProcessingFilter">
<propertyname="authenticationManager"
ref="authenticationManager"/>
<propertyname="authenticationFailureUrl">
<value>/login.jsp?login_error=user_psw_error</value>
</property>
<propertyname="filterProcessesUrl">
<value>/j_spring_security_check</value>
</property>
<propertyname="defaultTargetUrl">
<value>/security/index.do</value>
</property>
<propertyname="alwaysUseDefaultTargetUrl">
<value>true</value>
</property>
<propertyname="userManager"ref="userManager"/>
<propertyname="loginDao"ref="loginLogDao"></property>
<propertyname="rememberMeServices"ref="rememberMeServices"/>
<propertyname="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的定义如下:
<beanid="authenticationManager"
class="org.springframework.security.providers.ProviderManager">
<propertyname="providers">
<list>
<reflocal="daoAuthenticationProvider"/>
<reflocal="anonymousAuthenticationProvider"/>
<reflocal="rememberMeAuthenticationProvider"/>
</list>
</property>
<propertyname="sessionController">
<refbean="concurrentSessionController"/>
</property>
</bean>
在这个中定义了具体的认证管理器实现,而其中的
<reflocal="daoAuthenticationProvider"/>
<reflocal="anonymousAuthenticationProvider"/>
<reflocal="rememberMeAuthenticationProvider"/>
是用来进行从数据库里面读取用户等信息进行判断的:
<beanid="daoAuthenticationProvider"
class="org.springframework.security.providers.dao.DaoAuthenticationProvider">
<propertyname="userDetailsService"ref="jdbcDaoImpl"/>
<propertyname="userCache"ref="userCache"/>
<propertyname="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 security2认证详解说明
- spring-security2.0.2初步配置
- spring security2.0.x资料
- Spring security2 登录例子1
- spring security2配置文件学习小结
- spring security2配置文件学习小结
- spring security2学习笔记一(最小配置)
- spring security2 配置精讲(转)
- spring security2【与数据库权限关联】
- Spring配置详解说明
- Spring Security2.0的自带DEMO浅析
- spring security2中如何进行同步session控制
- spring security2中对url进行拦截的配置
- spring security2中对method进行拦截的配置
- Spring Security2的COOKIE的保存时间设置
- 请教关于spring security2.0配置IP,MAC,验证码.
- spring security2学习笔记二(自定义数据结构及登陆页面)
- Spring Security2.0 登录(登出)成功 后置处理
- linux下adb工具的安装
- android 为 ListView Item中的组件添加事件 以及更新数据
- 线程 信号量
- 一个简单的例子来演示将stderr 同时 tee 到文件上
- android editText 输入字数限制
- spring security2认证详解说明
- 异地数据库导入数据内容
- Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法
- ACTIVITY 跳转 通信
- Windows核心编程【2】小结
- Linux_常用命令耗时统计
- 【总结】大规模数据(300万条)测试时,需要注意的问题。
- php定时计划常用实现方法
- 浅议Windows 2000/XP Pagefile组织管理