41
41
import org .springframework .security .access .prepost .PreAuthorize ;
42
42
import org .springframework .security .authentication .TestAuthentication ;
43
43
import org .springframework .security .authorization .method .AuthorizationAdvisor ;
44
- import org .springframework .security .authorization .method .AuthorizationManagerBeforeMethodInterceptor ;
45
44
import org .springframework .security .core .Authentication ;
46
45
import org .springframework .security .core .context .SecurityContextHolder ;
47
46
@@ -65,9 +64,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
65
64
@ Test
66
65
public void proxyWhenPreAuthorizeThenHonors () {
67
66
SecurityContextHolder .getContext ().setAuthentication (this .user );
68
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
69
- .preAuthorize ();
70
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
67
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
71
68
Flight flight = new Flight ();
72
69
assertThat (flight .getAltitude ()).isEqualTo (35000d );
73
70
Flight secured = proxy (factory , flight );
@@ -78,9 +75,7 @@ public void proxyWhenPreAuthorizeThenHonors() {
78
75
@ Test
79
76
public void proxyWhenPreAuthorizeOnInterfaceThenHonors () {
80
77
SecurityContextHolder .getContext ().setAuthentication (this .user );
81
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
82
- .preAuthorize ();
83
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
78
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
84
79
assertThat (this .alan .getFirstName ()).isEqualTo ("alan" );
85
80
User secured = proxy (factory , this .alan );
86
81
assertThatExceptionOfType (AccessDeniedException .class ).isThrownBy (secured ::getFirstName );
@@ -94,9 +89,7 @@ public void proxyWhenPreAuthorizeOnInterfaceThenHonors() {
94
89
@ Test
95
90
public void proxyWhenPreAuthorizeOnRecordThenHonors () {
96
91
SecurityContextHolder .getContext ().setAuthentication (this .user );
97
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
98
- .preAuthorize ();
99
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
92
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
100
93
HasSecret repo = new Repository ("secret" );
101
94
assertThat (repo .secret ()).isEqualTo ("secret" );
102
95
HasSecret secured = proxy (factory , repo );
@@ -109,9 +102,7 @@ public void proxyWhenPreAuthorizeOnRecordThenHonors() {
109
102
@ Test
110
103
public void proxyWhenImmutableListThenReturnsSecuredImmutableList () {
111
104
SecurityContextHolder .getContext ().setAuthentication (this .user );
112
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
113
- .preAuthorize ();
114
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
105
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
115
106
List <Flight > flights = List .of (this .flight );
116
107
List <Flight > secured = proxy (factory , flights );
117
108
secured .forEach (
@@ -123,9 +114,7 @@ public void proxyWhenImmutableListThenReturnsSecuredImmutableList() {
123
114
@ Test
124
115
public void proxyWhenImmutableSetThenReturnsSecuredImmutableSet () {
125
116
SecurityContextHolder .getContext ().setAuthentication (this .user );
126
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
127
- .preAuthorize ();
128
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
117
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
129
118
Set <Flight > flights = Set .of (this .flight );
130
119
Set <Flight > secured = proxy (factory , flights );
131
120
secured .forEach (
@@ -137,9 +126,7 @@ public void proxyWhenImmutableSetThenReturnsSecuredImmutableSet() {
137
126
@ Test
138
127
public void proxyWhenQueueThenReturnsSecuredQueue () {
139
128
SecurityContextHolder .getContext ().setAuthentication (this .user );
140
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
141
- .preAuthorize ();
142
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
129
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
143
130
Queue <Flight > flights = new LinkedList <>(List .of (this .flight ));
144
131
Queue <Flight > secured = proxy (factory , flights );
145
132
assertThat (flights .size ()).isEqualTo (secured .size ());
@@ -151,9 +138,7 @@ public void proxyWhenQueueThenReturnsSecuredQueue() {
151
138
@ Test
152
139
public void proxyWhenImmutableSortedSetThenReturnsSecuredImmutableSortedSet () {
153
140
SecurityContextHolder .getContext ().setAuthentication (this .user );
154
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
155
- .preAuthorize ();
156
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
141
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
157
142
SortedSet <User > users = Collections .unmodifiableSortedSet (new TreeSet <>(Set .of (this .alan )));
158
143
SortedSet <User > secured = proxy (factory , users );
159
144
secured
@@ -165,9 +150,7 @@ public void proxyWhenImmutableSortedSetThenReturnsSecuredImmutableSortedSet() {
165
150
@ Test
166
151
public void proxyWhenImmutableSortedMapThenReturnsSecuredImmutableSortedMap () {
167
152
SecurityContextHolder .getContext ().setAuthentication (this .user );
168
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
169
- .preAuthorize ();
170
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
153
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
171
154
SortedMap <String , User > users = Collections
172
155
.unmodifiableSortedMap (new TreeMap <>(Map .of (this .alan .getId (), this .alan )));
173
156
SortedMap <String , User > secured = proxy (factory , users );
@@ -180,9 +163,7 @@ public void proxyWhenImmutableSortedMapThenReturnsSecuredImmutableSortedMap() {
180
163
@ Test
181
164
public void proxyWhenImmutableMapThenReturnsSecuredImmutableMap () {
182
165
SecurityContextHolder .getContext ().setAuthentication (this .user );
183
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
184
- .preAuthorize ();
185
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
166
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
186
167
Map <String , User > users = Map .of (this .alan .getId (), this .alan );
187
168
Map <String , User > secured = proxy (factory , users );
188
169
secured .forEach (
@@ -194,9 +175,7 @@ public void proxyWhenImmutableMapThenReturnsSecuredImmutableMap() {
194
175
@ Test
195
176
public void proxyWhenMutableListThenReturnsSecuredMutableList () {
196
177
SecurityContextHolder .getContext ().setAuthentication (this .user );
197
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
198
- .preAuthorize ();
199
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
178
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
200
179
List <Flight > flights = new ArrayList <>(List .of (this .flight ));
201
180
List <Flight > secured = proxy (factory , flights );
202
181
secured .forEach (
@@ -208,9 +187,7 @@ public void proxyWhenMutableListThenReturnsSecuredMutableList() {
208
187
@ Test
209
188
public void proxyWhenMutableSetThenReturnsSecuredMutableSet () {
210
189
SecurityContextHolder .getContext ().setAuthentication (this .user );
211
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
212
- .preAuthorize ();
213
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
190
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
214
191
Set <Flight > flights = new HashSet <>(Set .of (this .flight ));
215
192
Set <Flight > secured = proxy (factory , flights );
216
193
secured .forEach (
@@ -222,9 +199,7 @@ public void proxyWhenMutableSetThenReturnsSecuredMutableSet() {
222
199
@ Test
223
200
public void proxyWhenMutableSortedSetThenReturnsSecuredMutableSortedSet () {
224
201
SecurityContextHolder .getContext ().setAuthentication (this .user );
225
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
226
- .preAuthorize ();
227
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
202
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
228
203
SortedSet <User > users = new TreeSet <>(Set .of (this .alan ));
229
204
SortedSet <User > secured = proxy (factory , users );
230
205
secured .forEach ((u ) -> assertThatExceptionOfType (AccessDeniedException .class ).isThrownBy (u ::getFirstName ));
@@ -235,9 +210,7 @@ public void proxyWhenMutableSortedSetThenReturnsSecuredMutableSortedSet() {
235
210
@ Test
236
211
public void proxyWhenMutableSortedMapThenReturnsSecuredMutableSortedMap () {
237
212
SecurityContextHolder .getContext ().setAuthentication (this .user );
238
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
239
- .preAuthorize ();
240
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
213
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
241
214
SortedMap <String , User > users = new TreeMap <>(Map .of (this .alan .getId (), this .alan ));
242
215
SortedMap <String , User > secured = proxy (factory , users );
243
216
secured .forEach ((id , u ) -> assertThatExceptionOfType (AccessDeniedException .class ).isThrownBy (u ::getFirstName ));
@@ -248,9 +221,7 @@ public void proxyWhenMutableSortedMapThenReturnsSecuredMutableSortedMap() {
248
221
@ Test
249
222
public void proxyWhenMutableMapThenReturnsSecuredMutableMap () {
250
223
SecurityContextHolder .getContext ().setAuthentication (this .user );
251
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
252
- .preAuthorize ();
253
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
224
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
254
225
Map <String , User > users = new HashMap <>(Map .of (this .alan .getId (), this .alan ));
255
226
Map <String , User > secured = proxy (factory , users );
256
227
secured .forEach ((id , u ) -> assertThatExceptionOfType (AccessDeniedException .class ).isThrownBy (u ::getFirstName ));
@@ -261,9 +232,7 @@ public void proxyWhenMutableMapThenReturnsSecuredMutableMap() {
261
232
@ Test
262
233
public void proxyWhenPreAuthorizeForOptionalThenHonors () {
263
234
SecurityContextHolder .getContext ().setAuthentication (this .user );
264
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
265
- .preAuthorize ();
266
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
235
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
267
236
Optional <Flight > flights = Optional .of (this .flight );
268
237
assertThat (flights .get ().getAltitude ()).isEqualTo (35000d );
269
238
Optional <Flight > secured = proxy (factory , flights );
@@ -274,9 +243,7 @@ public void proxyWhenPreAuthorizeForOptionalThenHonors() {
274
243
@ Test
275
244
public void proxyWhenPreAuthorizeForStreamThenHonors () {
276
245
SecurityContextHolder .getContext ().setAuthentication (this .user );
277
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
278
- .preAuthorize ();
279
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
246
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
280
247
Stream <Flight > flights = Stream .of (this .flight );
281
248
Stream <Flight > secured = proxy (factory , flights );
282
249
assertThatExceptionOfType (AccessDeniedException .class ).isThrownBy (() -> secured .forEach (Flight ::getAltitude ));
@@ -286,9 +253,7 @@ public void proxyWhenPreAuthorizeForStreamThenHonors() {
286
253
@ Test
287
254
public void proxyWhenPreAuthorizeForArrayThenHonors () {
288
255
SecurityContextHolder .getContext ().setAuthentication (this .user );
289
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
290
- .preAuthorize ();
291
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
256
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
292
257
Flight [] flights = { this .flight };
293
258
Flight [] secured = proxy (factory , flights );
294
259
assertThatExceptionOfType (AccessDeniedException .class ).isThrownBy (secured [0 ]::getAltitude );
@@ -298,9 +263,7 @@ public void proxyWhenPreAuthorizeForArrayThenHonors() {
298
263
@ Test
299
264
public void proxyWhenPreAuthorizeForIteratorThenHonors () {
300
265
SecurityContextHolder .getContext ().setAuthentication (this .user );
301
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
302
- .preAuthorize ();
303
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
266
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
304
267
Iterator <Flight > flights = List .of (this .flight ).iterator ();
305
268
Iterator <Flight > secured = proxy (factory , flights );
306
269
assertThatExceptionOfType (AccessDeniedException .class ).isThrownBy (() -> secured .next ().getAltitude ());
@@ -310,9 +273,7 @@ public void proxyWhenPreAuthorizeForIteratorThenHonors() {
310
273
@ Test
311
274
public void proxyWhenPreAuthorizeForIterableThenHonors () {
312
275
SecurityContextHolder .getContext ().setAuthentication (this .user );
313
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
314
- .preAuthorize ();
315
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
276
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
316
277
Iterable <User > users = new UserRepository ();
317
278
Iterable <User > secured = proxy (factory , users );
318
279
assertThatExceptionOfType (AccessDeniedException .class ).isThrownBy (() -> secured .forEach (User ::getFirstName ));
@@ -321,9 +282,7 @@ public void proxyWhenPreAuthorizeForIterableThenHonors() {
321
282
322
283
@ Test
323
284
public void proxyWhenPreAuthorizeForClassThenHonors () {
324
- AuthorizationManagerBeforeMethodInterceptor preAuthorize = AuthorizationManagerBeforeMethodInterceptor
325
- .preAuthorize ();
326
- AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory (preAuthorize );
285
+ AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
327
286
Class <Flight > clazz = proxy (factory , Flight .class );
328
287
assertThat (clazz .getSimpleName ()).contains ("SpringCGLIB$$0" );
329
288
Flight secured = proxy (factory , this .flight );
@@ -334,12 +293,12 @@ public void proxyWhenPreAuthorizeForClassThenHonors() {
334
293
}
335
294
336
295
@ Test
337
- public void withAdvisorsWhenProxyThenVisits () {
296
+ public void setAdvisorsWhenProxyThenVisits () {
338
297
AuthorizationAdvisor advisor = mock (AuthorizationAdvisor .class );
339
298
given (advisor .getAdvice ()).willReturn (advisor );
340
299
given (advisor .getPointcut ()).willReturn (Pointcut .TRUE );
341
300
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ();
342
- factory = factory . withAdvisors (advisor );
301
+ factory . setAdvisors (advisor );
343
302
Flight flight = proxy (factory , this .flight );
344
303
flight .getAltitude ();
345
304
verify (advisor , atLeastOnce ()).getPointcut ();
0 commit comments