spring security 角色(ROLE)的继承

栏目: 后端 · 发布时间: 8年前

内容简介:spring security 角色(ROLE)的继承

在实践中,往往各个角色的权限存在某种包含关系。假设系统中角色划分如下:ROLE_supervisor,ROLE_teller,ROLE_user,超级用户拥有出纳的权限。 那边对于拥有超级用户角色的员工,为了对其赋予出纳权限,那么我们可以对其赋予出纳角色;或者我们也可以改变出纳权限的定义,拥有超级用户角色和出纳角色的员工都拥有出纳权限。这两种方法都不够完美,方案一显得冗余,需要对一个员工赋予多个角色,方案二显得角色的权限划分不单一。spring security 角色(ROLE)继承能完美的解决该问题

本文由博主javacoder.cn原创,转载请注明出处

此处示例能更直观的说明问题

<beans:bean id="roleHierarchy"
   class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl">
     <beans:property name="hierarchy">
       <beans:value>
         ROLE_supervisor > ROLE_teller
         ROLE_teller > ROLE_user
       </beans:value>
     </beans:property>
</beans:bean>
 
<beans:bean id="methodExpressionHandler"
    class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
    <beans:property name="roleHierarchy" ref="roleHierarchy" />
</beans:bean>
 
<beans:bean id="expressionHandler"
   class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler">
   <beans:property name="roleHierarchy" ref="roleHierarchy" />
</beans:bean>
 
<global-method-security pre-post-annotations="enabled" >
    <expression-handler ref="methodExpressionHandler"/>
</global-method-security>
 
<http>
   <expression-handler ref="expressionHandler"/>
</http>

RoleHierarchyImpl定义了权限的包含关系,"ROLE_supervisor > ROLE_teller"中的">"表示包含关系。然后定义MethodSecurityExpressionHandler和WebSecurityExpressionHandler bean,最后对<global-method-security >和<http>元素添加<expression-handler>子元素,让其指向定义的SecurityExpressionHandler。

Posted in:Spring Security


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Letting Go of the Words

Letting Go of the Words

Janice (Ginny) Redish / Morgan Kaufmann / 2007-06-11 / USD 49.95

"Redish has done her homework and created a thorough overview of the issues in writing for the Web. Ironically, I must recommend that you read her every word so that you can find out why your customer......一起来看看 《Letting Go of the Words》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器