Skip to content

Commit

Permalink
Update RoleHierarchy Docs
Browse files Browse the repository at this point in the history
Closes gh-12766
  • Loading branch information
jzheaux committed Feb 24, 2023
1 parent f5a4b52 commit eac1f84
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions docs/modules/ROOT/pages/servlet/authorization/architecture.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,25 @@ A typical configuration might look like this:
[source,java,role="primary"]
----
@Bean
AccessDecisionVoter hierarchyVoter() {
static RoleHierarchy roleHierarchy() {
RoleHierarchy hierarchy = new RoleHierarchyImpl();
hierarchy.setHierarchy("ROLE_ADMIN > ROLE_STAFF\n" +
"ROLE_STAFF > ROLE_USER\n" +
"ROLE_USER > ROLE_GUEST");
return new RoleHierarchyVoter(hierarchy);
}
// and, if using method security also add
@Bean
static MethodSecurityExpressionHandler methodSecurityExpressionHandler(RoleHierarchy roleHierarchy) {
DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler();
expressionHandler.setRoleHierarchy(roleHierarchy);
return expressionHandler;
}
----
.Xml
[source,java,role="secondary"]
----
<bean id="roleVoter" class="org.springframework.security.access.vote.RoleHierarchyVoter">
<constructor-arg ref="roleHierarchy" />
</bean>
<bean id="roleHierarchy"
class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl">
<property name="hierarchy">
Expand All @@ -222,6 +225,12 @@ AccessDecisionVoter hierarchyVoter() {
</value>
</property>
</bean>
<!-- and, if using method security also add -->
<bean id="methodSecurityExpressionHandler"
class="org.springframework.security.access.expression.method.MethodSecurityExpressionHandler">
<property ref="roleHierarchy"/>
</bean>
----
====

Expand Down

0 comments on commit eac1f84

Please sign in to comment.