37
37
*
38
38
* @author Luke Taylor
39
39
* @author Evgeniy Cheban
40
+ * @author Steve Riesenberg
40
41
* @since 3.0
41
42
*/
42
- public abstract class SecurityExpressionRoot implements SecurityExpressionOperations {
43
+ public abstract class SecurityExpressionRoot < T > implements SecurityExpressionOperations {
43
44
44
- private static final AuthorizationManagerFactory <Object > DEFAULT_AUTHORIZATION_MANAGER_FACTORY = new DefaultAuthorizationManagerFactory <>();
45
-
46
- private static final Object DEFAULT_OBJECT = new Object ();
45
+ private static final AuthorizationManagerFactory <?> DEFAULT_AUTHORIZATION_MANAGER_FACTORY = new DefaultAuthorizationManagerFactory <>();
47
46
48
47
private final Supplier <Authentication > authentication ;
49
48
50
- private final Object object ;
49
+ private final @ Nullable T object ;
51
50
52
- private @ Nullable DefaultAuthorizationManagerFactory <Object > defaultAuthorizationManagerFactory ;
51
+ private @ Nullable DefaultAuthorizationManagerFactory <T > defaultAuthorizationManagerFactory ;
53
52
54
- private AuthorizationManagerFactory <Object > authorizationManagerFactory = DEFAULT_AUTHORIZATION_MANAGER_FACTORY ;
53
+ private AuthorizationManagerFactory <T > authorizationManagerFactory = defaultAuthorizationManagerFactory () ;
55
54
56
55
/**
57
56
* Allows "permitAll" expression
@@ -82,7 +81,7 @@ public abstract class SecurityExpressionRoot implements SecurityExpressionOperat
82
81
*/
83
82
@ Deprecated (since = "7.0" )
84
83
public SecurityExpressionRoot (Authentication authentication ) {
85
- this (() -> authentication , DEFAULT_OBJECT );
84
+ this (() -> authentication );
86
85
}
87
86
88
87
/**
@@ -95,7 +94,12 @@ public SecurityExpressionRoot(Authentication authentication) {
95
94
*/
96
95
@ Deprecated (since = "7.0" )
97
96
public SecurityExpressionRoot (Supplier <Authentication > authentication ) {
98
- this (authentication , DEFAULT_OBJECT );
97
+ this .authentication = SingletonSupplier .of (() -> {
98
+ Authentication value = authentication .get ();
99
+ Assert .notNull (value , "Authentication object cannot be null" );
100
+ return value ;
101
+ });
102
+ this .object = null ;
99
103
}
100
104
101
105
/**
@@ -106,7 +110,7 @@ public SecurityExpressionRoot(Supplier<Authentication> authentication) {
106
110
* @param object the object being authorized
107
111
* @since 7.0
108
112
*/
109
- public SecurityExpressionRoot (Supplier <Authentication > authentication , Object object ) {
113
+ public SecurityExpressionRoot (Supplier <Authentication > authentication , T object ) {
110
114
this .authentication = SingletonSupplier .of (() -> {
111
115
Authentication value = authentication .get ();
112
116
Assert .notNull (value , "Authentication object cannot be null" );
@@ -170,7 +174,8 @@ public final boolean isFullyAuthenticated() {
170
174
return isGranted (this .authorizationManagerFactory .fullyAuthenticated ());
171
175
}
172
176
173
- private boolean isGranted (AuthorizationManager <Object > authorizationManager ) {
177
+ @ SuppressWarnings ("DataFlowIssue" )
178
+ private boolean isGranted (AuthorizationManager <T > authorizationManager ) {
174
179
AuthorizationResult authorizationResult = authorizationManager .authorize (this .authentication , this .object );
175
180
return (authorizationResult != null && authorizationResult .isGranted ());
176
181
}
@@ -228,12 +233,12 @@ public void setDefaultRolePrefix(String defaultRolePrefix) {
228
233
* @param authorizationManagerFactory the {@link AuthorizationManagerFactory} to use
229
234
* @since 7.0
230
235
*/
231
- public void setAuthorizationManagerFactory (AuthorizationManagerFactory <Object > authorizationManagerFactory ) {
236
+ public void setAuthorizationManagerFactory (AuthorizationManagerFactory <T > authorizationManagerFactory ) {
232
237
Assert .notNull (authorizationManagerFactory , "authorizationManagerFactory cannot be null" );
233
238
this .authorizationManagerFactory = authorizationManagerFactory ;
234
239
}
235
240
236
- private DefaultAuthorizationManagerFactory <Object > getDefaultAuthorizationManagerFactory () {
241
+ private DefaultAuthorizationManagerFactory <T > getDefaultAuthorizationManagerFactory () {
237
242
if (this .defaultAuthorizationManagerFactory == null ) {
238
243
this .defaultAuthorizationManagerFactory = new DefaultAuthorizationManagerFactory <>();
239
244
this .authorizationManagerFactory = this .defaultAuthorizationManagerFactory ;
@@ -258,4 +263,9 @@ public void setPermissionEvaluator(PermissionEvaluator permissionEvaluator) {
258
263
this .permissionEvaluator = permissionEvaluator ;
259
264
}
260
265
266
+ @ SuppressWarnings ("unchecked" )
267
+ private static <T > AuthorizationManagerFactory <T > defaultAuthorizationManagerFactory () {
268
+ return (AuthorizationManagerFactory <T >) DEFAULT_AUTHORIZATION_MANAGER_FACTORY ;
269
+ }
270
+
261
271
}
0 commit comments