File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed
main/java/org/springframework/security/access/expression
test/java/org/springframework/security/access/expression Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change 11
11
import org .springframework .security .access .PermissionEvaluator ;
12
12
import org .springframework .security .access .hierarchicalroles .RoleHierarchy ;
13
13
import org .springframework .security .core .Authentication ;
14
+ import org .springframework .util .Assert ;
14
15
15
16
/**
16
17
* Base implementation of the facade which isolates Spring Security's requirements for evaluating security expressions
20
21
* @since 3.1
21
22
*/
22
23
public abstract class AbstractSecurityExpressionHandler <T > implements SecurityExpressionHandler <T >, ApplicationContextAware {
23
- private final ExpressionParser expressionParser = new SpelExpressionParser ();
24
+ private ExpressionParser expressionParser = new SpelExpressionParser ();
24
25
private BeanResolver br ;
25
26
private RoleHierarchy roleHierarchy ;
26
27
private PermissionEvaluator permissionEvaluator = new DenyAllPermissionEvaluator ();
@@ -29,6 +30,11 @@ public final ExpressionParser getExpressionParser() {
29
30
return expressionParser ;
30
31
}
31
32
33
+ public final void setExpressionParser (ExpressionParser expressionParser ) {
34
+ Assert .notNull (expressionParser , "expressionParser cannot be null" );
35
+ this .expressionParser = expressionParser ;
36
+ }
37
+
32
38
/**
33
39
* Invokes the internal template methods to create {@code StandardEvaluationContext} and {@code SecurityExpressionRoot}
34
40
* objects.
Original file line number Diff line number Diff line change 3
3
import static org .junit .Assert .assertTrue ;
4
4
import static org .mockito .Mockito .mock ;
5
5
6
- import org .junit .* ;
7
- import org .springframework . context . ApplicationContext ;
6
+ import org .junit .Before ;
7
+ import org .junit . Test ;
8
8
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
9
9
import org .springframework .context .annotation .Bean ;
10
10
import org .springframework .context .annotation .Configuration ;
11
11
import org .springframework .expression .Expression ;
12
+ import org .springframework .expression .spel .standard .SpelExpressionParser ;
12
13
import org .springframework .security .core .Authentication ;
13
14
14
- import java .util .*;
15
-
16
15
/**
17
16
* @author Luke Taylor
18
17
*/
@@ -36,6 +35,18 @@ public void beanNamesAreCorrectlyResolved() throws Exception {
36
35
Expression expression = handler .getExpressionParser ().parseExpression ("@number10.compareTo(@number20) < 0" );
37
36
assertTrue ((Boolean ) expression .getValue (handler .createEvaluationContext (mock (Authentication .class ), new Object ())));
38
37
}
38
+
39
+ @ Test (expected =IllegalArgumentException .class )
40
+ public void setExpressionParserNull () {
41
+ handler .setExpressionParser (null );
42
+ }
43
+
44
+ @ Test
45
+ public void setExpressionParser () {
46
+ SpelExpressionParser parser = new SpelExpressionParser ();
47
+ handler .setExpressionParser (parser );
48
+ assertTrue (parser == handler .getExpressionParser ());
49
+ }
39
50
}
40
51
41
52
@ Configuration
You can’t perform that action at this time.
0 commit comments