|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2002-2017 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2002-2019 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -16,6 +16,7 @@
|
|
|
|
|
|
package org.springframework.security.config.annotation.method.configuration;
|
|
package org.springframework.security.config.annotation.method.configuration;
|
|
|
|
|
|
|
|
+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.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
@@ -28,17 +29,21 @@ import org.springframework.security.access.method.AbstractMethodSecurityMetadata
|
|
import org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource;
|
|
import org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource;
|
|
import org.springframework.security.access.prepost.PrePostAdviceReactiveMethodInterceptor;
|
|
import org.springframework.security.access.prepost.PrePostAdviceReactiveMethodInterceptor;
|
|
import org.springframework.security.access.prepost.PrePostAnnotationSecurityMetadataSource;
|
|
import org.springframework.security.access.prepost.PrePostAnnotationSecurityMetadataSource;
|
|
|
|
+import org.springframework.security.config.core.GrantedAuthorityDefaults;
|
|
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author Rob Winch
|
|
* @author Rob Winch
|
|
|
|
+ * @author Tadaya Tsuyukubo
|
|
* @since 5.0
|
|
* @since 5.0
|
|
*/
|
|
*/
|
|
@Configuration
|
|
@Configuration
|
|
class ReactiveMethodSecurityConfiguration implements ImportAware {
|
|
class ReactiveMethodSecurityConfiguration implements ImportAware {
|
|
private int advisorOrder;
|
|
private int advisorOrder;
|
|
|
|
|
|
|
|
+ private GrantedAuthorityDefaults grantedAuthorityDefaults;
|
|
|
|
+
|
|
@Bean
|
|
@Bean
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
|
public MethodSecurityMetadataSourceAdvisor methodSecurityInterceptor(AbstractMethodSecurityMetadataSource source) throws Exception {
|
|
public MethodSecurityMetadataSourceAdvisor methodSecurityInterceptor(AbstractMethodSecurityMetadataSource source) throws Exception {
|
|
@@ -49,9 +54,9 @@ class ReactiveMethodSecurityConfiguration implements ImportAware {
|
|
}
|
|
}
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
- public DelegatingMethodSecurityMetadataSource methodMetadataSource() {
|
|
|
|
|
|
+ public DelegatingMethodSecurityMetadataSource methodMetadataSource(MethodSecurityExpressionHandler methodSecurityExpressionHandler) {
|
|
ExpressionBasedAnnotationAttributeFactory attributeFactory = new ExpressionBasedAnnotationAttributeFactory(
|
|
ExpressionBasedAnnotationAttributeFactory attributeFactory = new ExpressionBasedAnnotationAttributeFactory(
|
|
- new DefaultMethodSecurityExpressionHandler());
|
|
|
|
|
|
+ methodSecurityExpressionHandler);
|
|
PrePostAnnotationSecurityMetadataSource prePostSource = new PrePostAnnotationSecurityMetadataSource(
|
|
PrePostAnnotationSecurityMetadataSource prePostSource = new PrePostAnnotationSecurityMetadataSource(
|
|
attributeFactory);
|
|
attributeFactory);
|
|
return new DelegatingMethodSecurityMetadataSource(Arrays.asList(prePostSource));
|
|
return new DelegatingMethodSecurityMetadataSource(Arrays.asList(prePostSource));
|
|
@@ -70,11 +75,21 @@ class ReactiveMethodSecurityConfiguration implements ImportAware {
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
public DefaultMethodSecurityExpressionHandler methodSecurityExpressionHandler() {
|
|
public DefaultMethodSecurityExpressionHandler methodSecurityExpressionHandler() {
|
|
- return new DefaultMethodSecurityExpressionHandler();
|
|
|
|
|
|
+ DefaultMethodSecurityExpressionHandler handler = new DefaultMethodSecurityExpressionHandler();
|
|
|
|
+ if (this.grantedAuthorityDefaults != null) {
|
|
|
|
+ handler.setDefaultRolePrefix(this.grantedAuthorityDefaults.getRolePrefix());
|
|
|
|
+ }
|
|
|
|
+ return handler;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
|
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
|
this.advisorOrder = (int) importMetadata.getAnnotationAttributes(EnableReactiveMethodSecurity.class.getName()).get("order");
|
|
this.advisorOrder = (int) importMetadata.getAnnotationAttributes(EnableReactiveMethodSecurity.class.getName()).get("order");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Autowired(required = false)
|
|
|
|
+ void setGrantedAuthorityDefaults(GrantedAuthorityDefaults grantedAuthorityDefaults) {
|
|
|
|
+ this.grantedAuthorityDefaults = grantedAuthorityDefaults;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|