From 14b9050616622618dc7958f7530c8826cc9f9d77 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Mon, 14 Oct 2013 10:36:31 -0500 Subject: [PATCH] SEC-2357: Move *RequestMatchers to .matchers package --- .../web/AbstractRequestMatcherConfigurer.java | 26 +- .../annotation/web/builders/HttpSecurity.java | 10 +- ...bstractAuthenticationFilterConfigurer.java | 2 +- .../web/configurers/FormLoginConfigurer.java | 2 +- .../web/configurers/HttpBasicConfigurer.java | 4 +- .../web/configurers/LogoutConfigurer.java | 2 +- .../configurers/RequestCacheConfigurer.java | 10 +- .../openid/OpenIDLoginConfigurer.java | 2 +- .../http/DefaultFilterChainValidator.java | 6 +- .../config/http/HttpConfigurationBuilder.java | 2 +- .../HttpSecurityBeanDefinitionParser.java | 2 +- .../security/config/http/MatcherType.java | 6 +- .../web/RequestMatchersTests.groovy | 4 +- .../web/builders/NamespaceHttpTests.groovy | 2 +- .../WebSecurityConfigurationTests.groovy | 2 +- ...equestMatcherMappingConfigurerTests.groovy | 4 +- .../configurers/DefaultFiltersTests.groovy | 2 +- .../FormLoginConfigurerTests.groovy | 2 +- .../configurers/NamespaceDebugTests.groovy | 4 +- .../NamespaceHttpCustomFilterTests.groovy | 4 +- .../NamespaceHttpHeadersTests.groovy | 4 +- .../configurers/NamespaceHttpJeeTests.groovy | 4 +- .../NamespaceHttpLogoutTests.groovy | 4 +- .../config/http/HttpHeadersConfigTests.groovy | 2 +- .../http/InterceptUrlConfigTests.groovy | 2 +- .../config/http/MiscHttpConfigTests.groovy | 2 +- .../config/FilterChainProxyConfigTests.java | 4 +- .../DefaultFilterChainValidatorTests.java | 4 +- .../security/util/filtertest-valid.xml | 10 +- docs/manual/src/asciidoctor/index.adoc | 22 +- .../expression/WebSecurityExpressionRoot.java | 2 +- .../DelegatingAuthenticationEntryPoint.java | 2 +- .../savedrequest/HttpSessionRequestCache.java | 4 +- .../web/util/AntPathRequestMatcher.java | 140 +--------- .../security/web/util/AnyRequestMatcher.java | 8 +- .../security/web/util/ELRequestMatcher.java | 14 +- .../web/util/RegexRequestMatcher.java | 45 +--- .../web/util/RequestMatcherEditor.java | 9 +- .../{ => matchers}/AndRequestMatcher.java | 3 +- .../util/matchers/AntPathRequestMatcher.java | 243 ++++++++++++++++++ .../web/util/matchers/AnyRequestMatcher.java | 47 ++++ .../web/util/matchers/ELRequestMatcher.java | 63 +++++ .../ELRequestMatcherContext.java | 2 +- .../util/{ => matchers}/IpAddressMatcher.java | 3 +- .../MediaTypeRequestMatcher.java | 3 +- .../{ => matchers}/NegatedRequestMatcher.java | 3 +- .../util/{ => matchers}/OrRequestMatcher.java | 3 +- .../util/matchers/RegexRequestMatcher.java | 105 ++++++++ .../RequestHeaderRequestMatcher.java | 3 +- ...InvocationSecurityMetadataSourceTests.java | 6 +- ...InvocationSecurityMetadataSourceTests.java | 2 +- .../header/writers/HstsHeaderWriterTests.java | 8 +- .../AndRequestMatcherTests.java | 4 +- .../AntPathRequestMatcherTests.java | 6 +- .../{ => matchers}/ELRequestMatcherTests.java | 3 +- .../{ => matchers}/IpAddressMatcherTests.java | 3 +- ...diaTypeRequestMatcherRequestHCNSTests.java | 3 +- .../MediaTypeRequestMatcherTests.java | 3 +- .../NegatedRequestMatcherTests.java | 4 +- .../{ => matchers}/OrRequestMatcherTests.java | 4 +- .../RegexRequestMatcherTests.java | 3 +- .../RequestHeaderRequestMatcherTests.java | 3 +- 62 files changed, 616 insertions(+), 294 deletions(-) rename web/src/main/java/org/springframework/security/web/util/{ => matchers}/AndRequestMatcher.java (95%) create mode 100644 web/src/main/java/org/springframework/security/web/util/matchers/AntPathRequestMatcher.java create mode 100644 web/src/main/java/org/springframework/security/web/util/matchers/AnyRequestMatcher.java create mode 100644 web/src/main/java/org/springframework/security/web/util/matchers/ELRequestMatcher.java rename web/src/main/java/org/springframework/security/web/util/{ => matchers}/ELRequestMatcherContext.java (95%) rename web/src/main/java/org/springframework/security/web/util/{ => matchers}/IpAddressMatcher.java (95%) rename web/src/main/java/org/springframework/security/web/util/{ => matchers}/MediaTypeRequestMatcher.java (98%) rename web/src/main/java/org/springframework/security/web/util/{ => matchers}/NegatedRequestMatcher.java (94%) rename web/src/main/java/org/springframework/security/web/util/{ => matchers}/OrRequestMatcher.java (95%) create mode 100644 web/src/main/java/org/springframework/security/web/util/matchers/RegexRequestMatcher.java rename web/src/main/java/org/springframework/security/web/util/{ => matchers}/RequestHeaderRequestMatcher.java (96%) rename web/src/test/java/org/springframework/security/web/util/{ => matchers}/AndRequestMatcherTests.java (94%) rename web/src/test/java/org/springframework/security/web/util/{ => matchers}/AntPathRequestMatcherTests.java (95%) rename web/src/test/java/org/springframework/security/web/util/{ => matchers}/ELRequestMatcherTests.java (95%) rename web/src/test/java/org/springframework/security/web/util/{ => matchers}/IpAddressMatcherTests.java (94%) rename web/src/test/java/org/springframework/security/web/util/{ => matchers}/MediaTypeRequestMatcherRequestHCNSTests.java (97%) rename web/src/test/java/org/springframework/security/web/util/{ => matchers}/MediaTypeRequestMatcherTests.java (98%) rename web/src/test/java/org/springframework/security/web/util/{ => matchers}/NegatedRequestMatcherTests.java (89%) rename web/src/test/java/org/springframework/security/web/util/{ => matchers}/OrRequestMatcherTests.java (94%) rename web/src/test/java/org/springframework/security/web/util/{ => matchers}/RegexRequestMatcherTests.java (96%) rename web/src/test/java/org/springframework/security/web/util/{ => matchers}/RequestHeaderRequestMatcherTests.java (95%) diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/AbstractRequestMatcherConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/web/AbstractRequestMatcherConfigurer.java index 09f6ab2ade..5cb70bf764 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/AbstractRequestMatcherConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/AbstractRequestMatcherConfigurer.java @@ -23,9 +23,9 @@ import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.SecurityBuilder; import org.springframework.security.config.annotation.SecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configurers.AbstractRequestMatcherMappingConfigurer; -import org.springframework.security.web.util.AntPathRequestMatcher; -import org.springframework.security.web.util.AnyRequestMatcher; -import org.springframework.security.web.util.RegexRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher; +import org.springframework.security.web.util.matchers.AnyRequestMatcher; +import org.springframework.security.web.util.matchers.RegexRequestMatcher; import org.springframework.security.web.util.RequestMatcher; /** @@ -41,12 +41,12 @@ import org.springframework.security.web.util.RequestMatcher; * @since 3.2 */ public abstract class AbstractRequestMatcherConfigurer,C,O> extends SecurityConfigurerAdapter { - private static final RequestMatcher ANY_REQUEST = new AnyRequestMatcher(); + private static final RequestMatcher ANY_REQUEST = AnyRequestMatcher.INSTANCE; /** * Maps any request. * * @param method the {@link HttpMethod} to use or {@code null} for any {@link HttpMethod}. - * @param antPatterns the ant patterns to create {@link org.springframework.security.web.util.AntPathRequestMatcher} + * @param antPatterns the ant patterns to create {@link org.springframework.security.web.util.matchers.AntPathRequestMatcher} * from * * @return the object that is chained after creating the {@link RequestMatcher} @@ -56,10 +56,10 @@ public abstract class AbstractRequestMatcherConfigurer implements SecurityBuilder, HttpSecurityBuilder { private final RequestMatcherConfigurer requestMatcherConfigurer = new RequestMatcherConfigurer(); private List filters = new ArrayList(); - private RequestMatcher requestMatcher = new AnyRequestMatcher(); + private RequestMatcher requestMatcher = AnyRequestMatcher.INSTANCE; private FilterComparator comparitor = new FilterComparator(); /** diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/AbstractAuthenticationFilterConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/AbstractAuthenticationFilterConfigurer.java index f1e04e55a1..a0252ece04 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/AbstractAuthenticationFilterConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/AbstractAuthenticationFilterConfigurer.java @@ -36,8 +36,8 @@ import org.springframework.security.web.authentication.SavedRequestAwareAuthenti import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; -import org.springframework.security.web.util.MediaTypeRequestMatcher; import org.springframework.security.web.util.RequestMatcher; +import org.springframework.security.web.util.matchers.MediaTypeRequestMatcher; import org.springframework.web.accept.ContentNegotiationStrategy; import org.springframework.web.accept.HeaderContentNegotiationStrategy; diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/FormLoginConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/FormLoginConfigurer.java index 42ab6db7ac..c937d4ea64 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/FormLoginConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/FormLoginConfigurer.java @@ -23,7 +23,7 @@ import org.springframework.security.web.authentication.RememberMeServices; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; import org.springframework.security.web.authentication.ui.DefaultLoginPageViewFilter; -import org.springframework.security.web.util.AntPathRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher; import org.springframework.security.web.util.RequestMatcher; /** diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/HttpBasicConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/HttpBasicConfigurer.java index 55fece397c..149871b1db 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/HttpBasicConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/HttpBasicConfigurer.java @@ -35,9 +35,9 @@ import org.springframework.security.web.authentication.DelegatingAuthenticationE import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint; import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; -import org.springframework.security.web.util.MediaTypeRequestMatcher; -import org.springframework.security.web.util.RequestHeaderRequestMatcher; import org.springframework.security.web.util.RequestMatcher; +import org.springframework.security.web.util.matchers.MediaTypeRequestMatcher; +import org.springframework.security.web.util.matchers.RequestHeaderRequestMatcher; import org.springframework.web.accept.ContentNegotiationStrategy; import org.springframework.web.accept.HeaderContentNegotiationStrategy; diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/LogoutConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/LogoutConfigurer.java index 77763a860e..f4c5bab12d 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/LogoutConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/LogoutConfigurer.java @@ -30,7 +30,7 @@ import org.springframework.security.web.authentication.logout.LogoutSuccessHandl import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler; import org.springframework.security.web.authentication.ui.DefaultLoginPageViewFilter; -import org.springframework.security.web.util.AntPathRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher; import org.springframework.security.web.util.RequestMatcher; /** diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/RequestCacheConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/RequestCacheConfigurer.java index 762046ba1d..d02de2655b 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/RequestCacheConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/RequestCacheConfigurer.java @@ -23,12 +23,12 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.web.savedrequest.HttpSessionRequestCache; import org.springframework.security.web.savedrequest.RequestCache; import org.springframework.security.web.savedrequest.RequestCacheAwareFilter; -import org.springframework.security.web.util.AndRequestMatcher; -import org.springframework.security.web.util.AntPathRequestMatcher; -import org.springframework.security.web.util.MediaTypeRequestMatcher; -import org.springframework.security.web.util.NegatedRequestMatcher; -import org.springframework.security.web.util.RequestHeaderRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher; import org.springframework.security.web.util.RequestMatcher; +import org.springframework.security.web.util.matchers.AndRequestMatcher; +import org.springframework.security.web.util.matchers.MediaTypeRequestMatcher; +import org.springframework.security.web.util.matchers.NegatedRequestMatcher; +import org.springframework.security.web.util.matchers.RequestHeaderRequestMatcher; import org.springframework.web.accept.ContentNegotiationStrategy; import org.springframework.web.accept.HeaderContentNegotiationStrategy; diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/openid/OpenIDLoginConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/openid/OpenIDLoginConfigurer.java index fb3ae2ab39..c232295e4f 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/openid/OpenIDLoginConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/openid/OpenIDLoginConfigurer.java @@ -50,7 +50,7 @@ import org.springframework.security.web.authentication.LoginUrlAuthenticationEnt import org.springframework.security.web.authentication.RememberMeServices; import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; import org.springframework.security.web.authentication.ui.DefaultLoginPageViewFilter; -import org.springframework.security.web.util.AntPathRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher; import org.springframework.security.web.util.RequestMatcher; /** diff --git a/config/src/main/java/org/springframework/security/config/http/DefaultFilterChainValidator.java b/config/src/main/java/org/springframework/security/config/http/DefaultFilterChainValidator.java index e242cc89b0..e226d35a59 100644 --- a/config/src/main/java/org/springframework/security/config/http/DefaultFilterChainValidator.java +++ b/config/src/main/java/org/springframework/security/config/http/DefaultFilterChainValidator.java @@ -25,7 +25,8 @@ import org.springframework.security.web.context.SecurityContextPersistenceFilter import org.springframework.security.web.jaasapi.JaasApiIntegrationFilter; import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter; import org.springframework.security.web.session.SessionManagementFilter; -import org.springframework.security.web.util.AnyRequestMatcher; +import org.springframework.security.web.util.RequestMatcher; +import org.springframework.security.web.util.matchers.AnyRequestMatcher; public class DefaultFilterChainValidator implements FilterChainProxy.FilterChainValidator { private final Log logger = LogFactory.getLog(getClass()); @@ -45,7 +46,8 @@ public class DefaultFilterChainValidator implements FilterChainProxy.FilterChain Iterator chains = filterChains.iterator(); while (chains.hasNext()) { - if (((DefaultSecurityFilterChain)chains.next()).getRequestMatcher() instanceof AnyRequestMatcher && chains.hasNext()) { + RequestMatcher matcher = ((DefaultSecurityFilterChain)chains.next()).getRequestMatcher(); + if (AnyRequestMatcher.INSTANCE.equals(matcher) && chains.hasNext()) { throw new IllegalArgumentException("A universal match pattern ('/**') is defined " + " before other patterns in the filter chain, causing them to be ignored. Please check the " + "ordering in your namespace or FilterChainProxy bean configuration"); diff --git a/config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java b/config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java index 51272bf1ff..4f14cf267e 100644 --- a/config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java +++ b/config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java @@ -70,7 +70,7 @@ import org.springframework.security.web.servletapi.SecurityContextHolderAwareReq import org.springframework.security.web.session.ConcurrentSessionFilter; import org.springframework.security.web.session.SessionManagementFilter; import org.springframework.security.web.session.SimpleRedirectInvalidSessionStrategy; -import org.springframework.security.web.util.AntPathRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; diff --git a/config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java b/config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java index 5043db0e74..4d55d055c9 100644 --- a/config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java +++ b/config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java @@ -40,7 +40,7 @@ import org.springframework.security.config.authentication.AuthenticationManagerF import org.springframework.security.web.DefaultSecurityFilterChain; import org.springframework.security.web.FilterChainProxy; import org.springframework.security.web.PortResolverImpl; -import org.springframework.security.web.util.AnyRequestMatcher; +import org.springframework.security.web.util.matchers.AnyRequestMatcher; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; diff --git a/config/src/main/java/org/springframework/security/config/http/MatcherType.java b/config/src/main/java/org/springframework/security/config/http/MatcherType.java index 7cb211e9c7..1f94ee555a 100644 --- a/config/src/main/java/org/springframework/security/config/http/MatcherType.java +++ b/config/src/main/java/org/springframework/security/config/http/MatcherType.java @@ -5,9 +5,9 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.security.web.util.AntPathRequestMatcher; -import org.springframework.security.web.util.AnyRequestMatcher; -import org.springframework.security.web.util.RegexRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher; +import org.springframework.security.web.util.matchers.AnyRequestMatcher; +import org.springframework.security.web.util.matchers.RegexRequestMatcher; import org.springframework.security.web.util.RequestMatcher; import org.springframework.util.StringUtils; import org.w3c.dom.Element; diff --git a/config/src/test/groovy/org/springframework/security/config/annotation/web/RequestMatchersTests.groovy b/config/src/test/groovy/org/springframework/security/config/annotation/web/RequestMatchersTests.groovy index 2bf3316708..72e78921e3 100644 --- a/config/src/test/groovy/org/springframework/security/config/annotation/web/RequestMatchersTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/annotation/web/RequestMatchersTests.groovy @@ -18,8 +18,8 @@ package org.springframework.security.config.annotation.web; import static org.springframework.security.config.annotation.web.AbstractRequestMatcherConfigurer.RequestMatchers.* import org.springframework.http.HttpMethod; -import org.springframework.security.web.util.AntPathRequestMatcher; -import org.springframework.security.web.util.RegexRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher; +import org.springframework.security.web.util.matchers.RegexRequestMatcher; import spock.lang.Specification; diff --git a/config/src/test/groovy/org/springframework/security/config/annotation/web/builders/NamespaceHttpTests.groovy b/config/src/test/groovy/org/springframework/security/config/annotation/web/builders/NamespaceHttpTests.groovy index 0dc43cf254..2fcb88185d 100644 --- a/config/src/test/groovy/org/springframework/security/config/annotation/web/builders/NamespaceHttpTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/annotation/web/builders/NamespaceHttpTests.groovy @@ -50,7 +50,7 @@ import org.springframework.security.web.savedrequest.NullRequestCache import org.springframework.security.web.savedrequest.RequestCacheAwareFilter import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter import org.springframework.security.web.session.SessionManagementFilter -import org.springframework.security.web.util.RegexRequestMatcher +import org.springframework.security.web.util.matchers.RegexRequestMatcher import org.springframework.security.web.util.RequestMatcher /** diff --git a/config/src/test/groovy/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurationTests.groovy b/config/src/test/groovy/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurationTests.groovy index d520fb1027..d59e3a4284 100644 --- a/config/src/test/groovy/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurationTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurationTests.groovy @@ -40,7 +40,7 @@ import org.springframework.security.web.access.WebInvocationPrivilegeEvaluator; import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler; import org.springframework.security.web.access.expression.WebSecurityExpressionHandler; import org.springframework.security.web.access.intercept.FilterSecurityInterceptor; -import org.springframework.security.web.util.AnyRequestMatcher +import org.springframework.security.web.util.matchers.AnyRequestMatcher import org.springframework.test.util.ReflectionTestUtils; /** diff --git a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/AbstractRequestMatcherMappingConfigurerTests.groovy b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/AbstractRequestMatcherMappingConfigurerTests.groovy index b2c36c999b..61b9d149ac 100644 --- a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/AbstractRequestMatcherMappingConfigurerTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/AbstractRequestMatcherMappingConfigurerTests.groovy @@ -23,8 +23,8 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractRequestMatcherMappingConfigurer; import org.springframework.security.web.DefaultSecurityFilterChain; import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource; -import org.springframework.security.web.util.AntPathRequestMatcher; -import org.springframework.security.web.util.RegexRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher; +import org.springframework.security.web.util.matchers.RegexRequestMatcher; import org.springframework.security.web.util.RequestMatcher; import spock.lang.Specification; diff --git a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/DefaultFiltersTests.groovy b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/DefaultFiltersTests.groovy index 5c51ebc448..03eed5f529 100644 --- a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/DefaultFiltersTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/DefaultFiltersTests.groovy @@ -43,7 +43,7 @@ import org.springframework.security.web.header.HeaderWriterFilter import org.springframework.security.web.savedrequest.RequestCacheAwareFilter import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter import org.springframework.security.web.session.SessionManagementFilter -import org.springframework.security.web.util.AnyRequestMatcher +import org.springframework.security.web.util.matchers.AnyRequestMatcher /** * diff --git a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/FormLoginConfigurerTests.groovy b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/FormLoginConfigurerTests.groovy index 44776aaa85..a79ec3721d 100644 --- a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/FormLoginConfigurerTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/FormLoginConfigurerTests.groovy @@ -46,7 +46,7 @@ import org.springframework.security.web.header.HeaderWriterFilter import org.springframework.security.web.savedrequest.RequestCacheAwareFilter import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter import org.springframework.security.web.session.SessionManagementFilter -import org.springframework.security.web.util.AnyRequestMatcher +import org.springframework.security.web.util.matchers.AnyRequestMatcher import org.springframework.test.util.ReflectionTestUtils import spock.lang.Unroll diff --git a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceDebugTests.groovy b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceDebugTests.groovy index a139f1233a..0faee83291 100644 --- a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceDebugTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceDebugTests.groovy @@ -51,8 +51,8 @@ import org.springframework.security.web.context.SecurityContextPersistenceFilter import org.springframework.security.web.debug.DebugFilter; import org.springframework.security.web.jaasapi.JaasApiIntegrationFilter; import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter; -import org.springframework.security.web.util.AntPathRequestMatcher -import org.springframework.security.web.util.AnyRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher +import org.springframework.security.web.util.matchers.AnyRequestMatcher; import org.springframework.security.web.util.RequestMatcher import spock.lang.Ignore; diff --git a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpCustomFilterTests.groovy b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpCustomFilterTests.groovy index 333ef50d0c..09d0beef23 100644 --- a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpCustomFilterTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpCustomFilterTests.groovy @@ -52,8 +52,8 @@ import org.springframework.security.web.context.NullSecurityContextRepository; import org.springframework.security.web.context.SecurityContextPersistenceFilter import org.springframework.security.web.jaasapi.JaasApiIntegrationFilter; import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter; -import org.springframework.security.web.util.AntPathRequestMatcher -import org.springframework.security.web.util.AnyRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher +import org.springframework.security.web.util.matchers.AnyRequestMatcher; import org.springframework.security.web.util.RequestMatcher import spock.lang.Ignore; diff --git a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpHeadersTests.groovy b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpHeadersTests.groovy index 5a99e30906..5f94f5d79c 100644 --- a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpHeadersTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpHeadersTests.groovy @@ -27,7 +27,7 @@ import org.springframework.security.web.header.writers.XXssProtectionHeaderWrite import org.springframework.security.web.header.writers.frameoptions.StaticAllowFromStrategy import org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter import org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter.XFrameOptionsMode -import org.springframework.security.web.util.AnyRequestMatcher +import org.springframework.security.web.util.matchers.AnyRequestMatcher /** * Tests to verify that all the functionality of attributes is present @@ -121,7 +121,7 @@ public class NamespaceHttpHeadersTests extends BaseSpringSpec { .headers() // hsts@request-matcher-ref, hsts@max-age-seconds, hsts@include-subdomains // Additional Constructors are provided to leverage default values - .addHeaderWriter(new HstsHeaderWriter(new AnyRequestMatcher(), 15768000, false)) + .addHeaderWriter(new HstsHeaderWriter(AnyRequestMatcher.INSTANCE, 15768000, false)) } } diff --git a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpJeeTests.groovy b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpJeeTests.groovy index c7bf8e027b..a7544bcab2 100644 --- a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpJeeTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpJeeTests.groovy @@ -67,8 +67,8 @@ import org.springframework.security.web.context.NullSecurityContextRepository; import org.springframework.security.web.context.SecurityContextPersistenceFilter import org.springframework.security.web.jaasapi.JaasApiIntegrationFilter; import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter; -import org.springframework.security.web.util.AntPathRequestMatcher -import org.springframework.security.web.util.AnyRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher +import org.springframework.security.web.util.matchers.AnyRequestMatcher; import org.springframework.security.web.util.RequestMatcher import org.springframework.test.util.ReflectionTestUtils; diff --git a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpLogoutTests.groovy b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpLogoutTests.groovy index 4578cbb2af..c7e2ddb7b8 100644 --- a/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpLogoutTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/NamespaceHttpLogoutTests.groovy @@ -60,8 +60,8 @@ import org.springframework.security.web.context.NullSecurityContextRepository; import org.springframework.security.web.context.SecurityContextPersistenceFilter import org.springframework.security.web.jaasapi.JaasApiIntegrationFilter; import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter; -import org.springframework.security.web.util.AntPathRequestMatcher -import org.springframework.security.web.util.AnyRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher +import org.springframework.security.web.util.matchers.AnyRequestMatcher; import org.springframework.security.web.util.RequestMatcher /** diff --git a/config/src/test/groovy/org/springframework/security/config/http/HttpHeadersConfigTests.groovy b/config/src/test/groovy/org/springframework/security/config/http/HttpHeadersConfigTests.groovy index 29501311c4..4226628bc7 100644 --- a/config/src/test/groovy/org/springframework/security/config/http/HttpHeadersConfigTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/http/HttpHeadersConfigTests.groovy @@ -20,7 +20,7 @@ import org.springframework.mock.web.MockHttpServletResponse import org.springframework.security.web.FilterChainProxy import org.springframework.security.web.header.HeaderWriterFilter import org.springframework.security.web.header.writers.StaticHeadersWriter -import org.springframework.security.web.util.AnyRequestMatcher +import org.springframework.security.web.util.matchers.AnyRequestMatcher /** * diff --git a/config/src/test/groovy/org/springframework/security/config/http/InterceptUrlConfigTests.groovy b/config/src/test/groovy/org/springframework/security/config/http/InterceptUrlConfigTests.groovy index 37c55cb869..119097f0ba 100644 --- a/config/src/test/groovy/org/springframework/security/config/http/InterceptUrlConfigTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/http/InterceptUrlConfigTests.groovy @@ -70,7 +70,7 @@ import org.springframework.security.access.vote.AffirmativeBased import org.springframework.security.access.PermissionEvaluator import org.springframework.security.core.Authentication import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler -import org.springframework.security.web.util.AntPathRequestMatcher +import org.springframework.security.web.util.matchers.AntPathRequestMatcher import org.springframework.security.authentication.AuthenticationManager diff --git a/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy b/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy index 372bf2a41e..c746440112 100644 --- a/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy @@ -71,7 +71,7 @@ import org.springframework.security.access.vote.AffirmativeBased import org.springframework.security.access.PermissionEvaluator import org.springframework.security.core.Authentication import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler -import org.springframework.security.web.util.AntPathRequestMatcher +import org.springframework.security.web.util.matchers.AntPathRequestMatcher import org.springframework.security.authentication.AuthenticationManager diff --git a/config/src/test/java/org/springframework/security/config/FilterChainProxyConfigTests.java b/config/src/test/java/org/springframework/security/config/FilterChainProxyConfigTests.java index cc31dc0c8a..324f17e932 100644 --- a/config/src/test/java/org/springframework/security/config/FilterChainProxyConfigTests.java +++ b/config/src/test/java/org/springframework/security/config/FilterChainProxyConfigTests.java @@ -39,8 +39,8 @@ import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.context.SecurityContextPersistenceFilter; import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter; -import org.springframework.security.web.util.AntPathRequestMatcher; -import org.springframework.security.web.util.AnyRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher; +import org.springframework.security.web.util.matchers.AnyRequestMatcher; import org.springframework.security.web.util.RequestMatcher; /** diff --git a/config/src/test/java/org/springframework/security/config/http/DefaultFilterChainValidatorTests.java b/config/src/test/java/org/springframework/security/config/http/DefaultFilterChainValidatorTests.java index 4eb705abac..5709dc7d8b 100644 --- a/config/src/test/java/org/springframework/security/config/http/DefaultFilterChainValidatorTests.java +++ b/config/src/test/java/org/springframework/security/config/http/DefaultFilterChainValidatorTests.java @@ -38,7 +38,7 @@ import org.springframework.security.web.access.intercept.FilterInvocationSecurit 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.util.AnyRequestMatcher; +import org.springframework.security.web.util.matchers.AnyRequestMatcher; /** * @@ -65,7 +65,7 @@ public class DefaultFilterChainValidatorTests { fsi.setSecurityMetadataSource(metadataSource); AuthenticationEntryPoint authenticationEntryPoint = new LoginUrlAuthenticationEntryPoint("/login"); ExceptionTranslationFilter etf = new ExceptionTranslationFilter(authenticationEntryPoint); - DefaultSecurityFilterChain securityChain = new DefaultSecurityFilterChain(new AnyRequestMatcher(), aaf, etf, fsi); + DefaultSecurityFilterChain securityChain = new DefaultSecurityFilterChain(AnyRequestMatcher.INSTANCE, aaf, etf, fsi); fcp = new FilterChainProxy(securityChain); validator = new DefaultFilterChainValidator(); Whitebox.setInternalState(validator, "logger", logger); diff --git a/config/src/test/resources/org/springframework/security/util/filtertest-valid.xml b/config/src/test/resources/org/springframework/security/util/filtertest-valid.xml index 4aa0b0ac2c..e21448cf74 100644 --- a/config/src/test/resources/org/springframework/security/util/filtertest-valid.xml +++ b/config/src/test/resources/org/springframework/security/util/filtertest-valid.xml @@ -45,9 +45,9 @@ - + - + @@ -137,7 +137,7 @@ - + @@ -151,7 +151,7 @@ - + @@ -161,7 +161,7 @@ - + diff --git a/docs/manual/src/asciidoctor/index.adoc b/docs/manual/src/asciidoctor/index.adoc index 6f4fe2324e..b40e5ddec9 100644 --- a/docs/manual/src/asciidoctor/index.adoc +++ b/docs/manual/src/asciidoctor/index.adoc @@ -1034,7 +1034,7 @@ We recommend you start with the tutorial sample, as the XML is minimal and easy ==== Contacts The Contacts Sample is an advanced example in that it illustrates the more powerful features of domain object access control lists (ACLs) in addition to basic application security. The application provides an interface with which the users are able to administer a simple database of contacts (the domain objects). -To deploy, simply copy the WAR file from Spring Security distribution into your container’s `webapps` directory. The war should be called `spring-security-samples-contacts-3.1.x.war` (the appended version number will vary depending on what release you are using). +To deploy, simply copy the WAR file from Spring Security distribution into your container���s `webapps` directory. The war should be called `spring-security-samples-contacts-3.1.x.war` (the appended version number will vary depending on what release you are using). After starting your container, check the application can load. Visit http://localhost:8080/contacts (or whichever URL is appropriate for your web container and the WAR you deployed). @@ -1424,7 +1424,7 @@ Following the secure object invocation proceeding and then returning - which may `AbstractSecurityInterceptor` and its related objects are shown in <> [[abstract-security-interceptor]] -.Security interceptors and the “secure object” model +.Security interceptors and the ���secure object��� model image::images/security-interception.png[Abstract Security Interceptor] ====== Extending the Secure Object Model @@ -2509,7 +2509,7 @@ $(function () { }); ---- -As a alternative to jQuery, we recommend using http://cujojs.com/[cujoJS’s] rest.js. https://github.com/cujojs/rest[rest.js] provides advanced support for working with HTTP request and responses in RESTful ways. A core capability is the ability to contextualize the HTTP client adding behavior as needed by chaining interceptors on to the client. +As a alternative to jQuery, we recommend using http://cujojs.com/[cujoJS���s] rest.js. https://github.com/cujojs/rest[rest.js] provides advanced support for working with HTTP request and responses in RESTful ways. A core capability is the ability to contextualize the HTTP client adding behavior as needed by chaining interceptors on to the client. [source,javascript] ---- @@ -3086,7 +3086,7 @@ At times you may want to only write a header for certain requests. For example, - @@ -3757,11 +3757,11 @@ Any Spring-EL functionality is available within the expression, so you can also public void doSomething(Contact contact); ---- -Here we are accessing another built–in expression, `authentication`, which is the `Authentication` stored in the security context. You can also access its "principal" property directly, using the expression `principal`. The value will often be a `UserDetails` instance, so you might use an expression like `principal.username` or `principal.enabled`. +Here we are accessing another built���in expression, `authentication`, which is the `Authentication` stored in the security context. You can also access its "principal" property directly, using the expression `principal`. The value will often be a `UserDetails` instance, so you might use an expression like `principal.username` or `principal.enabled`. [[el-pre-post-annotations-post]] * **Accessing the return value** -Less commonly, you may wish to perform an access-control check after the method has been invoked. This can be achieved using the `@PostAuthorize` annotation. To access the return value from a method, use the built–in name `returnObject` in the expression. +Less commonly, you may wish to perform an access-control check after the method has been invoked. This can be achieved using the `@PostAuthorize` annotation. To access the return value from a method, use the built���in name `returnObject` in the expression. ====== Filtering using @@ -4369,14 +4369,14 @@ In a Spring Security deployment, Spring Security is responsible for this user in Therefore, the JAAS package for Spring Security provides two default callback handlers, `JaasNameCallbackHandler` and `JaasPasswordCallbackHandler`. Each of these callback handlers implement `JaasAuthenticationCallbackHandler`. In most cases these callback handlers can simply be used without understanding the internal mechanics. -For those needing full control over the callback behavior, internally `AbstractJaasAuthenticationProvider` wraps these `JaasAuthenticationCallbackHandler` s with an `InternalCallbackHandler`. The `InternalCallbackHandler` is the class that actually implements JAAS’ normal `CallbackHandler` interface. Any time that the JAAS `LoginModule` is used, it is passed a list of application context configured `InternalCallbackHandler` s. If the `LoginModule` requests a callback against the `InternalCallbackHandler` s, the callback is in-turn passed to the `JaasAuthenticationCallbackHandler` s being wrapped. +For those needing full control over the callback behavior, internally `AbstractJaasAuthenticationProvider` wraps these `JaasAuthenticationCallbackHandler` s with an `InternalCallbackHandler`. The `InternalCallbackHandler` is the class that actually implements JAAS��� normal `CallbackHandler` interface. Any time that the JAAS `LoginModule` is used, it is passed a list of application context configured `InternalCallbackHandler` s. If the `LoginModule` requests a callback against the `InternalCallbackHandler` s, the callback is in-turn passed to the `JaasAuthenticationCallbackHandler` s being wrapped. [[jaas-authoritygranter]] ===== JAAS AuthorityGranter JAAS works with principals. Even "roles" are represented as principals in JAAS. Spring Security, on the other hand, works with `Authentication` objects. Each `Authentication` object contains a single principal, and multiple `GrantedAuthority` s. To facilitate mapping between these different concepts, Spring Security's JAAS package includes an `AuthorityGranter` interface. -An `AuthorityGranter` is responsible for inspecting a JAAS principal and returning a set of `String` s, representing the authorities assigned to the principal. For each returned authority string, the `AbstractJaasAuthenticationProvider` creates a `JaasGrantedAuthority` (which implements Spring Security’s `GrantedAuthority` interface) containing the authority string and the JAAS principal that the `AuthorityGranter` was passed. The `AbstractJaasAuthenticationProvider` obtains the JAAS principals by firstly successfully authenticating the user’s credentials using the JAAS `LoginModule`, and then accessing the `LoginContext` it returns. A call to `LoginContext.getSubject().getPrincipals()` is made, with each resulting principal passed to each `AuthorityGranter` defined against the `AbstractJaasAuthenticationProvider.setAuthorityGranters(List)` property. +An `AuthorityGranter` is responsible for inspecting a JAAS principal and returning a set of `String` s, representing the authorities assigned to the principal. For each returned authority string, the `AbstractJaasAuthenticationProvider` creates a `JaasGrantedAuthority` (which implements Spring Security���s `GrantedAuthority` interface) containing the authority string and the JAAS principal that the `AuthorityGranter` was passed. The `AbstractJaasAuthenticationProvider` obtains the JAAS principals by firstly successfully authenticating the user���s credentials using the JAAS `LoginModule`, and then accessing the `LoginContext` it returns. A call to `LoginContext.getSubject().getPrincipals()` is made, with each resulting principal passed to each `AuthorityGranter` defined against the `AbstractJaasAuthenticationProvider.setAuthorityGranters(List)` property. Spring Security does not include any production `AuthorityGranter` s given that every JAAS principal has an implementation-specific meaning. However, there is a `TestAuthorityGranter` in the unit tests that demonstrates a simple `AuthorityGranter` implementation. @@ -4445,7 +4445,7 @@ An example configuration of `DefaultJaasAuthenticationProvider` using `InMemoryC ==== JaasAuthenticationProvider The `JaasAuthenticationProvider` assumes the default `Configuration` is an instance of http://download.oracle.com/javase/1.4.2/docs/guide/security/jaas/spec/com/sun/security/auth/login/ConfigFile.html[ ConfigFile]. This assumption is made in order to attempt to update the `Configuration`. The `JaasAuthenticationProvider` then uses the default `Configuration` to create the `LoginContext`. -Let’s assume we have a JAAS login configuration file, `/WEB-INF/login.conf`, with the following contents: +Let���s assume we have a JAAS login configuration file, `/WEB-INF/login.conf`, with the following contents: [source,txt] ---- @@ -5509,7 +5509,7 @@ Specify the name of the request parameter to use when using regexp or whitelist [[nsa-xss-protection]] ===== -Adds the http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-iv-the-xss-filter.aspx[X-XSS-Protection header] to the response to assist in protecting against http://en.wikipedia.org/wiki/Cross-site_scripting#Non-Persistent[reflected / “Type-1” Cross-Site Scripting (XSS)] attacks. This is in no-way a full protection to XSS attacks! +Adds the http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-iv-the-xss-filter.aspx[X-XSS-Protection header] to the response to assist in protecting against http://en.wikipedia.org/wiki/Cross-site_scripting#Non-Persistent[reflected / ���Type-1��� Cross-Site Scripting (XSS)] attacks. This is in no-way a full protection to XSS attacks! [[nsa-xss-protection-attributes]] @@ -5518,7 +5518,7 @@ Adds the http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-iv-the- [[nsa-xss-protection-enabled]] * **xss-protection-enabled** -Enable or Disable http://en.wikipedia.org/wiki/Cross-site_scripting#Non-Persistent[reflected / “Type-1” Cross-Site Scripting (XSS)] protection. +Enable or Disable http://en.wikipedia.org/wiki/Cross-site_scripting#Non-Persistent[reflected / ���Type-1��� Cross-Site Scripting (XSS)] protection. [[nsa-xss-protection-block]] diff --git a/web/src/main/java/org/springframework/security/web/access/expression/WebSecurityExpressionRoot.java b/web/src/main/java/org/springframework/security/web/access/expression/WebSecurityExpressionRoot.java index c0b42d934e..9972d1d8fd 100644 --- a/web/src/main/java/org/springframework/security/web/access/expression/WebSecurityExpressionRoot.java +++ b/web/src/main/java/org/springframework/security/web/access/expression/WebSecurityExpressionRoot.java @@ -5,7 +5,7 @@ import javax.servlet.http.HttpServletRequest; import org.springframework.security.access.expression.SecurityExpressionRoot; import org.springframework.security.core.Authentication; import org.springframework.security.web.FilterInvocation; -import org.springframework.security.web.util.IpAddressMatcher; +import org.springframework.security.web.util.matchers.IpAddressMatcher; /** * diff --git a/web/src/main/java/org/springframework/security/web/authentication/DelegatingAuthenticationEntryPoint.java b/web/src/main/java/org/springframework/security/web/authentication/DelegatingAuthenticationEntryPoint.java index 10f040b419..c3598bb22a 100644 --- a/web/src/main/java/org/springframework/security/web/authentication/DelegatingAuthenticationEntryPoint.java +++ b/web/src/main/java/org/springframework/security/web/authentication/DelegatingAuthenticationEntryPoint.java @@ -27,7 +27,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; -import org.springframework.security.web.util.ELRequestMatcher; +import org.springframework.security.web.util.matchers.ELRequestMatcher; import org.springframework.security.web.util.RequestMatcher; import org.springframework.security.web.util.RequestMatcherEditor; import org.springframework.util.Assert; diff --git a/web/src/main/java/org/springframework/security/web/savedrequest/HttpSessionRequestCache.java b/web/src/main/java/org/springframework/security/web/savedrequest/HttpSessionRequestCache.java index a196bcb000..faa235ea06 100644 --- a/web/src/main/java/org/springframework/security/web/savedrequest/HttpSessionRequestCache.java +++ b/web/src/main/java/org/springframework/security/web/savedrequest/HttpSessionRequestCache.java @@ -8,7 +8,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.security.web.PortResolver; import org.springframework.security.web.PortResolverImpl; -import org.springframework.security.web.util.AnyRequestMatcher; +import org.springframework.security.web.util.matchers.AnyRequestMatcher; import org.springframework.security.web.util.RequestMatcher; /** @@ -25,7 +25,7 @@ public class HttpSessionRequestCache implements RequestCache { private PortResolver portResolver = new PortResolverImpl(); private boolean createSessionAllowed = true; - private RequestMatcher requestMatcher = new AnyRequestMatcher(); + private RequestMatcher requestMatcher = AnyRequestMatcher.INSTANCE; /** * Stores the current request, provided the configuration properties allow it. diff --git a/web/src/main/java/org/springframework/security/web/util/AntPathRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/AntPathRequestMatcher.java index 482e7bcec1..45d66768b2 100644 --- a/web/src/main/java/org/springframework/security/web/util/AntPathRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/AntPathRequestMatcher.java @@ -14,12 +14,7 @@ package org.springframework.security.web.util; import javax.servlet.http.HttpServletRequest; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.http.HttpMethod; import org.springframework.util.AntPathMatcher; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; /** * Matcher which compares a pre-defined ant-style pattern against the URL @@ -40,17 +35,11 @@ import org.springframework.util.StringUtils; * @author Luke Taylor * @author Rob Winch * @since 3.1 - * + * @deprecated use {@link org.springframework.security.web.util.matchers.AntPathRequestMatcher} * @see org.springframework.util.AntPathMatcher */ public final class AntPathRequestMatcher implements RequestMatcher { - private static final Log logger = LogFactory.getLog(AntPathRequestMatcher.class); - private static final String MATCH_ALL = "/**"; - - private final Matcher matcher; - private final String pattern; - private final HttpMethod httpMethod; - private final boolean caseSensitive; + private final org.springframework.security.web.util.matchers.AntPathRequestMatcher delegate; /** * Creates a matcher with the specific pattern which will match all HTTP @@ -90,28 +79,7 @@ public final class AntPathRequestMatcher implements RequestMatcher { * true if the matcher should consider case, else false */ public AntPathRequestMatcher(String pattern, String httpMethod, boolean caseSensitive) { - Assert.hasText(pattern, "Pattern cannot be null or empty"); - this.caseSensitive = caseSensitive; - - if (pattern.equals(MATCH_ALL) || pattern.equals("**")) { - pattern = MATCH_ALL; - matcher = null; - } else { - if(!caseSensitive) { - pattern = pattern.toLowerCase(); - } - - // If the pattern ends with {@code /**} and has no other wildcards, then optimize to a sub-path match - if (pattern.endsWith(MATCH_ALL) && pattern.indexOf('?') == -1 && - pattern.indexOf("*") == pattern.length() - 2) { - matcher = new SubpathMatcher(pattern.substring(0, pattern.length() - 3)); - } else { - matcher = new SpringAntMatcher(pattern); - } - } - - this.pattern = pattern; - this.httpMethod = StringUtils.hasText(httpMethod) ? HttpMethod.valueOf(httpMethod) : null; + this.delegate = new org.springframework.security.web.util.matchers.AntPathRequestMatcher(pattern, httpMethod, caseSensitive); } /** @@ -121,117 +89,29 @@ public final class AntPathRequestMatcher implements RequestMatcher { * {@code servletPath} + {@code pathInfo} of the request. */ public boolean matches(HttpServletRequest request) { - if (httpMethod != null && request.getMethod() != null && httpMethod != HttpMethod.valueOf(request.getMethod())) { - if (logger.isDebugEnabled()) { - logger.debug("Request '" + request.getMethod() + " " + getRequestPath(request) + "'" - + " doesn't match '" + httpMethod + " " + pattern); - } - - return false; - } - - if (pattern.equals(MATCH_ALL)) { - if (logger.isDebugEnabled()) { - logger.debug("Request '" + getRequestPath(request) + "' matched by universal pattern '/**'"); - } - - return true; - } - - String url = getRequestPath(request); - - if (logger.isDebugEnabled()) { - logger.debug("Checking match of request : '" + url + "'; against '" + pattern + "'"); - } - - return matcher.matches(url); + return this.delegate.matches(request); } - private String getRequestPath(HttpServletRequest request) { - String url = request.getServletPath(); - - if (request.getPathInfo() != null) { - url += request.getPathInfo(); - } - - if(!caseSensitive) { - url = url.toLowerCase(); - } - - return url; + public org.springframework.security.web.util.matchers.AntPathRequestMatcher getDelegate() { + return delegate; } public String getPattern() { - return pattern; + return delegate.getPattern(); } @Override public boolean equals(Object obj) { - if (!(obj instanceof AntPathRequestMatcher)) { - return false; - } - AntPathRequestMatcher other = (AntPathRequestMatcher)obj; - return this.pattern.equals(other.pattern) && - this.httpMethod == other.httpMethod && - this.caseSensitive == other.caseSensitive; + return delegate.equals(obj); } @Override public int hashCode() { - int code = 31 ^ pattern.hashCode(); - if (httpMethod != null) { - code ^= httpMethod.hashCode(); - } - return code; + return delegate.hashCode(); } @Override public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("Ant [pattern='").append(pattern).append("'"); - - if (httpMethod != null) { - sb.append(", ").append(httpMethod); - } - - sb.append("]"); - - return sb.toString(); - } - - private static interface Matcher { - boolean matches(String path); - } - - private static class SpringAntMatcher implements Matcher { - private static final AntPathMatcher antMatcher = new AntPathMatcher(); - - private final String pattern; - - private SpringAntMatcher(String pattern) { - this.pattern = pattern; - } - - public boolean matches(String path) { - return antMatcher.match(pattern, path); - } - } - - /** - * Optimized matcher for trailing wildcards - */ - private static class SubpathMatcher implements Matcher { - private final String subpath; - private final int length; - - private SubpathMatcher(String subpath) { - assert !subpath.contains("*"); - this.subpath = subpath; - this.length = subpath.length(); - } - - public boolean matches(String path) { - return path.startsWith(subpath) && (path.length() == length || path.charAt(length) == '/'); - } + return delegate.toString(); } } diff --git a/web/src/main/java/org/springframework/security/web/util/AnyRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/AnyRequestMatcher.java index 59432a8fb1..e819dbf19e 100644 --- a/web/src/main/java/org/springframework/security/web/util/AnyRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/AnyRequestMatcher.java @@ -7,20 +7,22 @@ import javax.servlet.http.HttpServletRequest; * * @author Luke Taylor * @since 3.1 + * @deprecated use org.springframework.security.web.util.matchers.AnyRequestMatcher.INSTANCE instead */ public final class AnyRequestMatcher implements RequestMatcher { + private final RequestMatcher delegate = org.springframework.security.web.util.matchers.AnyRequestMatcher.INSTANCE; public boolean matches(HttpServletRequest request) { - return true; + return delegate.matches(request); } @Override public boolean equals(Object obj) { - return obj instanceof AnyRequestMatcher; + return delegate.equals(obj); } @Override public int hashCode() { - return 1; + return delegate.hashCode(); } } diff --git a/web/src/main/java/org/springframework/security/web/util/ELRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/ELRequestMatcher.java index e1884441ee..2bc410c687 100644 --- a/web/src/main/java/org/springframework/security/web/util/ELRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/ELRequestMatcher.java @@ -19,9 +19,6 @@ package org.springframework.security.web.util; import javax.servlet.http.HttpServletRequest; import org.springframework.expression.EvaluationContext; -import org.springframework.expression.Expression; -import org.springframework.expression.spel.standard.SpelExpressionParser; -import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint; /** @@ -35,19 +32,18 @@ import org.springframework.security.web.authentication.DelegatingAuthenticationE * * @author Mike Wiesner * @since 3.0.2 + * @deprecated Use org.springframework.security.web.util.matchers.ELRequestMatcher */ public class ELRequestMatcher implements RequestMatcher { - private final Expression expression; + private final org.springframework.security.web.util.matchers.ELRequestMatcher delegate; public ELRequestMatcher(String el) { - SpelExpressionParser parser = new SpelExpressionParser(); - expression = parser.parseExpression(el); + delegate = new org.springframework.security.web.util.matchers.ELRequestMatcher(el); } public boolean matches(HttpServletRequest request) { - EvaluationContext context = createELContext(request); - return expression.getValue(context, Boolean.class).booleanValue(); + return delegate.matches(request); } /** @@ -56,7 +52,7 @@ public class ELRequestMatcher implements RequestMatcher { * @return EL root context which is used to evaluate the expression */ public EvaluationContext createELContext(HttpServletRequest request) { - return new StandardEvaluationContext(new ELRequestMatcherContext(request)); + return delegate.createELContext(request); } } diff --git a/web/src/main/java/org/springframework/security/web/util/RegexRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/RegexRequestMatcher.java index 3ed660b7a3..92d02f4331 100644 --- a/web/src/main/java/org/springframework/security/web/util/RegexRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/RegexRequestMatcher.java @@ -16,11 +16,6 @@ import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.http.HttpMethod; -import org.springframework.util.StringUtils; - /** * Uses a regular expression to decide whether a supplied the URL of a supplied {@code HttpServletRequest}. * @@ -33,12 +28,10 @@ import org.springframework.util.StringUtils; * @author Luke Taylor * @author Rob Winch * @since 3.1 + * @deprecated use org.springframework.security.web.util.matchers.RegexRequestMatcher */ public final class RegexRequestMatcher implements RequestMatcher { - private final static Log logger = LogFactory.getLog(RegexRequestMatcher.class); - - private final Pattern pattern; - private final HttpMethod httpMethod; + private final org.springframework.security.web.util.matchers.RegexRequestMatcher delegate; /** * Creates a case-sensitive {@code Pattern} instance to match against the request. @@ -58,12 +51,7 @@ public final class RegexRequestMatcher implements RequestMatcher { * @param caseInsensitive if true, the pattern will be compiled with the {@link Pattern#CASE_INSENSITIVE} flag set. */ public RegexRequestMatcher(String pattern, String httpMethod, boolean caseInsensitive) { - if (caseInsensitive) { - this.pattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE); - } else { - this.pattern = Pattern.compile(pattern); - } - this.httpMethod = StringUtils.hasText(httpMethod) ? HttpMethod.valueOf(httpMethod) : null; + this.delegate = new org.springframework.security.web.util.matchers.RegexRequestMatcher(pattern, httpMethod, caseInsensitive); } /** @@ -74,31 +62,6 @@ public final class RegexRequestMatcher implements RequestMatcher { * @return true if the pattern matches the URL, false otherwise. */ public boolean matches(HttpServletRequest request) { - if (httpMethod != null && request.getMethod() != null && httpMethod != HttpMethod.valueOf(request.getMethod())) { - return false; - } - - String url = request.getServletPath(); - String pathInfo = request.getPathInfo(); - String query = request.getQueryString(); - - if (pathInfo != null || query != null) { - StringBuilder sb = new StringBuilder(url); - - if (pathInfo != null) { - sb.append(pathInfo); - } - - if (query != null) { - sb.append('?').append(query); - } - url = sb.toString(); - } - - if (logger.isDebugEnabled()) { - logger.debug("Checking match of request : '" + url + "'; against '" + pattern + "'"); - } - - return pattern.matcher(url).matches(); + return delegate.matches(request); } } diff --git a/web/src/main/java/org/springframework/security/web/util/RequestMatcherEditor.java b/web/src/main/java/org/springframework/security/web/util/RequestMatcherEditor.java index dbd6b76cf8..446385529c 100644 --- a/web/src/main/java/org/springframework/security/web/util/RequestMatcherEditor.java +++ b/web/src/main/java/org/springframework/security/web/util/RequestMatcherEditor.java @@ -18,19 +18,20 @@ package org.springframework.security.web.util; import java.beans.PropertyEditorSupport; +import org.springframework.security.web.util.matchers.ELRequestMatcher; import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint; /** * PropertyEditor which creates ELRequestMatcher instances from Strings - * + * * This allows to use a String in a BeanDefinition instead of an (inner) bean - * if a RequestMatcher is required, e.g. in {@link DelegatingAuthenticationEntryPoint} - * + * if a RequestMatcher is required, e.g. in {@link DelegatingAuthenticationEntryPoint} + * * @author Mike Wiesner * @since 3.0.2 */ public class RequestMatcherEditor extends PropertyEditorSupport { - + @Override public void setAsText(String text) throws IllegalArgumentException { setValue(new ELRequestMatcher(text)); diff --git a/web/src/main/java/org/springframework/security/web/util/AndRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/matchers/AndRequestMatcher.java similarity index 95% rename from web/src/main/java/org/springframework/security/web/util/AndRequestMatcher.java rename to web/src/main/java/org/springframework/security/web/util/matchers/AndRequestMatcher.java index c635edd2d9..baf24023d3 100644 --- a/web/src/main/java/org/springframework/security/web/util/AndRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/matchers/AndRequestMatcher.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import java.util.Arrays; import java.util.List; @@ -22,6 +22,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.security.web.util.RequestMatcher; import org.springframework.util.Assert; diff --git a/web/src/main/java/org/springframework/security/web/util/matchers/AntPathRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/matchers/AntPathRequestMatcher.java new file mode 100644 index 0000000000..2668a80fab --- /dev/null +++ b/web/src/main/java/org/springframework/security/web/util/matchers/AntPathRequestMatcher.java @@ -0,0 +1,243 @@ +/* + * Copyright 2002-2012 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.web.util.matchers; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.http.HttpMethod; +import org.springframework.security.web.util.RequestMatcher; +import org.springframework.util.AntPathMatcher; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; + +/** + * Matcher which compares a pre-defined ant-style pattern against the URL + * ({@code servletPath + pathInfo}) of an {@code HttpServletRequest}. + * The query string of the URL is ignored and matching is case-insensitive or case-sensitive depending on + * the arguments passed into the constructor. + *

+ * Using a pattern value of {@code /**} or {@code **} is treated as a universal + * match, which will match any request. Patterns which end with {@code /**} (and have no other wildcards) + * are optimized by using a substring match — a pattern of {@code /aaa/**} will match {@code /aaa}, + * {@code /aaa/} and any sub-directories, such as {@code /aaa/bbb/ccc}. + *

+ *

+ * For all other cases, Spring's {@link AntPathMatcher} is used to perform the match. See the Spring documentation + * for this class for comprehensive information on the syntax used. + *

+ * + * @author Luke Taylor + * @author Rob Winch + * @since 3.1 + * + * @see org.springframework.util.AntPathMatcher + */ +public final class AntPathRequestMatcher implements RequestMatcher { + private static final Log logger = LogFactory.getLog(AntPathRequestMatcher.class); + private static final String MATCH_ALL = "/**"; + + private final Matcher matcher; + private final String pattern; + private final HttpMethod httpMethod; + private final boolean caseSensitive; + + /** + * Creates a matcher with the specific pattern which will match all HTTP + * methods in a case insensitive manner. + * + * @param pattern + * the ant pattern to use for matching + */ + public AntPathRequestMatcher(String pattern) { + this(pattern, null); + } + + /** + * Creates a matcher with the supplied pattern and HTTP method in a case + * insensitive manner. + * + * @param pattern + * the ant pattern to use for matching + * @param httpMethod + * the HTTP method. The {@code matches} method will return false + * if the incoming request doesn't have the same method. + */ + public AntPathRequestMatcher(String pattern, String httpMethod) { + this(pattern,httpMethod,false); + } + + /** + * Creates a matcher with the supplied pattern which will match the + * specified Http method + * + * @param pattern + * the ant pattern to use for matching + * @param httpMethod + * the HTTP method. The {@code matches} method will return false + * if the incoming request doesn't doesn't have the same method. + * @param caseSensitive + * true if the matcher should consider case, else false + */ + public AntPathRequestMatcher(String pattern, String httpMethod, boolean caseSensitive) { + Assert.hasText(pattern, "Pattern cannot be null or empty"); + this.caseSensitive = caseSensitive; + + if (pattern.equals(MATCH_ALL) || pattern.equals("**")) { + pattern = MATCH_ALL; + matcher = null; + } else { + if(!caseSensitive) { + pattern = pattern.toLowerCase(); + } + + // If the pattern ends with {@code /**} and has no other wildcards, then optimize to a sub-path match + if (pattern.endsWith(MATCH_ALL) && pattern.indexOf('?') == -1 && + pattern.indexOf("*") == pattern.length() - 2) { + matcher = new SubpathMatcher(pattern.substring(0, pattern.length() - 3)); + } else { + matcher = new SpringAntMatcher(pattern); + } + } + + this.pattern = pattern; + this.httpMethod = StringUtils.hasText(httpMethod) ? HttpMethod.valueOf(httpMethod) : null; + } + + /** + * Returns true if the configured pattern (and HTTP-Method) match those of the supplied request. + * + * @param request the request to match against. The ant pattern will be matched against the + * {@code servletPath} + {@code pathInfo} of the request. + */ + public boolean matches(HttpServletRequest request) { + if (httpMethod != null && request.getMethod() != null && httpMethod != HttpMethod.valueOf(request.getMethod())) { + if (logger.isDebugEnabled()) { + logger.debug("Request '" + request.getMethod() + " " + getRequestPath(request) + "'" + + " doesn't match '" + httpMethod + " " + pattern); + } + + return false; + } + + if (pattern.equals(MATCH_ALL)) { + if (logger.isDebugEnabled()) { + logger.debug("Request '" + getRequestPath(request) + "' matched by universal pattern '/**'"); + } + + return true; + } + + String url = getRequestPath(request); + + if (logger.isDebugEnabled()) { + logger.debug("Checking match of request : '" + url + "'; against '" + pattern + "'"); + } + + return matcher.matches(url); + } + + private String getRequestPath(HttpServletRequest request) { + String url = request.getServletPath(); + + if (request.getPathInfo() != null) { + url += request.getPathInfo(); + } + + if(!caseSensitive) { + url = url.toLowerCase(); + } + + return url; + } + + public String getPattern() { + return pattern; + } + + @SuppressWarnings("deprecation") + @Override + public boolean equals(Object obj) { + org.springframework.security.web.util.matchers.AntPathRequestMatcher other; + if (obj instanceof org.springframework.security.web.util.AntPathRequestMatcher) { + other = ((org.springframework.security.web.util.AntPathRequestMatcher) obj).getDelegate(); + } else if(obj instanceof AntPathRequestMatcher) { + other = (AntPathRequestMatcher) obj; + } else { + return false; + } + return this.pattern.equals(other.pattern) && + this.httpMethod == other.httpMethod && + this.caseSensitive == other.caseSensitive; + } + + @Override + public int hashCode() { + int code = 31 ^ pattern.hashCode(); + if (httpMethod != null) { + code ^= httpMethod.hashCode(); + } + return code; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Ant [pattern='").append(pattern).append("'"); + + if (httpMethod != null) { + sb.append(", ").append(httpMethod); + } + + sb.append("]"); + + return sb.toString(); + } + + private static interface Matcher { + boolean matches(String path); + } + + private static class SpringAntMatcher implements Matcher { + private static final AntPathMatcher antMatcher = new AntPathMatcher(); + + private final String pattern; + + private SpringAntMatcher(String pattern) { + this.pattern = pattern; + } + + public boolean matches(String path) { + return antMatcher.match(pattern, path); + } + } + + /** + * Optimized matcher for trailing wildcards + */ + private static class SubpathMatcher implements Matcher { + private final String subpath; + private final int length; + + private SubpathMatcher(String subpath) { + assert !subpath.contains("*"); + this.subpath = subpath; + this.length = subpath.length(); + } + + public boolean matches(String path) { + return path.startsWith(subpath) && (path.length() == length || path.charAt(length) == '/'); + } + } +} diff --git a/web/src/main/java/org/springframework/security/web/util/matchers/AnyRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/matchers/AnyRequestMatcher.java new file mode 100644 index 0000000000..9b41d00049 --- /dev/null +++ b/web/src/main/java/org/springframework/security/web/util/matchers/AnyRequestMatcher.java @@ -0,0 +1,47 @@ +/* + * Copyright 2002-2013 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.web.util.matchers; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.security.web.util.RequestMatcher; + +/** + * Matches any supplied request. + * + * @author Luke Taylor + * @since 3.1 + */ +public final class AnyRequestMatcher implements RequestMatcher { + public static final RequestMatcher INSTANCE = new AnyRequestMatcher(); + + public boolean matches(HttpServletRequest request) { + return true; + } + + @Override + @SuppressWarnings("deprecation") + public boolean equals(Object obj) { + return obj instanceof AnyRequestMatcher || obj instanceof org.springframework.security.web.util.AnyRequestMatcher; + } + + @Override + public int hashCode() { + return 1; + } + + private AnyRequestMatcher() {} +} diff --git a/web/src/main/java/org/springframework/security/web/util/matchers/ELRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/matchers/ELRequestMatcher.java new file mode 100644 index 0000000000..8784857b81 --- /dev/null +++ b/web/src/main/java/org/springframework/security/web/util/matchers/ELRequestMatcher.java @@ -0,0 +1,63 @@ +/* + * Copyright 2010 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.web.util.matchers; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.expression.EvaluationContext; +import org.springframework.expression.Expression; +import org.springframework.expression.spel.standard.SpelExpressionParser; +import org.springframework.expression.spel.support.StandardEvaluationContext; +import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint; +import org.springframework.security.web.util.RequestMatcher; + +/** + * A RequestMatcher implementation which uses a SpEL expression + * + *

With the default EvaluationContext ({@link ELRequestMatcherContext}) you can use + * hasIpAdress() and hasHeader()

+ * + *

See {@link DelegatingAuthenticationEntryPoint} for an example configuration.

+ * + * + * @author Mike Wiesner + * @since 3.0.2 + */ +public class ELRequestMatcher implements RequestMatcher { + + private final Expression expression; + + public ELRequestMatcher(String el) { + SpelExpressionParser parser = new SpelExpressionParser(); + expression = parser.parseExpression(el); + } + + public boolean matches(HttpServletRequest request) { + EvaluationContext context = createELContext(request); + return expression.getValue(context, Boolean.class).booleanValue(); + } + + /** + * Subclasses can override this methode if they want to use a different EL root context + * + * @return EL root context which is used to evaluate the expression + */ + public EvaluationContext createELContext(HttpServletRequest request) { + return new StandardEvaluationContext(new ELRequestMatcherContext(request)); + } + +} diff --git a/web/src/main/java/org/springframework/security/web/util/ELRequestMatcherContext.java b/web/src/main/java/org/springframework/security/web/util/matchers/ELRequestMatcherContext.java similarity index 95% rename from web/src/main/java/org/springframework/security/web/util/ELRequestMatcherContext.java rename to web/src/main/java/org/springframework/security/web/util/matchers/ELRequestMatcherContext.java index ab6fa70e84..e5e67e7732 100644 --- a/web/src/main/java/org/springframework/security/web/util/ELRequestMatcherContext.java +++ b/web/src/main/java/org/springframework/security/web/util/matchers/ELRequestMatcherContext.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import javax.servlet.http.HttpServletRequest; diff --git a/web/src/main/java/org/springframework/security/web/util/IpAddressMatcher.java b/web/src/main/java/org/springframework/security/web/util/matchers/IpAddressMatcher.java similarity index 95% rename from web/src/main/java/org/springframework/security/web/util/IpAddressMatcher.java rename to web/src/main/java/org/springframework/security/web/util/matchers/IpAddressMatcher.java index 57611e1a51..ce94c26456 100644 --- a/web/src/main/java/org/springframework/security/web/util/IpAddressMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/matchers/IpAddressMatcher.java @@ -1,4 +1,4 @@ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import java.net.InetAddress; import java.net.UnknownHostException; @@ -6,6 +6,7 @@ import java.util.Arrays; import javax.servlet.http.HttpServletRequest; +import org.springframework.security.web.util.RequestMatcher; import org.springframework.util.StringUtils; /** diff --git a/web/src/main/java/org/springframework/security/web/util/MediaTypeRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/matchers/MediaTypeRequestMatcher.java similarity index 98% rename from web/src/main/java/org/springframework/security/web/util/MediaTypeRequestMatcher.java rename to web/src/main/java/org/springframework/security/web/util/matchers/MediaTypeRequestMatcher.java index 1063dc8011..69e14f806c 100644 --- a/web/src/main/java/org/springframework/security/web/util/MediaTypeRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/matchers/MediaTypeRequestMatcher.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import java.util.Arrays; import java.util.Collection; @@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.http.MediaType; +import org.springframework.security.web.util.RequestMatcher; import org.springframework.util.Assert; import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.accept.ContentNegotiationStrategy; diff --git a/web/src/main/java/org/springframework/security/web/util/NegatedRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/matchers/NegatedRequestMatcher.java similarity index 94% rename from web/src/main/java/org/springframework/security/web/util/NegatedRequestMatcher.java rename to web/src/main/java/org/springframework/security/web/util/matchers/NegatedRequestMatcher.java index 369158ec0b..c88cca07d5 100644 --- a/web/src/main/java/org/springframework/security/web/util/NegatedRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/matchers/NegatedRequestMatcher.java @@ -13,12 +13,13 @@ * License for the specific language governing permissions and limitations under * the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.security.web.util.RequestMatcher; import org.springframework.util.Assert; /** diff --git a/web/src/main/java/org/springframework/security/web/util/OrRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/matchers/OrRequestMatcher.java similarity index 95% rename from web/src/main/java/org/springframework/security/web/util/OrRequestMatcher.java rename to web/src/main/java/org/springframework/security/web/util/matchers/OrRequestMatcher.java index 5b84823497..b7ae5cb1ff 100644 --- a/web/src/main/java/org/springframework/security/web/util/OrRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/matchers/OrRequestMatcher.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import java.util.Arrays; import java.util.List; @@ -22,6 +22,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.security.web.util.RequestMatcher; import org.springframework.util.Assert; diff --git a/web/src/main/java/org/springframework/security/web/util/matchers/RegexRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/matchers/RegexRequestMatcher.java new file mode 100644 index 0000000000..f77c2a30f5 --- /dev/null +++ b/web/src/main/java/org/springframework/security/web/util/matchers/RegexRequestMatcher.java @@ -0,0 +1,105 @@ +/* + * Copyright 2002-2012 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.web.util.matchers; + +import java.util.regex.Pattern; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.http.HttpMethod; +import org.springframework.security.web.util.RequestMatcher; +import org.springframework.util.StringUtils; + +/** + * Uses a regular expression to decide whether a supplied the URL of a supplied {@code HttpServletRequest}. + * + * Can also be configured to match a specific HTTP method. + * + * The match is performed against the {@code servletPath + pathInfo + queryString} of the request and is case-sensitive + * by default. Case-insensitive matching can be used by using the constructor which takes the {@code caseInsensitive} + * argument. + * + * @author Luke Taylor + * @author Rob Winch + * @since 3.1 + */ +public final class RegexRequestMatcher implements RequestMatcher { + private final static Log logger = LogFactory.getLog(RegexRequestMatcher.class); + + private final Pattern pattern; + private final HttpMethod httpMethod; + + /** + * Creates a case-sensitive {@code Pattern} instance to match against the request. + * + * @param pattern the regular expression to compile into a pattern. + * @param httpMethod the HTTP method to match. May be null to match all methods. + */ + public RegexRequestMatcher(String pattern, String httpMethod) { + this(pattern, httpMethod, false); + } + + /** + * As above, but allows setting of whether case-insensitive matching should be used. + * + * @param pattern the regular expression to compile into a pattern. + * @param httpMethod the HTTP method to match. May be null to match all methods. + * @param caseInsensitive if true, the pattern will be compiled with the {@link Pattern#CASE_INSENSITIVE} flag set. + */ + public RegexRequestMatcher(String pattern, String httpMethod, boolean caseInsensitive) { + if (caseInsensitive) { + this.pattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE); + } else { + this.pattern = Pattern.compile(pattern); + } + this.httpMethod = StringUtils.hasText(httpMethod) ? HttpMethod.valueOf(httpMethod) : null; + } + + /** + * Performs the match of the request URL ({@code servletPath + pathInfo + queryString}) against + * the compiled pattern. If the query string is present, a question mark will be prepended. + * + * @param request the request to match + * @return true if the pattern matches the URL, false otherwise. + */ + public boolean matches(HttpServletRequest request) { + if (httpMethod != null && request.getMethod() != null && httpMethod != HttpMethod.valueOf(request.getMethod())) { + return false; + } + + String url = request.getServletPath(); + String pathInfo = request.getPathInfo(); + String query = request.getQueryString(); + + if (pathInfo != null || query != null) { + StringBuilder sb = new StringBuilder(url); + + if (pathInfo != null) { + sb.append(pathInfo); + } + + if (query != null) { + sb.append('?').append(query); + } + url = sb.toString(); + } + + if (logger.isDebugEnabled()) { + logger.debug("Checking match of request : '" + url + "'; against '" + pattern + "'"); + } + + return pattern.matcher(url).matches(); + } +} diff --git a/web/src/main/java/org/springframework/security/web/util/RequestHeaderRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/matchers/RequestHeaderRequestMatcher.java similarity index 96% rename from web/src/main/java/org/springframework/security/web/util/RequestHeaderRequestMatcher.java rename to web/src/main/java/org/springframework/security/web/util/matchers/RequestHeaderRequestMatcher.java index ea5e1aaf06..1d67c7a4c5 100644 --- a/web/src/main/java/org/springframework/security/web/util/RequestHeaderRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/matchers/RequestHeaderRequestMatcher.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import javax.servlet.http.HttpServletRequest; +import org.springframework.security.web.util.RequestMatcher; import org.springframework.util.Assert; /** diff --git a/web/src/test/java/org/springframework/security/web/access/expression/ExpressionBasedFilterInvocationSecurityMetadataSourceTests.java b/web/src/test/java/org/springframework/security/web/access/expression/ExpressionBasedFilterInvocationSecurityMetadataSourceTests.java index e005ce53f3..601eba3813 100644 --- a/web/src/test/java/org/springframework/security/web/access/expression/ExpressionBasedFilterInvocationSecurityMetadataSourceTests.java +++ b/web/src/test/java/org/springframework/security/web/access/expression/ExpressionBasedFilterInvocationSecurityMetadataSourceTests.java @@ -7,7 +7,7 @@ import org.junit.Test; import org.springframework.security.access.ConfigAttribute; import org.springframework.security.access.SecurityConfig; import org.springframework.security.web.FilterInvocation; -import org.springframework.security.web.util.AnyRequestMatcher; +import org.springframework.security.web.util.matchers.AnyRequestMatcher; import org.springframework.security.web.util.RequestMatcher; import java.util.Collection; @@ -22,7 +22,7 @@ public class ExpressionBasedFilterInvocationSecurityMetadataSourceTests { public void expectedAttributeIsReturned() { final String expression = "hasRole('X')"; LinkedHashMap> requestMap = new LinkedHashMap>(); - requestMap.put(new AnyRequestMatcher(), SecurityConfig.createList(expression)); + requestMap.put(AnyRequestMatcher.INSTANCE, SecurityConfig.createList(expression)); ExpressionBasedFilterInvocationSecurityMetadataSource mds = new ExpressionBasedFilterInvocationSecurityMetadataSource(requestMap, new DefaultWebSecurityExpressionHandler()); assertEquals(1, mds.getAllConfigAttributes().size()); @@ -37,7 +37,7 @@ public class ExpressionBasedFilterInvocationSecurityMetadataSourceTests { @Test(expected=IllegalArgumentException.class) public void invalidExpressionIsRejected() throws Exception { LinkedHashMap> requestMap = new LinkedHashMap>(); - requestMap.put(new AnyRequestMatcher(), SecurityConfig.createList("hasRole('X'")); + requestMap.put(AnyRequestMatcher.INSTANCE, SecurityConfig.createList("hasRole('X'")); ExpressionBasedFilterInvocationSecurityMetadataSource mds = new ExpressionBasedFilterInvocationSecurityMetadataSource(requestMap, new DefaultWebSecurityExpressionHandler()); } diff --git a/web/src/test/java/org/springframework/security/web/access/intercept/DefaultFilterInvocationSecurityMetadataSourceTests.java b/web/src/test/java/org/springframework/security/web/access/intercept/DefaultFilterInvocationSecurityMetadataSourceTests.java index d419f6db0d..c9172b9d99 100644 --- a/web/src/test/java/org/springframework/security/web/access/intercept/DefaultFilterInvocationSecurityMetadataSourceTests.java +++ b/web/src/test/java/org/springframework/security/web/access/intercept/DefaultFilterInvocationSecurityMetadataSourceTests.java @@ -29,7 +29,7 @@ import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.security.access.ConfigAttribute; import org.springframework.security.access.SecurityConfig; import org.springframework.security.web.FilterInvocation; -import org.springframework.security.web.util.AntPathRequestMatcher; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher; import org.springframework.security.web.util.RequestMatcher; /** diff --git a/web/src/test/java/org/springframework/security/web/header/writers/HstsHeaderWriterTests.java b/web/src/test/java/org/springframework/security/web/header/writers/HstsHeaderWriterTests.java index 3ffb9e8ee7..7c46624c26 100644 --- a/web/src/test/java/org/springframework/security/web/header/writers/HstsHeaderWriterTests.java +++ b/web/src/test/java/org/springframework/security/web/header/writers/HstsHeaderWriterTests.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.security.web.header.writers.HstsHeaderWriter; -import org.springframework.security.web.util.AnyRequestMatcher; +import org.springframework.security.web.util.matchers.AnyRequestMatcher; /** * @author Rob Winch @@ -46,7 +46,7 @@ public class HstsHeaderWriterTests { @Test public void allArgsCustomConstructorWriteHeaders() { request.setSecure(false); - writer = new HstsHeaderWriter(new AnyRequestMatcher(), 15768000, false); + writer = new HstsHeaderWriter(AnyRequestMatcher.INSTANCE, 15768000, false); writer.writeHeaders(request, response); @@ -57,7 +57,7 @@ public class HstsHeaderWriterTests { @Test public void maxAgeAndIncludeSubdomainsCustomConstructorWriteHeaders() { request.setSecure(false); - writer = new HstsHeaderWriter(new AnyRequestMatcher(), 15768000, false); + writer = new HstsHeaderWriter(AnyRequestMatcher.INSTANCE, 15768000, false); writer.writeHeaders(request, response); @@ -124,7 +124,7 @@ public class HstsHeaderWriterTests { @Test public void writeHeadersAnyRequestMatcher() { - writer.setRequestMatcher(new AnyRequestMatcher()); + writer.setRequestMatcher(AnyRequestMatcher.INSTANCE); request.setSecure(false); writer.writeHeaders(request, response); diff --git a/web/src/test/java/org/springframework/security/web/util/AndRequestMatcherTests.java b/web/src/test/java/org/springframework/security/web/util/matchers/AndRequestMatcherTests.java similarity index 94% rename from web/src/test/java/org/springframework/security/web/util/AndRequestMatcherTests.java rename to web/src/test/java/org/springframework/security/web/util/matchers/AndRequestMatcherTests.java index 6c60a2f72c..f8a1f7a631 100644 --- a/web/src/test/java/org/springframework/security/web/util/AndRequestMatcherTests.java +++ b/web/src/test/java/org/springframework/security/web/util/matchers/AndRequestMatcherTests.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Mockito.when; @@ -28,6 +28,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.security.web.util.RequestMatcher; +import org.springframework.security.web.util.matchers.AndRequestMatcher; /** * diff --git a/web/src/test/java/org/springframework/security/web/util/AntPathRequestMatcherTests.java b/web/src/test/java/org/springframework/security/web/util/matchers/AntPathRequestMatcherTests.java similarity index 95% rename from web/src/test/java/org/springframework/security/web/util/AntPathRequestMatcherTests.java rename to web/src/test/java/org/springframework/security/web/util/matchers/AntPathRequestMatcherTests.java index 8612114019..a492a20055 100644 --- a/web/src/test/java/org/springframework/security/web/util/AntPathRequestMatcherTests.java +++ b/web/src/test/java/org/springframework/security/web/util/matchers/AntPathRequestMatcherTests.java @@ -10,7 +10,7 @@ * 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.web.util; +package org.springframework.security.web.util.matchers; import static org.fest.assertions.Assertions.assertThat; import static org.junit.Assert.assertEquals; @@ -25,6 +25,8 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.security.web.util.matchers.AntPathRequestMatcher; +import org.springframework.security.web.util.matchers.AnyRequestMatcher; /** * @author Luke Taylor @@ -139,7 +141,7 @@ public class AntPathRequestMatcherTests { assertEquals(new AntPathRequestMatcher("/xyz", "POST"), new AntPathRequestMatcher("/xyz", "POST")); assertFalse(new AntPathRequestMatcher("/xyz", "POST").equals(new AntPathRequestMatcher("/xyz", "GET"))); assertFalse(new AntPathRequestMatcher("/xyz").equals(new AntPathRequestMatcher("/xxx"))); - assertFalse(new AntPathRequestMatcher("/xyz").equals(new AnyRequestMatcher())); + assertFalse(new AntPathRequestMatcher("/xyz").equals(AnyRequestMatcher.INSTANCE)); assertFalse(new AntPathRequestMatcher("/xyz","GET", false).equals(new AntPathRequestMatcher("/xyz","GET", true))); } diff --git a/web/src/test/java/org/springframework/security/web/util/ELRequestMatcherTests.java b/web/src/test/java/org/springframework/security/web/util/matchers/ELRequestMatcherTests.java similarity index 95% rename from web/src/test/java/org/springframework/security/web/util/ELRequestMatcherTests.java rename to web/src/test/java/org/springframework/security/web/util/matchers/ELRequestMatcherTests.java index 82ff8ca1f2..b30cf11eba 100644 --- a/web/src/test/java/org/springframework/security/web/util/ELRequestMatcherTests.java +++ b/web/src/test/java/org/springframework/security/web/util/matchers/ELRequestMatcherTests.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import static org.junit.Assert.*; import org.junit.Test; import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.security.web.util.matchers.ELRequestMatcher; /** * @author Mike Wiesner diff --git a/web/src/test/java/org/springframework/security/web/util/IpAddressMatcherTests.java b/web/src/test/java/org/springframework/security/web/util/matchers/IpAddressMatcherTests.java similarity index 94% rename from web/src/test/java/org/springframework/security/web/util/IpAddressMatcherTests.java rename to web/src/test/java/org/springframework/security/web/util/matchers/IpAddressMatcherTests.java index e9febc7cd4..1a668e5e6a 100644 --- a/web/src/test/java/org/springframework/security/web/util/IpAddressMatcherTests.java +++ b/web/src/test/java/org/springframework/security/web/util/matchers/IpAddressMatcherTests.java @@ -1,4 +1,4 @@ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import static org.junit.Assert.*; @@ -6,6 +6,7 @@ import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.security.web.util.matchers.IpAddressMatcher; /** diff --git a/web/src/test/java/org/springframework/security/web/util/MediaTypeRequestMatcherRequestHCNSTests.java b/web/src/test/java/org/springframework/security/web/util/matchers/MediaTypeRequestMatcherRequestHCNSTests.java similarity index 97% rename from web/src/test/java/org/springframework/security/web/util/MediaTypeRequestMatcherRequestHCNSTests.java rename to web/src/test/java/org/springframework/security/web/util/matchers/MediaTypeRequestMatcherRequestHCNSTests.java index d7397f3157..9228d2ddd8 100644 --- a/web/src/test/java/org/springframework/security/web/util/MediaTypeRequestMatcherRequestHCNSTests.java +++ b/web/src/test/java/org/springframework/security/web/util/matchers/MediaTypeRequestMatcherRequestHCNSTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import static org.fest.assertions.Assertions.assertThat; @@ -23,6 +23,7 @@ import org.junit.Before; import org.junit.Test; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.security.web.util.matchers.MediaTypeRequestMatcher; import org.springframework.web.accept.ContentNegotiationStrategy; import org.springframework.web.accept.HeaderContentNegotiationStrategy; diff --git a/web/src/test/java/org/springframework/security/web/util/MediaTypeRequestMatcherTests.java b/web/src/test/java/org/springframework/security/web/util/matchers/MediaTypeRequestMatcherTests.java similarity index 98% rename from web/src/test/java/org/springframework/security/web/util/MediaTypeRequestMatcherTests.java rename to web/src/test/java/org/springframework/security/web/util/matchers/MediaTypeRequestMatcherTests.java index 026fae0307..fdebfac0dc 100644 --- a/web/src/test/java/org/springframework/security/web/util/MediaTypeRequestMatcherTests.java +++ b/web/src/test/java/org/springframework/security/web/util/matchers/MediaTypeRequestMatcherTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -30,6 +30,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.security.web.util.matchers.MediaTypeRequestMatcher; import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.accept.ContentNegotiationStrategy; import org.springframework.web.context.request.NativeWebRequest; diff --git a/web/src/test/java/org/springframework/security/web/util/NegatedRequestMatcherTests.java b/web/src/test/java/org/springframework/security/web/util/matchers/NegatedRequestMatcherTests.java similarity index 89% rename from web/src/test/java/org/springframework/security/web/util/NegatedRequestMatcherTests.java rename to web/src/test/java/org/springframework/security/web/util/matchers/NegatedRequestMatcherTests.java index 825e2c4506..e49bee8f4b 100644 --- a/web/src/test/java/org/springframework/security/web/util/NegatedRequestMatcherTests.java +++ b/web/src/test/java/org/springframework/security/web/util/matchers/NegatedRequestMatcherTests.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Mockito.when; @@ -24,6 +24,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.security.web.util.RequestMatcher; +import org.springframework.security.web.util.matchers.NegatedRequestMatcher; /** * diff --git a/web/src/test/java/org/springframework/security/web/util/OrRequestMatcherTests.java b/web/src/test/java/org/springframework/security/web/util/matchers/OrRequestMatcherTests.java similarity index 94% rename from web/src/test/java/org/springframework/security/web/util/OrRequestMatcherTests.java rename to web/src/test/java/org/springframework/security/web/util/matchers/OrRequestMatcherTests.java index 8e1d5d2f2e..ea4aacb686 100644 --- a/web/src/test/java/org/springframework/security/web/util/OrRequestMatcherTests.java +++ b/web/src/test/java/org/springframework/security/web/util/matchers/OrRequestMatcherTests.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Mockito.when; @@ -28,6 +28,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.security.web.util.RequestMatcher; +import org.springframework.security.web.util.matchers.OrRequestMatcher; /** * diff --git a/web/src/test/java/org/springframework/security/web/util/RegexRequestMatcherTests.java b/web/src/test/java/org/springframework/security/web/util/matchers/RegexRequestMatcherTests.java similarity index 96% rename from web/src/test/java/org/springframework/security/web/util/RegexRequestMatcherTests.java rename to web/src/test/java/org/springframework/security/web/util/matchers/RegexRequestMatcherTests.java index af7aebc2c0..263789c906 100644 --- a/web/src/test/java/org/springframework/security/web/util/RegexRequestMatcherTests.java +++ b/web/src/test/java/org/springframework/security/web/util/matchers/RegexRequestMatcherTests.java @@ -10,7 +10,7 @@ * 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.web.util; +package org.springframework.security.web.util.matchers; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -23,6 +23,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.security.web.util.matchers.RegexRequestMatcher; /** * @author Luke Taylor diff --git a/web/src/test/java/org/springframework/security/web/util/RequestHeaderRequestMatcherTests.java b/web/src/test/java/org/springframework/security/web/util/matchers/RequestHeaderRequestMatcherTests.java similarity index 95% rename from web/src/test/java/org/springframework/security/web/util/RequestHeaderRequestMatcherTests.java rename to web/src/test/java/org/springframework/security/web/util/matchers/RequestHeaderRequestMatcherTests.java index f231a163d9..c05a2c3886 100644 --- a/web/src/test/java/org/springframework/security/web/util/RequestHeaderRequestMatcherTests.java +++ b/web/src/test/java/org/springframework/security/web/util/matchers/RequestHeaderRequestMatcherTests.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.security.web.util; +package org.springframework.security.web.util.matchers; import static org.fest.assertions.Assertions.assertThat; import org.junit.Before; import org.junit.Test; import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.security.web.util.matchers.RequestHeaderRequestMatcher; /** *