快速业务通道

实现基于Spring框架应用的权限控制系统 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-24
nManager” class=”org.acegisecurity. providers.ProviderManager”> <property name=”providers”> <list> <ref local=”daoAuthenticationProvider”/> </list> </property> </bean>

授权管理器的配置方法与认证管理器的配置基本类似,这里不再讨论。

实现基于Spring框架应用的权限控制系统(4)

时间:2010-05-21 计算机与信息技术 黎小红

4、安全请求拦截器的配置

以上配置完成后,就需要配置安全拦截器。不同的安全管理对象需要使用不同的安全拦截器。对于方法级的安全认证需要使用的拦截器为MethodSecurityInterceptor,而应用于URL资源的安全拦截器为FilterSecurityInterceptor 。其中,MethodSecurityInterceptor拦截器是借助于Spring Aop实现的,而FilterSecurityInterceptor拦截器是借助于Servlet Filter 实现的。本文以URL资源请求的安全拦截器为例说明配置情况。

由于URL资源请求安全拦截是借助于过滤器进行的。因此首先要配置Acegi Servlet过滤器。过滤器类似于AOP Around装备,实现在web资源调用前后进行的一些操作6种过滤器,他们依次构成Servlet过滤器链,依次处理客户请求。需要注意的是过滤器配置的顺序是不能交换的,当不需要使用某个过滤器时,可直接将其删除和注释。过滤器在web.xml中配置形式为

<filter>  <filter-name>Acegi HTTP Request Security Filter</filter-name>  <filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>  <init-param>   <param-name>targetClass</param-name>   <param-value>    Org.acegisecurity.intercept.web.SecurityEnforcementFilter   </param-value>  </init-param> </filter> <filter-mapping>  <filter-name>Acigi HTTP Request Security Filter</filter-name>  <url-pattern>/*</url-pattern> </filter-mapping>

在spring applicationContext.xml文件中的配置形式为

<bean id=”securityEnforcementFilter” class=””>  <property name=”filterSecurityInterceptor”>   <ref bean=”filterInvocationInteceptor”/>  </property>  <property name=”authenticationEntryPoint”>   <ref bean=”authenticationProcessingFilterEntryPoint”/>  </property>

以上代码是SecurityEnforcementFilter的配置,该过滤器对用户是否有权访问web资源作出最后的决定。其它的过滤器的配置类同。

配置完过滤器后,需要对拦截器FilterSecurityInterceptor进行配置,

<bean id=”filterInvocationInterceptor” Class=””>  <property name=”authenuserCacheticationManager”>1  <property name=”accessDecisionManager”>  <property name=”objectDefinitionSource”>   <ref local="filterObjectDefinitionSource"/>  </property> <bean id="filterObjectDefinitionSource" class="org.xiaohongli.acegi.db.DBFilterObjectDefinitionSource">  <constructor-arg><refbean="jdbcTemplate"/>  </constructor-arg> </bean>

objectDefinitionSource属性定义了那些受保护的URL资源,其中引用了一个本地对象filterObjectDefinitionSource。filterObjectDefinitionSource类从数据库中读取需要保护的URL安全信息,它扩展了PathBasedFilterInvocationDefinition Map类。

同样,实现了另外一个methodObjectDefin

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号