|
@@ -17,8 +17,11 @@
|
|
package org.springframework.security.config.annotation.method.configuration;
|
|
package org.springframework.security.config.annotation.method.configuration;
|
|
|
|
|
|
import org.springframework.aop.Advisor;
|
|
import org.springframework.aop.Advisor;
|
|
|
|
+import org.springframework.beans.BeansException;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.config.BeanDefinition;
|
|
import org.springframework.beans.factory.config.BeanDefinition;
|
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
|
+import org.springframework.context.ApplicationContextAware;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Role;
|
|
import org.springframework.context.annotation.Role;
|
|
@@ -42,7 +45,7 @@ import org.springframework.security.config.core.GrantedAuthorityDefaults;
|
|
*/
|
|
*/
|
|
@Configuration(proxyBeanMethods = false)
|
|
@Configuration(proxyBeanMethods = false)
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
|
-final class PrePostMethodSecurityConfiguration {
|
|
|
|
|
|
+final class PrePostMethodSecurityConfiguration implements ApplicationContextAware {
|
|
|
|
|
|
private final PreFilterAuthorizationMethodInterceptor preFilterAuthorizationMethodInterceptor = new PreFilterAuthorizationMethodInterceptor();
|
|
private final PreFilterAuthorizationMethodInterceptor preFilterAuthorizationMethodInterceptor = new PreFilterAuthorizationMethodInterceptor();
|
|
|
|
|
|
@@ -52,29 +55,43 @@ final class PrePostMethodSecurityConfiguration {
|
|
|
|
|
|
private final PostFilterAuthorizationMethodInterceptor postFilterAuthorizationMethodInterceptor = new PostFilterAuthorizationMethodInterceptor();
|
|
private final PostFilterAuthorizationMethodInterceptor postFilterAuthorizationMethodInterceptor = new PostFilterAuthorizationMethodInterceptor();
|
|
|
|
|
|
|
|
+ private final DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler();
|
|
|
|
+
|
|
private boolean customMethodSecurityExpressionHandler = false;
|
|
private boolean customMethodSecurityExpressionHandler = false;
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
|
Advisor preFilterAuthorizationMethodInterceptor() {
|
|
Advisor preFilterAuthorizationMethodInterceptor() {
|
|
|
|
+ if (!this.customMethodSecurityExpressionHandler) {
|
|
|
|
+ this.preAuthorizeAuthorizationManager.setExpressionHandler(this.expressionHandler);
|
|
|
|
+ }
|
|
return this.preFilterAuthorizationMethodInterceptor;
|
|
return this.preFilterAuthorizationMethodInterceptor;
|
|
}
|
|
}
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
|
Advisor preAuthorizeAuthorizationMethodInterceptor() {
|
|
Advisor preAuthorizeAuthorizationMethodInterceptor() {
|
|
|
|
+ if (!this.customMethodSecurityExpressionHandler) {
|
|
|
|
+ this.preAuthorizeAuthorizationManager.setExpressionHandler(this.expressionHandler);
|
|
|
|
+ }
|
|
return AuthorizationManagerBeforeMethodInterceptor.preAuthorize(this.preAuthorizeAuthorizationManager);
|
|
return AuthorizationManagerBeforeMethodInterceptor.preAuthorize(this.preAuthorizeAuthorizationManager);
|
|
}
|
|
}
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
|
Advisor postAuthorizeAuthorizationMethodInterceptor() {
|
|
Advisor postAuthorizeAuthorizationMethodInterceptor() {
|
|
|
|
+ if (!this.customMethodSecurityExpressionHandler) {
|
|
|
|
+ this.postAuthorizeAuthorizationManager.setExpressionHandler(this.expressionHandler);
|
|
|
|
+ }
|
|
return AuthorizationManagerAfterMethodInterceptor.postAuthorize(this.postAuthorizeAuthorizationManager);
|
|
return AuthorizationManagerAfterMethodInterceptor.postAuthorize(this.postAuthorizeAuthorizationManager);
|
|
}
|
|
}
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
|
Advisor postFilterAuthorizationMethodInterceptor() {
|
|
Advisor postFilterAuthorizationMethodInterceptor() {
|
|
|
|
+ if (!this.customMethodSecurityExpressionHandler) {
|
|
|
|
+ this.postFilterAuthorizationMethodInterceptor.setExpressionHandler(this.expressionHandler);
|
|
|
|
+ }
|
|
return this.postFilterAuthorizationMethodInterceptor;
|
|
return this.postFilterAuthorizationMethodInterceptor;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -89,15 +106,12 @@ final class PrePostMethodSecurityConfiguration {
|
|
|
|
|
|
@Autowired(required = false)
|
|
@Autowired(required = false)
|
|
void setGrantedAuthorityDefaults(GrantedAuthorityDefaults grantedAuthorityDefaults) {
|
|
void setGrantedAuthorityDefaults(GrantedAuthorityDefaults grantedAuthorityDefaults) {
|
|
- if (this.customMethodSecurityExpressionHandler) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler();
|
|
|
|
- expressionHandler.setDefaultRolePrefix(grantedAuthorityDefaults.getRolePrefix());
|
|
|
|
- this.preFilterAuthorizationMethodInterceptor.setExpressionHandler(expressionHandler);
|
|
|
|
- this.preAuthorizeAuthorizationManager.setExpressionHandler(expressionHandler);
|
|
|
|
- this.postAuthorizeAuthorizationManager.setExpressionHandler(expressionHandler);
|
|
|
|
- this.postFilterAuthorizationMethodInterceptor.setExpressionHandler(expressionHandler);
|
|
|
|
|
|
+ this.expressionHandler.setDefaultRolePrefix(grantedAuthorityDefaults.getRolePrefix());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setApplicationContext(ApplicationContext context) throws BeansException {
|
|
|
|
+ this.expressionHandler.setApplicationContext(context);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|