SEC-2192: Create DEFAULT_FILTER_NAME
This commit is contained in:
parent
cd34c47643
commit
cf80cc88b5
|
@ -40,6 +40,7 @@ import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||||
import org.springframework.security.web.FilterChainProxy;
|
import org.springframework.security.web.FilterChainProxy;
|
||||||
import org.springframework.security.web.FilterInvocation;
|
import org.springframework.security.web.FilterInvocation;
|
||||||
import org.springframework.security.web.access.WebInvocationPrivilegeEvaluator;
|
import org.springframework.security.web.access.WebInvocationPrivilegeEvaluator;
|
||||||
|
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,6 +56,7 @@ import org.springframework.util.ClassUtils;
|
||||||
* @see WebSecurity
|
* @see WebSecurity
|
||||||
*
|
*
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
|
* @author Keesun Baik
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ -66,7 +68,7 @@ public class WebSecurityConfiguration implements ImportAware, BeanClassLoaderAwa
|
||||||
private ClassLoader beanClassLoader;
|
private ClassLoader beanClassLoader;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@DependsOn("springSecurityFilterChain")
|
@DependsOn(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME)
|
||||||
public SecurityExpressionHandler<FilterInvocation> webSecurityExpressionHandler() {
|
public SecurityExpressionHandler<FilterInvocation> webSecurityExpressionHandler() {
|
||||||
return webSecurity.getExpressionHandler();
|
return webSecurity.getExpressionHandler();
|
||||||
}
|
}
|
||||||
|
@ -76,7 +78,7 @@ public class WebSecurityConfiguration implements ImportAware, BeanClassLoaderAwa
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Bean(name="springSecurityFilterChain")
|
@Bean(name=AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME)
|
||||||
public Filter springSecurityFilterChain() throws Exception {
|
public Filter springSecurityFilterChain() throws Exception {
|
||||||
boolean hasConfigurers = webSecurityConfigurers != null && !webSecurityConfigurers.isEmpty();
|
boolean hasConfigurers = webSecurityConfigurers != null && !webSecurityConfigurers.isEmpty();
|
||||||
if(!hasConfigurers) {
|
if(!hasConfigurers) {
|
||||||
|
@ -91,7 +93,7 @@ public class WebSecurityConfiguration implements ImportAware, BeanClassLoaderAwa
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@DependsOn("springSecurityFilterChain")
|
@DependsOn(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME)
|
||||||
public WebInvocationPrivilegeEvaluator privilegeEvaluator() throws Exception {
|
public WebInvocationPrivilegeEvaluator privilegeEvaluator() throws Exception {
|
||||||
return webSecurity.getPrivilegeEvaluator();
|
return webSecurity.getPrivilegeEvaluator();
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,11 +66,14 @@ import org.springframework.web.filter.DelegatingFilterProxy;
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
|
* @author Keesun Baik
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSecurityWebApplicationInitializer implements WebApplicationInitializer {
|
public abstract class AbstractSecurityWebApplicationInitializer implements WebApplicationInitializer {
|
||||||
|
|
||||||
private static final String SERVLET_CONTEXT_PREFIX = "org.springframework.web.servlet.FrameworkServlet.CONTEXT.";
|
private static final String SERVLET_CONTEXT_PREFIX = "org.springframework.web.servlet.FrameworkServlet.CONTEXT.";
|
||||||
|
|
||||||
|
public static final String DEFAULT_FILTER_NAME = "springSecurityFilterChain";
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext)
|
* @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext)
|
||||||
*/
|
*/
|
||||||
|
@ -100,7 +103,7 @@ public abstract class AbstractSecurityWebApplicationInitializer implements WebAp
|
||||||
* @param servletContext the {@link ServletContext}
|
* @param servletContext the {@link ServletContext}
|
||||||
*/
|
*/
|
||||||
private void insertSpringSecurityFilterChain(ServletContext servletContext) {
|
private void insertSpringSecurityFilterChain(ServletContext servletContext) {
|
||||||
String filterName = "springSecurityFilterChain";
|
String filterName = DEFAULT_FILTER_NAME;
|
||||||
DelegatingFilterProxy springSecurityFilterChain = new DelegatingFilterProxy(filterName);
|
DelegatingFilterProxy springSecurityFilterChain = new DelegatingFilterProxy(filterName);
|
||||||
String contextAttribute = getWebApplicationContextAttribute();
|
String contextAttribute = getWebApplicationContextAttribute();
|
||||||
if(contextAttribute != null) {
|
if(contextAttribute != null) {
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package org.springframework.security.web.context;
|
||||||
|
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Keesun Baik
|
||||||
|
*/
|
||||||
|
public class AbstractSecurityWebApplicationInitializerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void defaultFilterName() {
|
||||||
|
assertEquals(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME, "springSecurityFilterChain");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue