Skip to content

Commit 4542f00

Browse files
committed
SEC-975: Namespace security syntax does not interpret properties
http://jira.springframework.org/browse/SEC-975. Changed creation of AccessDeniedHandler to use a BeanDefinition to make sure placeholders work OK.
1 parent 5e4634d commit 4542f00

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

core/src/main/java/org/springframework/security/config/HttpSecurityBeanDefinitionParser.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ private void registerExceptionTranslationFilter(Element element, ParserContext p
273273
exceptionTranslationFilterBuilder.addPropertyValue("createSessionAllowed", new Boolean(allowSessionCreation));
274274

275275
if (StringUtils.hasText(accessDeniedPage)) {
276-
AccessDeniedHandlerImpl accessDeniedHandler = new AccessDeniedHandlerImpl();
277-
accessDeniedHandler.setErrorPage(accessDeniedPage);
276+
BeanDefinition accessDeniedHandler = new RootBeanDefinition(AccessDeniedHandlerImpl.class);
277+
accessDeniedHandler.getPropertyValues().addPropertyValue("errorPage", accessDeniedPage);
278278
exceptionTranslationFilterBuilder.addPropertyValue("accessDeniedHandler", accessDeniedHandler);
279279
}
280280

core/src/test/java/org/springframework/security/config/HttpSecurityBeanDefinitionParserTests.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public void accessDeniedPageAttributeIsSupported() throws Exception {
267267
assertEquals("/access-denied", FieldUtils.getFieldValue(etf, "accessDeniedHandler.errorPage"));
268268
}
269269

270-
@Test(expected=BeanDefinitionStoreException.class)
270+
@Test(expected=BeanCreationException.class)
271271
public void invalidAccessDeniedUrlIsDetected() throws Exception {
272272
setContext("<http auto-config='true' access-denied-page='noLeadingSlash'/>" + AUTH_PROVIDER_XML);
273273
}
@@ -318,6 +318,16 @@ public void portMappingsWorkWithPlaceholders() throws Exception {
318318
assertEquals(Integer.valueOf(9443), pm.lookupHttpsPort(9080));
319319
}
320320

321+
@Test
322+
public void accessDeniedPageWorkWithPlaceholders() throws Exception {
323+
System.setProperty("accessDenied", "/go-away");
324+
setContext(
325+
" <b:bean id='configurer' class='org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'/>" +
326+
" <http auto-config='true' access-denied-page='${accessDenied}'/>" + AUTH_PROVIDER_XML);
327+
ExceptionTranslationFilter filter = (ExceptionTranslationFilter) appContext.getBean(BeanIds.EXCEPTION_TRANSLATION_FILTER);
328+
assertEquals("/go-away", FieldUtils.getFieldValue(filter, "accessDeniedHandler.errorPage"));
329+
}
330+
321331
@Test
322332
public void externalFiltersAreTreatedCorrectly() throws Exception {
323333
// Decorated user-filters should be added to stack. The others should be ignored.

0 commit comments

Comments
 (0)