@@ -196,22 +196,25 @@ A typical configuration might look like this:
196
196
[source,java,role="primary"]
197
197
----
198
198
@Bean
199
- AccessDecisionVoter hierarchyVoter () {
199
+ static RoleHierarchy roleHierarchy () {
200
200
RoleHierarchy hierarchy = new RoleHierarchyImpl();
201
201
hierarchy.setHierarchy("ROLE_ADMIN > ROLE_STAFF\n" +
202
202
"ROLE_STAFF > ROLE_USER\n" +
203
203
"ROLE_USER > ROLE_GUEST");
204
- return new RoleHierarchyVoter(hierarchy);
204
+ }
205
+
206
+ // and, if using method security also add
207
+ @Bean
208
+ static MethodSecurityExpressionHandler methodSecurityExpressionHandler(RoleHierarchy roleHierarchy) {
209
+ DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler();
210
+ expressionHandler.setRoleHierarchy(roleHierarchy);
211
+ return expressionHandler;
205
212
}
206
213
----
207
214
208
215
.Xml
209
216
[source,java,role="secondary"]
210
217
----
211
-
212
- <bean id="roleVoter" class="org.springframework.security.access.vote.RoleHierarchyVoter">
213
- <constructor-arg ref="roleHierarchy" />
214
- </bean>
215
218
<bean id="roleHierarchy"
216
219
class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl">
217
220
<property name="hierarchy">
@@ -222,6 +225,12 @@ AccessDecisionVoter hierarchyVoter() {
222
225
</value>
223
226
</property>
224
227
</bean>
228
+
229
+ <!-- and, if using method security also add -->
230
+ <bean id="methodSecurityExpressionHandler"
231
+ class="org.springframework.security.access.expression.method.MethodSecurityExpressionHandler">
232
+ <property ref="roleHierarchy"/>
233
+ </bean>
225
234
----
226
235
====
227
236
0 commit comments