acegi安全框架使用

acegi安全框架使用:第二部分

二、dbms实现鉴权
1.dbms鉴权,修改FilterSecurityInterceptor中的objectDefinitionSource属性,注入rdbmsFilterInvocationDefinitionSource,可加入Ehcahe提高性能
<!-- 权限过滤,基于URL的过滤器,使用RDBMS和Ehcache实现 -->
 <bean id="securityInterceptor"
class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
<!-- 修改默认值,防止没有授权的角色导致的错误 -->
<property name="validateConfigAttributes" value="true" />
<property name="authenticationManager" ref="authenticationManager" />
<property name="accessDecisionManager" ref="accessDecisionManager" />
<property name="objectDefinitionSource" ref="rdbmsFilterInvocationDefinitionSource" />
</bean>
<bean id="rdbmsFilterInvocationDefinitionSource" class="com.hengtian.security.RdbmsFilterInvocationDefinitionSource">
<property name="dataSource" ref="dataSource" />
<property name="webresdbCache" ref="webresCacheBackend" />
</bean>

<bean id="webresCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager" ref="cacheManager" />
<property name="cacheName">
<value>webresdbCache</value>
</property>
</bean>

RdbmsFilterInvocationDefinitionSource是objectDefinitionSource的dbms实现,这个要自己实现


2.aop实现方法过滤
如果不想对action,url等资源过滤,也可对调用方法过滤,实现特定角色只能实现特定方法。在applicationContext.xml中配置,注意这里是用BeanNameAutoProxyCreator实现aop的.
<bean id="serviceSecurityInterceptor"
class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
<property name="validateConfigAttributes" value="true" /> <property
name="authenticationManager" ref="authenticationManager" /> <property
name="accessDecisionManager" ref="accessDecisionManager" /> <property
name="objectDefinitionSource"> <value>
com.role.action.RoleAction.operateRole=ROLE_ADMIN </value> </property>
</bean>


<bean id="serviceSecurityInterceptor"
class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
<property name="validateConfigAttributes" value="true" />
<property name="authenticationManager" ref="authenticationManager" />
<property name="accessDecisionManager" ref="accessDecisionManager" />
<property name="objectDefinitionSource" ref="rdbmsMethodDefinitionSource" />
</bean>
<bean id="rdbmsMethodDefinitionSource" class="com.hengtian.security.RdbmsMethodDefinitionSource">
<property name="dataSource" ref="dataSource" />
<property name="webresdbCache" ref="webresCacheBackend" />
</bean>
<bean id="webresCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager" ref="cacheManager" />
<property name="cacheName">
<value>webresdbCache</value>
</property>
</bean>

<bean id="autoProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="interceptorNames">
<list>
<value>serviceSecurityInterceptor</value>
</list>
</property>
<property name="beanNames">
<list>
<value>*Action</value>
</list>
</property>
</bean>


3.表结构设置
按照常规的权限模型设计:用户表、角色表、用户角色关系表、角色功能关系表;系统表、模块表、菜单表、按钮表、按钮资源表(在一个操作做个url的情况使用)
权限这块的表结构所有的系统都查不多,这里只是在功能表里面多加上了url字段。对外显示为特定角色有执行某模块、某菜单、界面中的某个按钮的权限,对内则是某个角色和action的映射关系供acegi鉴权使用
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值