浏览代码

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 年之前
父节点
当前提交
0cab7c8f15

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

@@ -146,6 +146,7 @@ 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;
 		}
 		}
@@ -170,7 +171,6 @@ public final class AuthorizationAdvisorProxyFactory
 	 */
 	 */
 	public void setAdvisors(AuthorizationAdvisor... advisors) {
 	public void setAdvisors(AuthorizationAdvisor... advisors) {
 		this.advisors = new ArrayList<>(List.of(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) {
 	public void setAdvisors(Collection<AuthorizationAdvisor> advisors) {
 		this.advisors = new ArrayList<>(advisors);
 		this.advisors = new ArrayList<>(advisors);
-		AnnotationAwareOrderComparator.sort(this.advisors);
 	}
 	}
 
 
 	/**
 	/**