Skip to content

Commit 2417de3

Browse files
ngocnhan-tran1996jzheaux
authored andcommitted
Sort Advisors AfterSingletonsInstantiated
In order to make so that authorization advisors are sorted only one time and also as part of the configuration lifecycle, AuthorizationAdvisorProxyFactory now implements SmartInitializingBean. Closes gh-16819 Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
1 parent af2668f commit 2417de3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

core/src/main/java/org/springframework/security/authorization/method/AuthorizationAdvisorProxyFactory.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@
4242

4343
import org.springframework.aop.Advisor;
4444
import org.springframework.aop.framework.ProxyFactory;
45+
import org.springframework.beans.factory.SmartInitializingSingleton;
4546
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
4647
import org.springframework.lang.NonNull;
4748
import org.springframework.security.authorization.AuthorizationProxyFactory;
@@ -75,7 +76,7 @@
7576
* @since 6.3
7677
*/
7778
public final class AuthorizationAdvisorProxyFactory
78-
implements AuthorizationProxyFactory, Iterable<AuthorizationAdvisor> {
79+
implements AuthorizationProxyFactory, Iterable<AuthorizationAdvisor>, SmartInitializingSingleton {
7980

8081
private static final boolean isReactivePresent = ClassUtils.isPresent("reactor.core.publisher.Mono", null);
8182

@@ -126,6 +127,11 @@ public static AuthorizationAdvisorProxyFactory withReactiveDefaults() {
126127
return new AuthorizationAdvisorProxyFactory(advisors);
127128
}
128129

130+
@Override
131+
public void afterSingletonsInstantiated() {
132+
AnnotationAwareOrderComparator.sort(this.advisors);
133+
}
134+
129135
/**
130136
* Proxy an object to enforce authorization advice.
131137
*
@@ -146,7 +152,6 @@ public static AuthorizationAdvisorProxyFactory withReactiveDefaults() {
146152
*/
147153
@Override
148154
public Object proxy(Object target) {
149-
AnnotationAwareOrderComparator.sort(this.advisors);
150155
if (target == null) {
151156
return null;
152157
}

0 commit comments

Comments
 (0)