41
41
import reactor .core .publisher .Mono ;
42
42
43
43
import org .springframework .aop .Advisor ;
44
+ import org .springframework .aop .framework .AopInfrastructureBean ;
44
45
import org .springframework .aop .framework .ProxyFactory ;
45
46
import org .springframework .core .annotation .AnnotationAwareOrderComparator ;
46
47
import org .springframework .lang .NonNull ;
75
76
* @since 6.3
76
77
*/
77
78
public final class AuthorizationAdvisorProxyFactory
78
- implements AuthorizationProxyFactory , Iterable <AuthorizationAdvisor > {
79
+ implements AuthorizationProxyFactory , Iterable <AuthorizationAdvisor >, AopInfrastructureBean {
79
80
80
81
private static final boolean isReactivePresent = ClassUtils .isPresent ("reactor.core.publisher.Mono" , null );
81
82
@@ -90,10 +91,18 @@ public final class AuthorizationAdvisorProxyFactory
90
91
91
92
private TargetVisitor visitor = DEFAULT_VISITOR ;
92
93
93
- private AuthorizationAdvisorProxyFactory (List <AuthorizationAdvisor > advisors ) {
94
+ /**
95
+ * Construct an {@link AuthorizationAdvisorProxyFactory} with the provided advisors.
96
+ *
97
+ * <p>
98
+ * The list may be empty, in the case where advisors are added later using
99
+ * {@link #addAdvisor}.
100
+ * @param advisors the advisors to use
101
+ * @since 6.4
102
+ */
103
+ public AuthorizationAdvisorProxyFactory (List <AuthorizationAdvisor > advisors ) {
94
104
this .advisors = new ArrayList <>(advisors );
95
- this .advisors .add (new AuthorizeReturnObjectMethodInterceptor (this ));
96
- setAdvisors (this .advisors );
105
+ AnnotationAwareOrderComparator .sort (this .advisors );
97
106
}
98
107
99
108
/**
@@ -108,7 +117,9 @@ public static AuthorizationAdvisorProxyFactory withDefaults() {
108
117
advisors .add (AuthorizationManagerAfterMethodInterceptor .postAuthorize ());
109
118
advisors .add (new PreFilterAuthorizationMethodInterceptor ());
110
119
advisors .add (new PostFilterAuthorizationMethodInterceptor ());
111
- return new AuthorizationAdvisorProxyFactory (advisors );
120
+ AuthorizationAdvisorProxyFactory proxyFactory = new AuthorizationAdvisorProxyFactory (advisors );
121
+ proxyFactory .addAdvisor (new AuthorizeReturnObjectMethodInterceptor (proxyFactory ));
122
+ return proxyFactory ;
112
123
}
113
124
114
125
/**
@@ -123,7 +134,9 @@ public static AuthorizationAdvisorProxyFactory withReactiveDefaults() {
123
134
advisors .add (AuthorizationManagerAfterReactiveMethodInterceptor .postAuthorize ());
124
135
advisors .add (new PreFilterAuthorizationReactiveMethodInterceptor ());
125
136
advisors .add (new PostFilterAuthorizationReactiveMethodInterceptor ());
126
- return new AuthorizationAdvisorProxyFactory (advisors );
137
+ AuthorizationAdvisorProxyFactory proxyFactory = new AuthorizationAdvisorProxyFactory (advisors );
138
+ proxyFactory .addAdvisor (new AuthorizeReturnObjectMethodInterceptor (proxyFactory ));
139
+ return proxyFactory ;
127
140
}
128
141
129
142
/**
@@ -167,7 +180,9 @@ public Object proxy(Object target) {
167
180
* <p>
168
181
* All advisors are re-sorted by their advisor order.
169
182
* @param advisors the advisors to add
183
+ * @deprecated Please use {@link #addAdvisor} instead
170
184
*/
185
+ @ Deprecated
171
186
public void setAdvisors (AuthorizationAdvisor ... advisors ) {
172
187
this .advisors = new ArrayList <>(List .of (advisors ));
173
188
AnnotationAwareOrderComparator .sort (this .advisors );
@@ -179,12 +194,30 @@ public void setAdvisors(AuthorizationAdvisor... advisors) {
179
194
* <p>
180
195
* All advisors are re-sorted by their advisor order.
181
196
* @param advisors the advisors to add
197
+ * @deprecated Please use {@link #addAdvisor} instead
182
198
*/
199
+ @ Deprecated
183
200
public void setAdvisors (Collection <AuthorizationAdvisor > advisors ) {
184
201
this .advisors = new ArrayList <>(advisors );
185
202
AnnotationAwareOrderComparator .sort (this .advisors );
186
203
}
187
204
205
+ /**
206
+ * Add an advisor that should be included to each proxy created.
207
+ *
208
+ * <p>
209
+ * This method sorts the advisors based on the order in
210
+ * {@link AuthorizationAdvisor#getOrder}. You can use the values in
211
+ * {@link AuthorizationInterceptorsOrder}to ensure advisors are located where you need
212
+ * them.
213
+ * @param advisor
214
+ * @since 6.4
215
+ */
216
+ public void addAdvisor (AuthorizationAdvisor advisor ) {
217
+ this .advisors .add (advisor );
218
+ AnnotationAwareOrderComparator .sort (this .advisors );
219
+ }
220
+
188
221
/**
189
222
* Use this visitor to navigate the proxy target's hierarchy.
190
223
*
0 commit comments