Skip to content

Commit a43677d

Browse files
committed
Simplify PrePostMethodSecurityConfiguration
Issue gh-9288
1 parent c73bd47 commit a43677d

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

config/src/main/java/org/springframework/security/config/annotation/method/configuration/PrePostMethodSecurityConfiguration.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,55 +49,55 @@ final class PrePostMethodSecurityConfiguration implements ApplicationContextAwar
4949

5050
private final PreFilterAuthorizationMethodInterceptor preFilterAuthorizationMethodInterceptor = new PreFilterAuthorizationMethodInterceptor();
5151

52+
private final AuthorizationManagerBeforeMethodInterceptor preAuthorizeAuthorizationMethodInterceptor;
53+
5254
private final PreAuthorizeAuthorizationManager preAuthorizeAuthorizationManager = new PreAuthorizeAuthorizationManager();
5355

56+
private final AuthorizationManagerAfterMethodInterceptor postAuthorizeAuthorizaitonMethodInterceptor;
57+
5458
private final PostAuthorizeAuthorizationManager postAuthorizeAuthorizationManager = new PostAuthorizeAuthorizationManager();
5559

5660
private final PostFilterAuthorizationMethodInterceptor postFilterAuthorizationMethodInterceptor = new PostFilterAuthorizationMethodInterceptor();
5761

5862
private final DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler();
5963

60-
private boolean customMethodSecurityExpressionHandler = false;
64+
PrePostMethodSecurityConfiguration() {
65+
this.preAuthorizeAuthorizationManager.setExpressionHandler(this.expressionHandler);
66+
this.preAuthorizeAuthorizationMethodInterceptor = AuthorizationManagerBeforeMethodInterceptor
67+
.preAuthorize(this.preAuthorizeAuthorizationManager);
68+
this.postAuthorizeAuthorizationManager.setExpressionHandler(this.expressionHandler);
69+
this.postAuthorizeAuthorizaitonMethodInterceptor = AuthorizationManagerAfterMethodInterceptor
70+
.postAuthorize(this.postAuthorizeAuthorizationManager);
71+
this.preFilterAuthorizationMethodInterceptor.setExpressionHandler(this.expressionHandler);
72+
this.postFilterAuthorizationMethodInterceptor.setExpressionHandler(this.expressionHandler);
73+
}
6174

6275
@Bean
6376
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
6477
Advisor preFilterAuthorizationMethodInterceptor() {
65-
if (!this.customMethodSecurityExpressionHandler) {
66-
this.preAuthorizeAuthorizationManager.setExpressionHandler(this.expressionHandler);
67-
}
6878
return this.preFilterAuthorizationMethodInterceptor;
6979
}
7080

7181
@Bean
7282
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
7383
Advisor preAuthorizeAuthorizationMethodInterceptor() {
74-
if (!this.customMethodSecurityExpressionHandler) {
75-
this.preAuthorizeAuthorizationManager.setExpressionHandler(this.expressionHandler);
76-
}
77-
return AuthorizationManagerBeforeMethodInterceptor.preAuthorize(this.preAuthorizeAuthorizationManager);
84+
return this.preAuthorizeAuthorizationMethodInterceptor;
7885
}
7986

8087
@Bean
8188
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
8289
Advisor postAuthorizeAuthorizationMethodInterceptor() {
83-
if (!this.customMethodSecurityExpressionHandler) {
84-
this.postAuthorizeAuthorizationManager.setExpressionHandler(this.expressionHandler);
85-
}
86-
return AuthorizationManagerAfterMethodInterceptor.postAuthorize(this.postAuthorizeAuthorizationManager);
90+
return this.postAuthorizeAuthorizaitonMethodInterceptor;
8791
}
8892

8993
@Bean
9094
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
9195
Advisor postFilterAuthorizationMethodInterceptor() {
92-
if (!this.customMethodSecurityExpressionHandler) {
93-
this.postFilterAuthorizationMethodInterceptor.setExpressionHandler(this.expressionHandler);
94-
}
9596
return this.postFilterAuthorizationMethodInterceptor;
9697
}
9798

9899
@Autowired(required = false)
99100
void setMethodSecurityExpressionHandler(MethodSecurityExpressionHandler methodSecurityExpressionHandler) {
100-
this.customMethodSecurityExpressionHandler = true;
101101
this.preFilterAuthorizationMethodInterceptor.setExpressionHandler(methodSecurityExpressionHandler);
102102
this.preAuthorizeAuthorizationManager.setExpressionHandler(methodSecurityExpressionHandler);
103103
this.postAuthorizeAuthorizationManager.setExpressionHandler(methodSecurityExpressionHandler);

0 commit comments

Comments
 (0)