@@ -86,14 +86,28 @@ public final class AuthorizationAdvisorProxyFactory
86
86
private static final TargetVisitor DEFAULT_VISITOR_SKIP_VALUE_TYPES = TargetVisitor .of (new ClassVisitor (),
87
87
new IgnoreValueTypeVisitor (), DEFAULT_VISITOR );
88
88
89
- private List <AuthorizationAdvisor > advisors ;
89
+ private List <AuthorizationAdvisor > advisors = new ArrayList <>() ;
90
90
91
91
private TargetVisitor visitor = DEFAULT_VISITOR ;
92
92
93
- private AuthorizationAdvisorProxyFactory (List <AuthorizationAdvisor > advisors ) {
94
- this .advisors = new ArrayList <>(advisors );
95
- this .advisors .add (new AuthorizeReturnObjectMethodInterceptor (this ));
96
- setAdvisors (this .advisors );
93
+ /**
94
+ * Construct an {@link AuthorizationAdvisorProxyFactory} with the following advisors
95
+ * @param advisors the list of advisors to wrap around proxied objects
96
+ * @since 6.4
97
+ */
98
+ public AuthorizationAdvisorProxyFactory (List <AuthorizationAdvisor > advisors ) {
99
+ this .advisors .addAll (advisors );
100
+ AnnotationAwareOrderComparator .sort (this .advisors );
101
+ }
102
+
103
+ /**
104
+ * Construct an {@link AuthorizationAdvisorProxyFactory} with the following advisors
105
+ * @param advisors the list of advisors to wrap around proxied objects
106
+ * @since 6.4
107
+ */
108
+ public AuthorizationAdvisorProxyFactory (AuthorizationAdvisor ... advisors ) {
109
+ this .advisors .addAll (List .of (advisors ));
110
+ AnnotationAwareOrderComparator .sort (this .advisors );
97
111
}
98
112
99
113
/**
@@ -108,7 +122,9 @@ public static AuthorizationAdvisorProxyFactory withDefaults() {
108
122
advisors .add (AuthorizationManagerAfterMethodInterceptor .postAuthorize ());
109
123
advisors .add (new PreFilterAuthorizationMethodInterceptor ());
110
124
advisors .add (new PostFilterAuthorizationMethodInterceptor ());
111
- return new AuthorizationAdvisorProxyFactory (advisors );
125
+ AuthorizationAdvisorProxyFactory proxyFactory = new AuthorizationAdvisorProxyFactory (advisors );
126
+ proxyFactory .addAdvisors (new AuthorizeReturnObjectMethodInterceptor (proxyFactory ));
127
+ return proxyFactory ;
112
128
}
113
129
114
130
/**
@@ -123,7 +139,9 @@ public static AuthorizationAdvisorProxyFactory withReactiveDefaults() {
123
139
advisors .add (AuthorizationManagerAfterReactiveMethodInterceptor .postAuthorize ());
124
140
advisors .add (new PreFilterAuthorizationReactiveMethodInterceptor ());
125
141
advisors .add (new PostFilterAuthorizationReactiveMethodInterceptor ());
126
- return new AuthorizationAdvisorProxyFactory (advisors );
142
+ AuthorizationAdvisorProxyFactory proxyFactory = new AuthorizationAdvisorProxyFactory (advisors );
143
+ proxyFactory .addAdvisors (new AuthorizeReturnObjectMethodInterceptor (proxyFactory ));
144
+ return proxyFactory ;
127
145
}
128
146
129
147
/**
@@ -161,13 +179,21 @@ public Object proxy(Object target) {
161
179
return factory .getProxy ();
162
180
}
163
181
182
+ public void addAdvisors (AuthorizationAdvisor ... advisors ) {
183
+ this .advisors .addAll (List .of (advisors ));
184
+ AnnotationAwareOrderComparator .sort (this .advisors );
185
+ }
186
+
164
187
/**
165
188
* Add advisors that should be included to each proxy created.
166
189
*
167
190
* <p>
168
191
* All advisors are re-sorted by their advisor order.
169
192
* @param advisors the advisors to add
193
+ * @deprecated Either use the constructor to provide a complete set of advisors or use
194
+ * {@link #addAdvisors(AuthorizationAdvisor...)} to add to the existing list
170
195
*/
196
+ @ Deprecated
171
197
public void setAdvisors (AuthorizationAdvisor ... advisors ) {
172
198
this .advisors = new ArrayList <>(List .of (advisors ));
173
199
AnnotationAwareOrderComparator .sort (this .advisors );
@@ -179,7 +205,10 @@ public void setAdvisors(AuthorizationAdvisor... advisors) {
179
205
* <p>
180
206
* All advisors are re-sorted by their advisor order.
181
207
* @param advisors the advisors to add
208
+ * @deprecated Either use the constructor to provide a complete set of advisors or use
209
+ * {@link #addAdvisors(AuthorizationAdvisor...)} to add to the existing list
182
210
*/
211
+ @ Deprecated
183
212
public void setAdvisors (Collection <AuthorizationAdvisor > advisors ) {
184
213
this .advisors = new ArrayList <>(advisors );
185
214
AnnotationAwareOrderComparator .sort (this .advisors );
0 commit comments