|
8 | 8 | import org.springframework.context.ApplicationEventPublisher; |
9 | 9 | import org.springframework.context.annotation.Bean; |
10 | 10 | import org.springframework.context.annotation.Configuration; |
11 | | -import org.springframework.security.access.expression.SecurityExpressionHandler; |
12 | 11 | import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler; |
13 | 12 | import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; |
14 | 13 | import org.springframework.security.access.hierarchicalroles.RoleHierarchy; |
|
23 | 22 | import org.springframework.security.core.userdetails.UserDetailsService; |
24 | 23 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
25 | 24 | import org.springframework.security.crypto.password.PasswordEncoder; |
26 | | -import org.springframework.security.web.FilterInvocation; |
27 | 25 | import org.springframework.security.web.SecurityFilterChain; |
28 | | -import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler; |
29 | 26 | import org.springframework.security.web.session.HttpSessionEventPublisher; |
30 | 27 | import com.digitalsanctuary.spring.user.roles.RolesAndPrivilegesConfig; |
31 | 28 | import com.digitalsanctuary.spring.user.service.DSOAuth2UserService; |
@@ -279,28 +276,16 @@ public RoleHierarchy roleHierarchy() { |
279 | 276 | return roleHierarchy; |
280 | 277 | } |
281 | 278 |
|
282 | | - /** |
283 | | - * The webExpressionHandler method creates a DefaultWebSecurityExpressionHandler object and sets the roleHierarchy for the handler. |
284 | | - * |
285 | | - * @return the DefaultWebSecurityExpressionHandler object |
286 | | - */ |
287 | | - @Bean |
288 | | - public SecurityExpressionHandler<FilterInvocation> webExpressionHandler() { |
289 | | - DefaultWebSecurityExpressionHandler defaultWebSecurityExpressionHandler = new DefaultWebSecurityExpressionHandler(); |
290 | | - defaultWebSecurityExpressionHandler.setRoleHierarchy(roleHierarchy()); |
291 | | - return defaultWebSecurityExpressionHandler; |
292 | | - } |
293 | | - |
294 | 279 | /** |
295 | 280 | * The methodSecurityExpressionHandler method creates a MethodSecurityExpressionHandler object and sets the roleHierarchy for the handler. This |
296 | 281 | * ensures that method security annotations like @PreAuthorize use the configured role hierarchy. |
297 | 282 | * |
298 | 283 | * @return the MethodSecurityExpressionHandler object |
299 | 284 | */ |
300 | 285 | @Bean |
301 | | - public MethodSecurityExpressionHandler methodSecurityExpressionHandler() { |
| 286 | + static MethodSecurityExpressionHandler methodSecurityExpressionHandler(RoleHierarchy roleHierarchy) { |
302 | 287 | DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler(); |
303 | | - expressionHandler.setRoleHierarchy(roleHierarchy()); |
| 288 | + expressionHandler.setRoleHierarchy(roleHierarchy); |
304 | 289 | return expressionHandler; |
305 | 290 | } |
306 | 291 |
|
|
0 commit comments