mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-01 09:42:13 +00:00
Only Register as Advisor in Proxy Mode
Closes gh-13160
This commit is contained in:
parent
219faf29d4
commit
35ad1f857e
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2023 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,7 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.security.config.annotation.method.configuration;
|
package org.springframework.security.config.annotation.method.configuration;
|
||||||
|
|
||||||
import org.springframework.aop.Advisor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
|
|
||||||
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.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@ -47,7 +48,7 @@ final class Jsr250MethodSecurityConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||||
Advisor jsr250AuthorizationMethodInterceptor() {
|
MethodInterceptor jsr250AuthorizationMethodInterceptor() {
|
||||||
AuthorizationManagerBeforeMethodInterceptor interceptor = AuthorizationManagerBeforeMethodInterceptor
|
AuthorizationManagerBeforeMethodInterceptor interceptor = AuthorizationManagerBeforeMethodInterceptor
|
||||||
.jsr250(this.jsr250AuthorizationManager);
|
.jsr250(this.jsr250AuthorizationManager);
|
||||||
interceptor.setSecurityContextHolderStrategy(this.securityContextHolderStrategy);
|
interceptor.setSecurityContextHolderStrategy(this.securityContextHolderStrategy);
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2002-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.security.config.annotation.method.configuration;
|
||||||
|
|
||||||
|
import org.springframework.aop.Advisor;
|
||||||
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
|
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||||
|
import org.springframework.core.type.AnnotationMetadata;
|
||||||
|
|
||||||
|
class MethodSecurityAdvisorRegistrar implements ImportBeanDefinitionRegistrar {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
|
||||||
|
registerAsAdvisor("preFilterAuthorization", registry);
|
||||||
|
registerAsAdvisor("preAuthorizeAuthorization", registry);
|
||||||
|
registerAsAdvisor("postFilterAuthorization", registry);
|
||||||
|
registerAsAdvisor("postAuthorizeAuthorization", registry);
|
||||||
|
registerAsAdvisor("securedAuthorization", registry);
|
||||||
|
registerAsAdvisor("jsr250Authorization", registry);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerAsAdvisor(String prefix, BeanDefinitionRegistry registry) {
|
||||||
|
String interceptorName = prefix + "MethodInterceptor";
|
||||||
|
if (!registry.containsBeanDefinition(interceptorName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BeanDefinition definition = registry.getBeanDefinition(interceptorName);
|
||||||
|
if (!(definition instanceof RootBeanDefinition)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RootBeanDefinition advisor = new RootBeanDefinition((RootBeanDefinition) definition);
|
||||||
|
advisor.setTargetType(Advisor.class);
|
||||||
|
registry.registerBeanDefinition(prefix + "Advisor", advisor);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2023 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.
|
||||||
@ -60,7 +60,8 @@ final class MethodSecuritySelector implements ImportSelector {
|
|||||||
|
|
||||||
private static final class AutoProxyRegistrarSelector extends AdviceModeImportSelector<EnableMethodSecurity> {
|
private static final class AutoProxyRegistrarSelector extends AdviceModeImportSelector<EnableMethodSecurity> {
|
||||||
|
|
||||||
private static final String[] IMPORTS = new String[] { AutoProxyRegistrar.class.getName() };
|
private static final String[] IMPORTS = new String[] { AutoProxyRegistrar.class.getName(),
|
||||||
|
MethodSecurityAdvisorRegistrar.class.getName() };
|
||||||
|
|
||||||
private static final String[] ASPECTJ_IMPORTS = new String[] {
|
private static final String[] ASPECTJ_IMPORTS = new String[] {
|
||||||
MethodSecurityAspectJAutoProxyRegistrar.class.getName() };
|
MethodSecurityAspectJAutoProxyRegistrar.class.getName() };
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2023 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,8 @@
|
|||||||
|
|
||||||
package org.springframework.security.config.annotation.method.configuration;
|
package org.springframework.security.config.annotation.method.configuration;
|
||||||
|
|
||||||
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
|
|
||||||
import org.springframework.aop.Advisor;
|
import org.springframework.aop.Advisor;
|
||||||
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;
|
||||||
@ -80,19 +82,19 @@ final class PrePostMethodSecurityConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||||
Advisor preFilterAuthorizationMethodInterceptor() {
|
MethodInterceptor preFilterAuthorizationMethodInterceptor() {
|
||||||
return this.preFilterAuthorizationMethodInterceptor;
|
return this.preFilterAuthorizationMethodInterceptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||||
Advisor preAuthorizeAuthorizationMethodInterceptor() {
|
MethodInterceptor preAuthorizeAuthorizationMethodInterceptor() {
|
||||||
return this.preAuthorizeAuthorizationMethodInterceptor;
|
return this.preAuthorizeAuthorizationMethodInterceptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||||
Advisor postAuthorizeAuthorizationMethodInterceptor() {
|
MethodInterceptor postAuthorizeAuthorizationMethodInterceptor() {
|
||||||
return this.postAuthorizeAuthorizaitonMethodInterceptor;
|
return this.postAuthorizeAuthorizaitonMethodInterceptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2023 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,7 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.security.config.annotation.method.configuration;
|
package org.springframework.security.config.annotation.method.configuration;
|
||||||
|
|
||||||
import org.springframework.aop.Advisor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
|
|
||||||
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.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@ -44,7 +45,7 @@ final class SecuredMethodSecurityConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||||
Advisor securedAuthorizationMethodInterceptor() {
|
MethodInterceptor securedAuthorizationMethodInterceptor() {
|
||||||
AuthorizationManagerBeforeMethodInterceptor interceptor = AuthorizationManagerBeforeMethodInterceptor.secured();
|
AuthorizationManagerBeforeMethodInterceptor interceptor = AuthorizationManagerBeforeMethodInterceptor.secured();
|
||||||
interceptor.setSecurityContextHolderStrategy(this.securityContextHolderStrategy);
|
interceptor.setSecurityContextHolderStrategy(this.securityContextHolderStrategy);
|
||||||
return interceptor;
|
return interceptor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user