Spring Security 3学习笔记
??? Step 3: 在Spring Security配置文件中添加如下配置????????????????
?
B. Example 2 - 自定义认证管理器和决策管理器(通过插入自定义的过滤器来实现, 实现灵活和复杂的认证授权管理)
??? Step 1: web.xml中的配置无特别之处, 参考上面的关键步骤1
??? Step 2: 在Spring Security配置文件中添加类似如下配置
???
?
??? Step 3:?登录页面login.jsp
????
?
??? Step 3: 在Spring Security配置文件中添加类似如下配置
???
authenticationManager" />
<beans:property name="accessDecisionManager" ref="PmAccessDecisionManagerBean" />
<beans:property name="securityMetadataSource" ref="securityMetadataSource" />
</beans:bean>
<!-- 认证管理器authenticationManager,实现用户认证的入口,主要实现UserDetailsService接口即可 -->
<authentication-manager alias="authenticationManager">
<authentication-provider user-service-ref="PmUserDetailService">
<!-- 如果用户的密码采用加密的话,可以加点“盐” --><password-encoder hash="sha" />
</authentication-provider>
</authentication-manager>
<beans:bean id="PmUserDetailService" />
<!-- 访问决策器accessDecisionManager,决定某个用户具有的角色,是否有足够的权限去访问某个资源 -->
<beans:bean id="PmAccessDecisionManagerBean" />???
??? Step 4:?实现custom-filter、authentication-provider、accessDecisionManager、securityMetadataSource
???????????????? 例子分别如下:PmFilterSecurityInterceptor、PmUserDetailService、PmAccessDecisionManager、PmInvocationSecurityMetadataSource
???????????????? PmFilterSecurityInterceptor: 拦截器,是进行认证授权处理的起点;
???????????????? PmUserDetailService:认证(authentication)信息加载,用户基本信息(密码、权限等)加载;
?????????????????PmAccessDecisionManager:授权(authorization),对当前用户的实际ROLE和访问当前资源所需要的ROLE进行比较,如果符合,正常返回;否则,抛出异常;
???????????????? PmInvocationSecurityMetadataSource: 授权(authorization)信息加载,加载资源(URI)和ROLE的对应关系,提供方法getAttributes(), 这个方法根据URL得到访问该URL应该拥有的ROLE集合;
????????????????
??? Step 5: 实现URL和访问权限的对应关系,实际代码是实现在PmInvocationSecurityMetadataSource的loadResourceDefine()?方法中 (这个方法的代码如何实现,直接关系到访问权限配置的格式)
?
3?Key points:
??? i. login form的action属性值, user name, password字段名要符合spring security framework要求;
??? ii. 认证(authentication)信息加载在UserDetailService中实现;
????iii. 对每个资源URI的权限控制设置,配置在spring security配置文件中.
?
?
P.S. 网上的一篇spring security详解教程,觉得不错,转过来
http://ljx1619.iteye.com/blog/468166?
?