zoukankan      html  css  js  c++  java
  • 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鉴权使用

  • 相关阅读:
    你自己不优秀,就算认识再多优秀人又有何用
    史玉柱和他老同学的一段故事
    哪有雪中送碳,都是锦上添花
    围城之困
    心已死,梦前行
    一位销售高手逼单经历!
    Python--函数return多个值
    Python--内置函数
    Python--小程序
    Python--递归
  • 原文地址:https://www.cnblogs.com/lodestar/p/2308609.html
Copyright © 2011-2022 走看看