|
@@ -196,22 +196,25 @@ A typical configuration might look like this:
|
|
[source,java,role="primary"]
|
|
[source,java,role="primary"]
|
|
----
|
|
----
|
|
@Bean
|
|
@Bean
|
|
-AccessDecisionVoter hierarchyVoter() {
|
|
|
|
|
|
+static RoleHierarchy roleHierarchy() {
|
|
RoleHierarchy hierarchy = new RoleHierarchyImpl();
|
|
RoleHierarchy hierarchy = new RoleHierarchyImpl();
|
|
hierarchy.setHierarchy("ROLE_ADMIN > ROLE_STAFF\n" +
|
|
hierarchy.setHierarchy("ROLE_ADMIN > ROLE_STAFF\n" +
|
|
"ROLE_STAFF > ROLE_USER\n" +
|
|
"ROLE_STAFF > ROLE_USER\n" +
|
|
"ROLE_USER > ROLE_GUEST");
|
|
"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
|
|
.Xml
|
|
[source,java,role="secondary"]
|
|
[source,java,role="secondary"]
|
|
----
|
|
----
|
|
-
|
|
|
|
-<bean id="roleVoter" class="org.springframework.security.access.vote.RoleHierarchyVoter">
|
|
|
|
- <constructor-arg ref="roleHierarchy" />
|
|
|
|
-</bean>
|
|
|
|
<bean id="roleHierarchy"
|
|
<bean id="roleHierarchy"
|
|
class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl">
|
|
class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl">
|
|
<property name="hierarchy">
|
|
<property name="hierarchy">
|
|
@@ -222,6 +225,12 @@ AccessDecisionVoter hierarchyVoter() {
|
|
</value>
|
|
</value>
|
|
</property>
|
|
</property>
|
|
</bean>
|
|
</bean>
|
|
|
|
+
|
|
|
|
+<!-- and, if using method security also add -->
|
|
|
|
+<bean id="methodSecurityExpressionHandler"
|
|
|
|
+ class="org.springframework.security.access.expression.method.MethodSecurityExpressionHandler">
|
|
|
|
+ <property ref="roleHierarchy"/>
|
|
|
|
+</bean>
|
|
----
|
|
----
|
|
====
|
|
====
|
|
|
|
|