File tree 2 files changed +14
-1
lines changed
main/java/org/springframework/security/authorization
test/java/org/springframework/security/authorization
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -254,7 +254,8 @@ public interface TargetVisitor {
254
254
/**
255
255
* The default {@link TargetVisitor}, which will proxy {@link Class} instances as
256
256
* well as instances contained in reactive types (if reactor is present),
257
- * collection types, and other container types like {@link Optional}
257
+ * collection types, and other container types like {@link Optional} and
258
+ * {@link Supplier}
258
259
*/
259
260
static TargetVisitor defaults () {
260
261
return AuthorizationAdvisorProxyFactory .DEFAULT_VISITOR ;
Original file line number Diff line number Diff line change 31
31
import java .util .SortedSet ;
32
32
import java .util .TreeMap ;
33
33
import java .util .TreeSet ;
34
+ import java .util .function .Supplier ;
34
35
import java .util .stream .Stream ;
35
36
36
37
import org .jetbrains .annotations .NotNull ;
@@ -242,6 +243,17 @@ public void proxyWhenPreAuthorizeForOptionalThenHonors() {
242
243
SecurityContextHolder .clearContext ();
243
244
}
244
245
246
+ @ Test
247
+ public void proxyWhenPreAuthorizeForSupplierThenHonors () {
248
+ SecurityContextHolder .getContext ().setAuthentication (this .user );
249
+ AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory .withDefaults ();
250
+ Supplier <Flight > flights = () -> this .flight ;
251
+ assertThat (flights .get ().getAltitude ()).isEqualTo (35000d );
252
+ Supplier <Flight > secured = proxy (factory , flights );
253
+ assertThatExceptionOfType (AccessDeniedException .class ).isThrownBy (() -> secured .get ().getAltitude ());
254
+ SecurityContextHolder .clearContext ();
255
+ }
256
+
245
257
@ Test
246
258
public void proxyWhenPreAuthorizeForStreamThenHonors () {
247
259
SecurityContextHolder .getContext ().setAuthentication (this .user );
You can’t perform that action at this time.
0 commit comments