@@ -50,6 +50,8 @@ class AuthorizationFilterParser implements BeanDefinitionParser {
50
50
51
51
private static final String ATT_USE_EXPRESSIONS = "use-expressions" ;
52
52
53
+ private static final String ATT_ACCESS_DECISION_MANAGER_REF = "access-decision-manager-ref" ;
54
+
53
55
private static final String ATT_HTTP_METHOD = "method" ;
54
56
55
57
private static final String ATT_PATTERN = "pattern" ;
@@ -60,17 +62,29 @@ class AuthorizationFilterParser implements BeanDefinitionParser {
60
62
61
63
private String authorizationManagerRef ;
62
64
65
+ private final BeanMetadataElement securityContextHolderStrategy ;
66
+
67
+ AuthorizationFilterParser (BeanMetadataElement securityContextHolderStrategy ) {
68
+ this .securityContextHolderStrategy = securityContextHolderStrategy ;
69
+ }
70
+
63
71
@ Override
64
72
public BeanDefinition parse (Element element , ParserContext parserContext ) {
65
73
if (!isUseExpressions (element )) {
66
74
parserContext .getReaderContext ().error ("AuthorizationManager must be used with `use-expressions=\" true\" " ,
67
75
element );
68
76
return null ;
69
77
}
78
+ if (StringUtils .hasText (element .getAttribute (ATT_ACCESS_DECISION_MANAGER_REF ))) {
79
+ parserContext .getReaderContext ().error (
80
+ "AuthorizationManager cannot be used in conjunction with `access-decision-manager-ref`" , element );
81
+ return null ;
82
+ }
70
83
this .authorizationManagerRef = createAuthorizationManager (element , parserContext );
71
84
BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder .rootBeanDefinition (AuthorizationFilter .class );
72
85
filterBuilder .getRawBeanDefinition ().setSource (parserContext .extractSource (element ));
73
86
BeanDefinition filter = filterBuilder .addConstructorArgReference (this .authorizationManagerRef )
87
+ .addPropertyValue ("securityContextHolderStrategy" , this .securityContextHolderStrategy )
74
88
.getBeanDefinition ();
75
89
String id = element .getAttribute (AbstractBeanDefinitionParser .ID_ATTRIBUTE );
76
90
if (StringUtils .hasText (id )) {
@@ -172,7 +186,9 @@ static class DefaultWebSecurityExpressionHandlerBeanFactory
172
186
173
187
@ Override
174
188
public DefaultHttpSecurityExpressionHandler getBean () {
175
- this .handler .setDefaultRolePrefix (this .rolePrefix );
189
+ if (this .rolePrefix != null ) {
190
+ this .handler .setDefaultRolePrefix (this .rolePrefix );
191
+ }
176
192
return this .handler ;
177
193
}
178
194
0 commit comments