mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-26 13:53:14 +00:00
Merge branch '6.3.x' into 6.4.x
Closes gh-16837
This commit is contained in:
commit
6c5b6d1c51
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 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.
|
||||||
@ -56,6 +56,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.Role;
|
import org.springframework.context.annotation.Role;
|
||||||
|
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||||
import org.springframework.core.annotation.AnnotationConfigurationException;
|
import org.springframework.core.annotation.AnnotationConfigurationException;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
import org.springframework.security.access.PermissionEvaluator;
|
import org.springframework.security.access.PermissionEvaluator;
|
||||||
@ -1103,6 +1104,21 @@ public class PrePostMethodSecurityConfigurationTests {
|
|||||||
verifyNoInteractions(handler);
|
verifyNoInteractions(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gh-16819
|
||||||
|
@Test
|
||||||
|
void autowireWhenDefaultsThenAdvisorAnnotationsAreSorted() {
|
||||||
|
this.spring.register(MethodSecurityServiceConfig.class).autowire();
|
||||||
|
AuthorizationAdvisorProxyFactory proxyFactory = this.spring.getContext()
|
||||||
|
.getBean(AuthorizationAdvisorProxyFactory.class);
|
||||||
|
AnnotationAwareOrderComparator comparator = AnnotationAwareOrderComparator.INSTANCE;
|
||||||
|
AuthorizationAdvisor previous = null;
|
||||||
|
for (AuthorizationAdvisor advisor : proxyFactory) {
|
||||||
|
boolean ordered = previous == null || comparator.compare(previous, advisor) < 0;
|
||||||
|
assertThat(ordered).isTrue();
|
||||||
|
previous = advisor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Consumer<ConfigurableWebApplicationContext> disallowBeanOverriding() {
|
private static Consumer<ConfigurableWebApplicationContext> disallowBeanOverriding() {
|
||||||
return (context) -> ((AnnotationConfigWebApplicationContext) context).setAllowBeanDefinitionOverriding(false);
|
return (context) -> ((AnnotationConfigWebApplicationContext) context).setAllowBeanDefinitionOverriding(false);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 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.
|
||||||
@ -47,6 +47,7 @@ import org.springframework.aop.Advisor;
|
|||||||
import org.springframework.aop.Pointcut;
|
import org.springframework.aop.Pointcut;
|
||||||
import org.springframework.aop.framework.AopInfrastructureBean;
|
import org.springframework.aop.framework.AopInfrastructureBean;
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
|
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.security.authorization.AuthorizationProxyFactory;
|
import org.springframework.security.authorization.AuthorizationProxyFactory;
|
||||||
@ -79,8 +80,8 @@ import org.springframework.util.ClassUtils;
|
|||||||
* @author Josh Cummings
|
* @author Josh Cummings
|
||||||
* @since 6.3
|
* @since 6.3
|
||||||
*/
|
*/
|
||||||
public final class AuthorizationAdvisorProxyFactory
|
public final class AuthorizationAdvisorProxyFactory implements AuthorizationProxyFactory,
|
||||||
implements AuthorizationProxyFactory, Iterable<AuthorizationAdvisor>, AopInfrastructureBean {
|
Iterable<AuthorizationAdvisor>, AopInfrastructureBean, SmartInitializingSingleton {
|
||||||
|
|
||||||
private static final boolean isReactivePresent = ClassUtils.isPresent("reactor.core.publisher.Mono", null);
|
private static final boolean isReactivePresent = ClassUtils.isPresent("reactor.core.publisher.Mono", null);
|
||||||
|
|
||||||
@ -125,6 +126,7 @@ public final class AuthorizationAdvisorProxyFactory
|
|||||||
advisors.add(new PostFilterAuthorizationMethodInterceptor());
|
advisors.add(new PostFilterAuthorizationMethodInterceptor());
|
||||||
AuthorizationAdvisorProxyFactory proxyFactory = new AuthorizationAdvisorProxyFactory(advisors);
|
AuthorizationAdvisorProxyFactory proxyFactory = new AuthorizationAdvisorProxyFactory(advisors);
|
||||||
proxyFactory.addAdvisor(new AuthorizeReturnObjectMethodInterceptor(proxyFactory));
|
proxyFactory.addAdvisor(new AuthorizeReturnObjectMethodInterceptor(proxyFactory));
|
||||||
|
AnnotationAwareOrderComparator.sort(proxyFactory.advisors);
|
||||||
return proxyFactory;
|
return proxyFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,9 +144,15 @@ public final class AuthorizationAdvisorProxyFactory
|
|||||||
advisors.add(new PostFilterAuthorizationReactiveMethodInterceptor());
|
advisors.add(new PostFilterAuthorizationReactiveMethodInterceptor());
|
||||||
AuthorizationAdvisorProxyFactory proxyFactory = new AuthorizationAdvisorProxyFactory(advisors);
|
AuthorizationAdvisorProxyFactory proxyFactory = new AuthorizationAdvisorProxyFactory(advisors);
|
||||||
proxyFactory.addAdvisor(new AuthorizeReturnObjectMethodInterceptor(proxyFactory));
|
proxyFactory.addAdvisor(new AuthorizeReturnObjectMethodInterceptor(proxyFactory));
|
||||||
|
AnnotationAwareOrderComparator.sort(proxyFactory.advisors);
|
||||||
return proxyFactory;
|
return proxyFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterSingletonsInstantiated() {
|
||||||
|
AnnotationAwareOrderComparator.sort(this.advisors);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proxy an object to enforce authorization advice.
|
* Proxy an object to enforce authorization advice.
|
||||||
*
|
*
|
||||||
@ -165,7 +173,6 @@ public final class AuthorizationAdvisorProxyFactory
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object proxy(Object target) {
|
public Object proxy(Object target) {
|
||||||
AnnotationAwareOrderComparator.sort(this.advisors);
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -178,9 +185,9 @@ public final class AuthorizationAdvisorProxyFactory
|
|||||||
}
|
}
|
||||||
ProxyFactory factory = new ProxyFactory(target);
|
ProxyFactory factory = new ProxyFactory(target);
|
||||||
factory.addAdvisors(this.authorizationProxy);
|
factory.addAdvisors(this.authorizationProxy);
|
||||||
for (Advisor advisor : this.advisors) {
|
List<Advisor> advisors = new ArrayList<>(this.advisors);
|
||||||
factory.addAdvisors(advisor);
|
AnnotationAwareOrderComparator.sort(advisors);
|
||||||
}
|
factory.addAdvisors(advisors);
|
||||||
factory.addInterface(AuthorizationProxy.class);
|
factory.addInterface(AuthorizationProxy.class);
|
||||||
factory.setOpaque(true);
|
factory.setOpaque(true);
|
||||||
factory.setProxyTargetClass(!Modifier.isFinal(target.getClass().getModifiers()));
|
factory.setProxyTargetClass(!Modifier.isFinal(target.getClass().getModifiers()));
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 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.
|
||||||
@ -40,6 +40,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.aop.Pointcut;
|
import org.springframework.aop.Pointcut;
|
||||||
|
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.security.authentication.TestAuthentication;
|
import org.springframework.security.authentication.TestAuthentication;
|
||||||
@ -360,6 +361,32 @@ public class AuthorizationAdvisorProxyFactoryTests {
|
|||||||
assertThat(target).isSameAs(this.flight);
|
assertThat(target).isSameAs(this.flight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gh-16819
|
||||||
|
@Test
|
||||||
|
void advisorsWhenWithDefaultsThenAreSorted() {
|
||||||
|
AuthorizationAdvisorProxyFactory proxyFactory = AuthorizationAdvisorProxyFactory.withDefaults();
|
||||||
|
AnnotationAwareOrderComparator comparator = AnnotationAwareOrderComparator.INSTANCE;
|
||||||
|
AuthorizationAdvisor previous = null;
|
||||||
|
for (AuthorizationAdvisor advisor : proxyFactory) {
|
||||||
|
boolean ordered = previous == null || comparator.compare(previous, advisor) < 0;
|
||||||
|
assertThat(ordered).isTrue();
|
||||||
|
previous = advisor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// gh-16819
|
||||||
|
@Test
|
||||||
|
void advisorsWhenWithReactiveDefaultsThenAreSorted() {
|
||||||
|
AuthorizationAdvisorProxyFactory proxyFactory = AuthorizationAdvisorProxyFactory.withReactiveDefaults();
|
||||||
|
AnnotationAwareOrderComparator comparator = AnnotationAwareOrderComparator.INSTANCE;
|
||||||
|
AuthorizationAdvisor previous = null;
|
||||||
|
for (AuthorizationAdvisor advisor : proxyFactory) {
|
||||||
|
boolean ordered = previous == null || comparator.compare(previous, advisor) < 0;
|
||||||
|
assertThat(ordered).isTrue();
|
||||||
|
previous = advisor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Authentication authenticated(String user, String... authorities) {
|
private Authentication authenticated(String user, String... authorities) {
|
||||||
return TestAuthentication.authenticated(TestAuthentication.withUsername(user).authorities(authorities).build());
|
return TestAuthentication.authenticated(TestAuthentication.withUsername(user).authorities(authorities).build());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user