SEC-2499: Allow MethodSecurityExpressionHandler in parent context
Previously a NoSuchBeanDefintionException was thrown when the MethodSecurityExpressionHandler was defined in the parent context. This happened due to trying to work around ordering issues related to SEC-2136 This commit resolves this by not marking the MethodSecurityExpressionHandler bean as lazy unless it exists.
This commit is contained in:
parent
9988fa141c
commit
4cdeacc277
config/src
main/java/org/springframework/security/config/method
test
java/org/springframework/security/config/method/sec2499
resources/org/springframework/security/config/method/sec2499
|
@ -452,6 +452,9 @@ public class GlobalMethodSecurityBeanDefinitionParser implements BeanDefinitionP
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
|
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
|
||||||
|
if(!registry.containsBeanDefinition(beanName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);
|
BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);
|
||||||
beanDefinition.setLazyInit(true);
|
beanDefinition.setLazyInit(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2014 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.security.config.method.sec2499;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Rob Winch
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Sec2499Tests {
|
||||||
|
private GenericXmlApplicationContext parent;
|
||||||
|
|
||||||
|
private GenericXmlApplicationContext child;
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void cleanup() {
|
||||||
|
if(parent != null) {
|
||||||
|
parent.close();
|
||||||
|
}
|
||||||
|
if(child != null) {
|
||||||
|
child.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void methodExpressionHandlerInParentContextLoads() {
|
||||||
|
parent = new GenericXmlApplicationContext("org/springframework/security/config/method/sec2499/parent.xml");
|
||||||
|
child = new GenericXmlApplicationContext();
|
||||||
|
child.load("org/springframework/security/config/method/sec2499/child.xml");
|
||||||
|
child.setParent(parent);
|
||||||
|
child.refresh();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<b:beans xmlns:b="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://www.springframework.org/schema/security"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
|
||||||
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
|
||||||
|
<global-method-security pre-post-annotations="enabled">
|
||||||
|
<expression-handler ref="expressionHandler"/>
|
||||||
|
</global-method-security>
|
||||||
|
|
||||||
|
</b:beans>
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
|
||||||
|
<bean id="expressionHandler"
|
||||||
|
class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler"/>
|
||||||
|
|
||||||
|
</beans>
|
Loading…
Reference in New Issue