Browse Source

Defer Sorting AuthorizationAdvisors

Invoking AnnotationAwareOrderComparator#sort while the
AuthorizationAdvisors are still being computed causes those
advisors to be eagerly instantiated, making components
like ObservationRegistry ineligible for post processing.

This commit defers the sorting of the advisors until
after they are all fully instantiated and available in
the application context.

Closes gh-15658
Josh Cummings 1 year ago
parent
commit
0cab7c8f15

+ 1 - 2
core/src/main/java/org/springframework/security/authorization/method/AuthorizationAdvisorProxyFactory.java

@@ -146,6 +146,7 @@ public final class AuthorizationAdvisorProxyFactory
 	 */
 	@Override
 	public Object proxy(Object target) {
+		AnnotationAwareOrderComparator.sort(this.advisors);
 		if (target == null) {
 			return null;
 		}
@@ -170,7 +171,6 @@ public final class AuthorizationAdvisorProxyFactory
 	 */
 	public void setAdvisors(AuthorizationAdvisor... advisors) {
 		this.advisors = new ArrayList<>(List.of(advisors));
-		AnnotationAwareOrderComparator.sort(this.advisors);
 	}
 
 	/**
@@ -182,7 +182,6 @@ public final class AuthorizationAdvisorProxyFactory
 	 */
 	public void setAdvisors(Collection<AuthorizationAdvisor> advisors) {
 		this.advisors = new ArrayList<>(advisors);
-		AnnotationAwareOrderComparator.sort(this.advisors);
 	}
 
 	/**