Add GlobalMethodSecurityConfiguration Test

Issue gh-9845
This commit is contained in:
Josh Cummings 2021-06-08 17:18:11 -06:00
parent 7a233c41f0
commit 5b49433ed1
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
1 changed files with 26 additions and 0 deletions

View File

@ -37,6 +37,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
import org.springframework.security.access.hierarchicalroles.RoleHierarchy;
import org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl;
import org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor;
@ -194,6 +195,15 @@ public class GlobalMethodSecurityConfigurationTests {
assertThat(pp.afterInit).containsKeys("dataSource");
}
// SEC-9845
@Test
public void enableGlobalMethodSecurityWhenBeanPostProcessorThenInvokedForDefaultMethodSecurityExpressionHandler() {
this.spring.register(Sec9845Config.class).autowire();
MockBeanPostProcessor pp = this.spring.getContext().getBean(MockBeanPostProcessor.class);
assertThat(pp.beforeInitClass).containsKeys(DefaultMethodSecurityExpressionHandler.class);
assertThat(pp.afterInitClass).containsKeys(DefaultMethodSecurityExpressionHandler.class);
}
// SEC-3045
@Test
public void globalSecurityProxiesSecurity() {
@ -441,21 +451,37 @@ public class GlobalMethodSecurityConfigurationTests {
}
@EnableGlobalMethodSecurity(prePostEnabled = true)
static class Sec9845Config {
@Bean
BeanPostProcessor mockBeanPostProcessor() {
return new MockBeanPostProcessor();
}
}
static class MockBeanPostProcessor implements BeanPostProcessor {
Map<String, Object> beforeInit = new HashMap<>();
Map<String, Object> afterInit = new HashMap<>();
Map<Class<?>, Object> beforeInitClass = new HashMap<>();
Map<Class<?>, Object> afterInitClass = new HashMap<>();
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
this.beforeInit.put(beanName, bean);
this.beforeInitClass.put(bean.getClass(), bean);
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
this.afterInit.put(beanName, bean);
this.afterInitClass.put(bean.getClass(), bean);
return bean;
}