|
|
|
@ -1,51 +1,47 @@ |
|
|
|
package org.springframework.security.config.http; |
|
|
|
package org.springframework.security.config.http; |
|
|
|
|
|
|
|
|
|
|
|
import java.security.Principal |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Iterator; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.security.Principal |
|
|
|
import javax.servlet.Filter |
|
|
|
import javax.servlet.Filter |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeansException |
|
|
|
import org.springframework.beans.BeansException |
|
|
|
import org.springframework.beans.factory.BeanCreationException; |
|
|
|
import org.springframework.beans.factory.BeanCreationException |
|
|
|
import org.springframework.mock.web.MockFilterChain; |
|
|
|
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer |
|
|
|
import org.springframework.mock.web.MockHttpServletRequest; |
|
|
|
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException |
|
|
|
import org.springframework.mock.web.MockHttpServletResponse; |
|
|
|
import org.springframework.mock.web.MockFilterChain |
|
|
|
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; |
|
|
|
import org.springframework.mock.web.MockHttpServletRequest |
|
|
|
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; |
|
|
|
import org.springframework.mock.web.MockHttpServletResponse |
|
|
|
import org.springframework.context.support.AbstractXmlApplicationContext |
|
|
|
|
|
|
|
import org.springframework.security.config.BeanIds; |
|
|
|
|
|
|
|
import org.springframework.security.config.util.InMemoryXmlApplicationContext; |
|
|
|
|
|
|
|
import org.springframework.security.core.authority.AuthorityUtils; |
|
|
|
|
|
|
|
import org.springframework.security.core.context.SecurityContext |
|
|
|
|
|
|
|
import org.springframework.security.core.context.SecurityContextHolder; |
|
|
|
|
|
|
|
import org.springframework.security.util.FieldUtils; |
|
|
|
|
|
|
|
import org.springframework.security.access.AccessDeniedException |
|
|
|
import org.springframework.security.access.AccessDeniedException |
|
|
|
import org.springframework.security.access.SecurityConfig; |
|
|
|
import org.springframework.security.access.SecurityConfig |
|
|
|
import org.springframework.security.authentication.TestingAuthenticationToken |
|
|
|
import org.springframework.security.authentication.TestingAuthenticationToken |
|
|
|
import org.springframework.security.config.MockUserServiceBeanPostProcessor; |
|
|
|
import org.springframework.security.config.BeanIds |
|
|
|
import org.springframework.security.config.PostProcessedMockUserDetailsService; |
|
|
|
import org.springframework.security.config.MockUserServiceBeanPostProcessor |
|
|
|
import org.springframework.security.web.*; |
|
|
|
import org.springframework.security.config.PostProcessedMockUserDetailsService |
|
|
|
import org.springframework.security.web.access.channel.ChannelProcessingFilter; |
|
|
|
import org.springframework.security.config.util.InMemoryXmlApplicationContext |
|
|
|
import org.springframework.security.web.access.ExceptionTranslationFilter; |
|
|
|
import org.springframework.security.core.authority.AuthorityUtils |
|
|
|
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor; |
|
|
|
import org.springframework.security.core.context.SecurityContext |
|
|
|
import org.springframework.security.web.authentication.* |
|
|
|
import org.springframework.security.core.context.SecurityContextHolder |
|
|
|
|
|
|
|
import org.springframework.security.openid.OpenIDAuthenticationFilter |
|
|
|
|
|
|
|
import org.springframework.security.util.FieldUtils |
|
|
|
|
|
|
|
import org.springframework.security.web.FilterChainProxy |
|
|
|
|
|
|
|
import org.springframework.security.web.PortMapperImpl |
|
|
|
|
|
|
|
import org.springframework.security.web.access.ExceptionTranslationFilter |
|
|
|
|
|
|
|
import org.springframework.security.web.access.channel.ChannelProcessingFilter |
|
|
|
|
|
|
|
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor |
|
|
|
|
|
|
|
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter |
|
|
|
|
|
|
|
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint |
|
|
|
|
|
|
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter |
|
|
|
import org.springframework.security.web.authentication.logout.LogoutFilter |
|
|
|
import org.springframework.security.web.authentication.logout.LogoutFilter |
|
|
|
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler |
|
|
|
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler |
|
|
|
import org.springframework.security.web.authentication.preauth.x509.X509AuthenticationFilter |
|
|
|
import org.springframework.security.web.authentication.preauth.x509.X509AuthenticationFilter |
|
|
|
import org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter |
|
|
|
import org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter |
|
|
|
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint |
|
|
|
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint |
|
|
|
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter |
|
|
|
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter |
|
|
|
import org.springframework.security.web.context.*; |
|
|
|
import org.springframework.security.web.context.HttpSessionSecurityContextRepository |
|
|
|
|
|
|
|
import org.springframework.security.web.context.SecurityContextPersistenceFilter |
|
|
|
import org.springframework.security.web.savedrequest.HttpSessionRequestCache |
|
|
|
import org.springframework.security.web.savedrequest.HttpSessionRequestCache |
|
|
|
import org.springframework.security.web.savedrequest.RequestCacheAwareFilter; |
|
|
|
import org.springframework.security.web.savedrequest.RequestCacheAwareFilter |
|
|
|
import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter; |
|
|
|
import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter |
|
|
|
import org.springframework.security.web.session.SessionManagementFilter; |
|
|
|
import org.springframework.security.web.session.SessionManagementFilter |
|
|
|
|
|
|
|
|
|
|
|
import groovy.lang.Closure |
|
|
|
|
|
|
|
import org.springframework.security.openid.OpenIDAuthenticationFilter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MiscHttpConfigTests extends AbstractHttpConfigTests { |
|
|
|
class MiscHttpConfigTests extends AbstractHttpConfigTests { |
|
|
|
def 'Minimal configuration parses'() { |
|
|
|
def 'Minimal configuration parses'() { |
|
|
|
@ -87,6 +83,7 @@ class MiscHttpConfigTests extends AbstractHttpConfigTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def filterListShouldBeEmptyForPatternWithNoFilters() { |
|
|
|
def filterListShouldBeEmptyForPatternWithNoFilters() { |
|
|
|
|
|
|
|
xml.debug() |
|
|
|
xml.http(pattern: '/unprotected', security: 'none') |
|
|
|
xml.http(pattern: '/unprotected', security: 'none') |
|
|
|
httpAutoConfig() {} |
|
|
|
httpAutoConfig() {} |
|
|
|
createAppContext() |
|
|
|
createAppContext() |
|
|
|
@ -95,6 +92,20 @@ class MiscHttpConfigTests extends AbstractHttpConfigTests { |
|
|
|
getFilters("/unprotected").size() == 0 |
|
|
|
getFilters("/unprotected").size() == 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def debugFilterHandlesMissingAndEmptyFilterChains() { |
|
|
|
|
|
|
|
when: |
|
|
|
|
|
|
|
xml.debug() |
|
|
|
|
|
|
|
xml.http(pattern: '/unprotected', security: 'none') |
|
|
|
|
|
|
|
createAppContext() |
|
|
|
|
|
|
|
then: |
|
|
|
|
|
|
|
Filter debugFilter = appContext.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN); |
|
|
|
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest() |
|
|
|
|
|
|
|
request.setServletPath("/unprotected"); |
|
|
|
|
|
|
|
debugFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()); |
|
|
|
|
|
|
|
request.setServletPath("/nomatch"); |
|
|
|
|
|
|
|
debugFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def regexPathsWorkCorrectly() { |
|
|
|
def regexPathsWorkCorrectly() { |
|
|
|
xml.http(pattern: '\\A\\/[a-z]+', security: 'none', 'request-matcher': 'regex') |
|
|
|
xml.http(pattern: '\\A\\/[a-z]+', security: 'none', 'request-matcher': 'regex') |
|
|
|
httpAutoConfig() {} |
|
|
|
httpAutoConfig() {} |
|
|
|
@ -422,7 +433,7 @@ class MiscHttpConfigTests extends AbstractHttpConfigTests { |
|
|
|
|
|
|
|
|
|
|
|
expect: |
|
|
|
expect: |
|
|
|
filter.repo == appContext.getBean('repo') |
|
|
|
filter.repo == appContext.getBean('repo') |
|
|
|
filter.forceEagerSessionCreation == true |
|
|
|
filter.forceEagerSessionCreation |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def expressionBasedAccessAllowsAndDeniesAccessAsExpected() { |
|
|
|
def expressionBasedAccessAllowsAndDeniesAccessAsExpected() { |
|
|
|
@ -461,7 +472,7 @@ class MiscHttpConfigTests extends AbstractHttpConfigTests { |
|
|
|
createAppContext() |
|
|
|
createAppContext() |
|
|
|
|
|
|
|
|
|
|
|
expect: |
|
|
|
expect: |
|
|
|
getFilter(SecurityContextPersistenceFilter).repo.disableUrlRewriting == true |
|
|
|
getFilter(SecurityContextPersistenceFilter).repo.disableUrlRewriting |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def userDetailsServiceInParentContextIsLocatedSuccessfully() { |
|
|
|
def userDetailsServiceInParentContextIsLocatedSuccessfully() { |
|
|
|
@ -478,18 +489,19 @@ class MiscHttpConfigTests extends AbstractHttpConfigTests { |
|
|
|
|
|
|
|
|
|
|
|
def httpConfigWithNoAuthProvidersWorksOk() { |
|
|
|
def httpConfigWithNoAuthProvidersWorksOk() { |
|
|
|
when: "Http config has no internal authentication providers" |
|
|
|
when: "Http config has no internal authentication providers" |
|
|
|
|
|
|
|
xml.debug() |
|
|
|
xml.http() { |
|
|
|
xml.http() { |
|
|
|
'form-login'() |
|
|
|
'form-login'() |
|
|
|
anonymous(enabled: 'false') |
|
|
|
anonymous(enabled: 'false') |
|
|
|
} |
|
|
|
} |
|
|
|
createAppContext() |
|
|
|
createAppContext() |
|
|
|
FilterChainProxy fcp = appContext.getBean(BeanIds.FILTER_CHAIN_PROXY); |
|
|
|
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/j_spring_security_check"); |
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/j_spring_security_check"); |
|
|
|
request.setServletPath("/j_spring_security_check"); |
|
|
|
request.setServletPath("/j_spring_security_check"); |
|
|
|
request.addParameter("j_username", "bob"); |
|
|
|
request.addParameter("j_username", "bob"); |
|
|
|
request.addParameter("j_password", "bob"); |
|
|
|
request.addParameter("j_password", "bob"); |
|
|
|
then: "App context creation and login request succeed" |
|
|
|
then: "App context creation and login request succeed" |
|
|
|
fcp.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()); |
|
|
|
Filter debugFilter = appContext.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN); |
|
|
|
|
|
|
|
debugFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def eraseCredentialsDefaultsToTrue() { |
|
|
|
def eraseCredentialsDefaultsToTrue() { |
|
|
|
@ -498,7 +510,7 @@ class MiscHttpConfigTests extends AbstractHttpConfigTests { |
|
|
|
} |
|
|
|
} |
|
|
|
createAppContext() |
|
|
|
createAppContext() |
|
|
|
expect: |
|
|
|
expect: |
|
|
|
getFilter(UsernamePasswordAuthenticationFilter).authenticationManager.eraseCredentialsAfterAuthentication == true |
|
|
|
getFilter(UsernamePasswordAuthenticationFilter).authenticationManager.eraseCredentialsAfterAuthentication |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def eraseCredentialsIsSetFromParentAuthenticationManager() { |
|
|
|
def eraseCredentialsIsSetFromParentAuthenticationManager() { |
|
|
|
@ -507,7 +519,7 @@ class MiscHttpConfigTests extends AbstractHttpConfigTests { |
|
|
|
} |
|
|
|
} |
|
|
|
createAppContext("<authentication-manager erase-credentials='false' />"); |
|
|
|
createAppContext("<authentication-manager erase-credentials='false' />"); |
|
|
|
expect: |
|
|
|
expect: |
|
|
|
getFilter(UsernamePasswordAuthenticationFilter).authenticationManager.eraseCredentialsAfterAuthentication == false |
|
|
|
!getFilter(UsernamePasswordAuthenticationFilter).authenticationManager.eraseCredentialsAfterAuthentication |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def jeeFilterExtractsExpectedRoles() { |
|
|
|
def jeeFilterExtractsExpectedRoles() { |
|
|
|
|