@@ -40,12 +40,8 @@ public abstract class AbstractSecurityExpressionHandler<T> implements
40
40
SecurityExpressionHandler <T >, ApplicationContextAware {
41
41
private ExpressionParser expressionParser = new SpelExpressionParser ();
42
42
private BeanResolver br ;
43
- private ApplicationContext context ;
44
43
private RoleHierarchy roleHierarchy ;
45
44
private PermissionEvaluator permissionEvaluator = new DenyAllPermissionEvaluator ();
46
- private boolean roleHierarchySet = false ;
47
- private boolean permissionEvaluatorSet = false ;
48
-
49
45
50
46
public final ExpressionParser getExpressionParser () {
51
47
return expressionParser ;
@@ -105,52 +101,23 @@ protected StandardEvaluationContext createEvaluationContextInternal(
105
101
protected abstract SecurityExpressionOperations createSecurityExpressionRoot (
106
102
Authentication authentication , T invocation );
107
103
108
- private boolean roleHerarchyNotSetForValidContext () {
109
- return ! roleHierarchySet && context != null ;
110
- }
111
-
112
104
protected RoleHierarchy getRoleHierarchy () {
113
- if (roleHerarchyNotSetForValidContext ()) {
114
- RoleHierarchy contextRoleHierarchy = getSingleBeanOrNull (RoleHierarchy .class );
115
- if (contextRoleHierarchy != null ){
116
- roleHierarchy = contextRoleHierarchy ;
117
- }
118
- roleHierarchySet = true ;
119
- }
120
105
return roleHierarchy ;
121
106
}
122
107
123
108
public void setRoleHierarchy (RoleHierarchy roleHierarchy ) {
124
- roleHierarchySet = true ;
125
109
this .roleHierarchy = roleHierarchy ;
126
110
}
127
111
128
112
protected PermissionEvaluator getPermissionEvaluator () {
129
- if (! permissionEvaluatorSet && context != null ) {
130
- PermissionEvaluator contextPermissionEvaluator = getSingleBeanOrNull (PermissionEvaluator .class );
131
- if (contextPermissionEvaluator != null ){
132
- permissionEvaluator = contextPermissionEvaluator ;
133
- }
134
- permissionEvaluatorSet = true ;
135
- }
136
113
return permissionEvaluator ;
137
114
}
138
115
139
116
public void setPermissionEvaluator (PermissionEvaluator permissionEvaluator ) {
140
- permissionEvaluatorSet = true ;
141
117
this .permissionEvaluator = permissionEvaluator ;
142
118
}
143
119
144
120
public void setApplicationContext (ApplicationContext applicationContext ) {
145
121
br = new BeanFactoryResolver (applicationContext );
146
- this .context = applicationContext ;
147
- }
148
-
149
- private <T > T getSingleBeanOrNull (Class <T > type ) {
150
- String [] beanNamesForType = context .getBeanNamesForType (type );
151
- if (beanNamesForType == null || beanNamesForType .length != 1 ) {
152
- return null ;
153
- }
154
- return context .getBean (beanNamesForType [0 ], type );
155
122
}
156
123
}
0 commit comments