From 75e7e099ab2e43423e42548183b425d6e8ef186d Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Wed, 15 Aug 2018 08:27:17 -0600 Subject: [PATCH] MiscHttpConfigTests groovy->java Issue: gh-4939 --- .../config/http/MiscHttpConfigTests.groovy | 804 -------------- .../BeanNameCollectingPostProcessor.java | 13 +- .../config/http/MiscHttpConfigTests.java | 987 ++++++++++++++++++ ...pConfigTests-AnonymousCustomAttributes.xml | 38 + .../MiscHttpConfigTests-AnonymousDisabled.xml | 35 + ...MiscHttpConfigTests-AnonymousEndpoints.xml | 34 + ...nfigTests-AnonymousMultipleAuthorities.xml | 38 + ...-AuthenticationManagerEraseCredentials.xml | 41 + ...uthenticationManagerRefKeepCredentials.xml | 41 + ...enticationManagerRefNotProviderManager.xml | 33 + .../http/MiscHttpConfigTests-AutoConfig.xml | 30 + ...HttpConfigTests-CiRegexSecurityPattern.xml | 36 + .../MiscHttpConfigTests-CollidingFilters.xml | 36 + ...onfigTests-CustomAccessDecisionManager.xml | 36 + ...s-CustomAuthenticationDetailsSourceRef.xml | 40 + .../MiscHttpConfigTests-CustomFilters.xml | 40 + ...nfigTests-CustomHttpBasicEntryPointRef.xml | 37 + ...scHttpConfigTests-CustomRequestMatcher.xml | 40 + .../MiscHttpConfigTests-DeleteCookies.xml | 32 + ...iscHttpConfigTests-DisableUrlRewriting.xml | 32 + .../http/MiscHttpConfigTests-EntryPoint.xml | 36 + .../MiscHttpConfigTests-ExpressionHandler.xml | 42 + .../http/MiscHttpConfigTests-HttpBasic.xml | 33 + .../http/MiscHttpConfigTests-HttpFirewall.xml | 38 + ...ttpConfigTests-InterceptUrlExpressions.xml | 34 + ...MiscHttpConfigTests-InterceptUrlMethod.xml | 42 + ...gTests-InterceptUrlMethodRequiresHttps.xml | 35 + ...sts-InterceptUrlMethodRequiresHttpsAny.xml | 35 + ...ttpConfigTests-InvalidLogoutSuccessUrl.xml | 32 + .../config/http/MiscHttpConfigTests-Jaas.xml | 56 + .../http/MiscHttpConfigTests-JeeFilter.xml | 33 + ...ttpConfigTests-LogoutSuccessHandlerRef.xml | 36 + ...scHttpConfigTests-MinimalConfiguration.xml | 32 + ...pConfigTests-MissingUserDetailsService.xml | 28 + .../MiscHttpConfigTests-NoAuthProviders.xml | 34 + ...ests-NoInternalAuthenticationProviders.xml | 34 + ...scHttpConfigTests-NoSecurityForPattern.xml | 32 + .../MiscHttpConfigTests-OncePerRequest.xml | 34 + ...rtsMappedInterceptUrlMethodRequiresAny.xml | 37 + ...tpConfigTests-PortsMappedRequiresHttps.xml | 36 + ...MiscHttpConfigTests-ProtectedLoginPage.xml | 33 + ...scHttpConfigTests-RegexSecurityPattern.xml | 36 + .../http/MiscHttpConfigTests-RequestCache.xml | 37 + .../http/MiscHttpConfigTests-Sec750.xml | 43 + .../http/MiscHttpConfigTests-Sec934.xml | 35 + ...pConfigTests-SecurityContextRepository.xml | 38 + .../config/http/MiscHttpConfigTests-X509.xml | 36 + .../http/MiscHttpConfigTests-certificate.pem | 21 + .../http/MiscHttpConfigTests-controllers.xml | 34 + .../security/config/http/jaas-login.conf | 3 + .../security/config/http/key.pem | 28 + 51 files changed, 2680 insertions(+), 806 deletions(-) delete mode 100644 config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy create mode 100644 config/src/test/java/org/springframework/security/config/http/MiscHttpConfigTests.java create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousCustomAttributes.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousDisabled.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousEndpoints.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousMultipleAuthorities.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AuthenticationManagerEraseCredentials.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AuthenticationManagerRefKeepCredentials.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AuthenticationManagerRefNotProviderManager.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AutoConfig.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CiRegexSecurityPattern.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CollidingFilters.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomAccessDecisionManager.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomAuthenticationDetailsSourceRef.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomFilters.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomHttpBasicEntryPointRef.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomRequestMatcher.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-DeleteCookies.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-DisableUrlRewriting.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-EntryPoint.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-ExpressionHandler.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-HttpBasic.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-HttpFirewall.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlExpressions.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlMethod.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlMethodRequiresHttps.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlMethodRequiresHttpsAny.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InvalidLogoutSuccessUrl.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Jaas.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-JeeFilter.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-LogoutSuccessHandlerRef.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-MinimalConfiguration.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-MissingUserDetailsService.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-NoAuthProviders.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-NoInternalAuthenticationProviders.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-NoSecurityForPattern.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-OncePerRequest.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-PortsMappedInterceptUrlMethodRequiresAny.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-PortsMappedRequiresHttps.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-ProtectedLoginPage.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-RegexSecurityPattern.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-RequestCache.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Sec750.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Sec934.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-SecurityContextRepository.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-X509.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-certificate.pem create mode 100644 config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-controllers.xml create mode 100644 config/src/test/resources/org/springframework/security/config/http/jaas-login.conf create mode 100644 config/src/test/resources/org/springframework/security/config/http/key.pem 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 deleted file mode 100644 index eaab25d203..0000000000 --- a/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy +++ /dev/null @@ -1,804 +0,0 @@ -/* - * 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.config.http - -import org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter -import org.springframework.security.web.csrf.CsrfFilter -import org.springframework.security.web.header.HeaderWriterFilter - -import java.security.Principal -import javax.servlet.Filter -import org.springframework.beans.BeansException -import org.springframework.beans.factory.BeanCreationException -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer -import org.springframework.beans.factory.parsing.BeanDefinitionParsingException -import org.springframework.mock.web.MockFilterChain -import org.springframework.mock.web.MockHttpServletRequest -import org.springframework.mock.web.MockHttpServletResponse -import org.springframework.security.access.AccessDeniedException -import org.springframework.security.access.SecurityConfig -import org.springframework.security.authentication.AnonymousAuthenticationProvider; -import org.springframework.security.authentication.TestingAuthenticationToken -import org.springframework.security.config.BeanIds -import org.springframework.security.config.MockUserServiceBeanPostProcessor -import org.springframework.security.config.PostProcessedMockUserDetailsService -import org.springframework.security.config.util.InMemoryXmlApplicationContext -import org.springframework.security.core.authority.AuthorityUtils -import org.springframework.security.core.context.SecurityContext -import org.springframework.security.core.context.SecurityContextHolder -import org.springframework.security.openid.OpenIDAuthenticationFilter -import org.springframework.security.util.FieldUtils -import org.springframework.security.web.FilterChainProxy -import org.springframework.security.web.PortMapperImpl -import org.springframework.security.web.access.ExceptionTranslationFilter -import org.springframework.security.web.access.channel.ChannelProcessingFilter -import org.springframework.security.web.access.intercept.FilterSecurityInterceptor -import org.springframework.security.web.authentication.AnonymousAuthenticationFilter -import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint -import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter -import org.springframework.security.web.authentication.logout.LogoutFilter -import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler -import org.springframework.security.web.authentication.preauth.x509.X509AuthenticationFilter -import org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter -import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint -import org.springframework.security.web.authentication.www.BasicAuthenticationFilter -import org.springframework.security.web.context.HttpSessionSecurityContextRepository -import org.springframework.security.web.context.SecurityContextPersistenceFilter -import org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter; -import org.springframework.security.web.debug.DebugFilter; -import org.springframework.security.web.jaasapi.JaasApiIntegrationFilter -import org.springframework.security.web.savedrequest.HttpSessionRequestCache -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.authentication.logout.CookieClearingLogoutHandler -import org.springframework.security.web.firewall.DefaultHttpFirewall -import org.springframework.security.BeanNameCollectingPostProcessor -import org.springframework.security.authentication.dao.DaoAuthenticationProvider -import org.springframework.security.access.vote.RoleVoter -import org.springframework.security.web.access.expression.WebExpressionVoter -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.matcher.AntPathRequestMatcher -import org.springframework.security.authentication.AuthenticationManager - - -/** - * - * @author Luke Taylor - * @author Rob Winch - */ -class MiscHttpConfigTests extends AbstractHttpConfigTests { - - def 'Minimal configuration parses'() { - setup: - xml.http { - 'http-basic'() - } - createAppContext() - } - - def httpAutoConfigSetsUpCorrectFilterList() { - when: - xml.http('auto-config': 'true') - createAppContext() - - then: - filtersMatchExpectedAutoConfigList('/anyurl'); - } - - void filtersMatchExpectedAutoConfigList(String url) { - def filterList = getFilters(url); - Iterator filters = filterList.iterator(); - - assert filters.next() instanceof SecurityContextPersistenceFilter - assert filters.next() instanceof WebAsyncManagerIntegrationFilter - assert filters.next() instanceof HeaderWriterFilter - assert filters.next() instanceof CsrfFilter - assert filters.next() instanceof LogoutFilter - Object authProcFilter = filters.next(); - assert authProcFilter instanceof UsernamePasswordAuthenticationFilter - assert filters.next() instanceof DefaultLoginPageGeneratingFilter - assert filters.next() instanceof DefaultLogoutPageGeneratingFilter - assert filters.next() instanceof BasicAuthenticationFilter - assert filters.next() instanceof RequestCacheAwareFilter - assert filters.next() instanceof SecurityContextHolderAwareRequestFilter - assert filters.next() instanceof AnonymousAuthenticationFilter - assert filters.next() instanceof SessionManagementFilter - assert filters.next() instanceof ExceptionTranslationFilter - Object fsiObj = filters.next(); - assert fsiObj instanceof FilterSecurityInterceptor - def fsi = (FilterSecurityInterceptor) fsiObj; - assert fsi.isObserveOncePerRequest() - } - - def filterListShouldBeEmptyForPatternWithNoFilters() { - xml.debug() - xml.http(pattern: '/unprotected', security: 'none') - httpAutoConfig() {} - createAppContext() - - expect: - getFilters("/unprotected").size() == 0 - } - - def debugFilterHandlesMissingAndEmptyFilterChains() { - when: - xml.debug() - xml.http(pattern: '/unprotected', security: 'none') - createAppContext() - then: - Filter debugFilter = appContext.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN); - MockHttpServletRequest request = new MockHttpServletRequest("GET", "") - request.setServletPath("/unprotected"); - debugFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()); - request.setServletPath("/nomatch"); - debugFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()); - } - - def regexPathsWorkCorrectly() { - xml.http(pattern: '\\A\\/[a-z]+', security: 'none', 'request-matcher': 'regex') - httpAutoConfig() {} - createAppContext() - - expect: - getFilters('/imlowercase').size() == 0 - filtersMatchExpectedAutoConfigList('/MixedCase'); - } - - def ciRegexPathsWorkCorrectly() { - when: - xml.http(pattern: '\\A\\/[a-z]+', security: 'none', 'request-matcher': 'ciRegex') - httpAutoConfig() {} - createAppContext() - - then: - getFilters('/imMixedCase').size() == 0 - filtersMatchExpectedAutoConfigList('/Im_caught_by_the_Universal_Match'); - } - - def requestMatcherRefWorksCorrectly() { - xml.http('request-matcher-ref': 'matcher', security: 'none') - bean('matcher', AntPathRequestMatcher.class.name, ['/nofilters']) - httpAutoConfig() {} - createAppContext() - - expect: - getFilters('/nofilters').size() == 0 - filtersMatchExpectedAutoConfigList('/somethingElse'); - } - - // SEC-1152 - def anonymousFilterIsAddedByDefault() { - xml.http { - 'form-login'() - } - createAppContext() - - expect: - getFilters("/anything")[9] instanceof AnonymousAuthenticationFilter - } - - def anonymousFilterIsRemovedIfDisabledFlagSet() { - xml.http { - 'form-login'() - 'anonymous'(enabled: 'false') - } - createAppContext() - - expect: - !(getFilters("/anything").get(9) instanceof AnonymousAuthenticationFilter) - } - - def anonymousCustomAttributesAreSetCorrectly() { - xml.http { - 'form-login'() - 'anonymous'(username: 'joe', 'granted-authority':'anonymity', key: 'customKey') - } - createAppContext() - - AnonymousAuthenticationFilter filter = getFilter(AnonymousAuthenticationFilter); - def providers = appContext.getBeansOfType(AuthenticationManager).values()*.providers.flatten() - - expect: - 'customKey' == providers.find { it instanceof AnonymousAuthenticationProvider }.key - 'customKey' == filter.key - 'joe' == filter.principal - 'anonymity' == filter.authorities[0].authority - } - - def anonymousSupportsMultipleGrantedAuthorities() { - xml.http { - 'form-login'() - 'anonymous'(username: 'joe', 'granted-authority':'ROLE_INVITADO,ROLE_PROFILE_INVITADO,ROLE_GRUPO_PUBLICO', key: 'customKey') - } - createAppContext() - - AnonymousAuthenticationFilter filter = getFilter(AnonymousAuthenticationFilter); - def providers = appContext.getBeansOfType(AuthenticationManager).values()*.providers.flatten() - - expect: - 'customKey' == providers.find { it instanceof AnonymousAuthenticationProvider }.key - 'customKey' == filter.key - 'joe' == filter.principal - ['ROLE_INVITADO','ROLE_PROFILE_INVITADO','ROLE_GRUPO_PUBLICO'] == filter.authorities*.authority - } - - def httpMethodMatchIsSupported() { - httpAutoConfig { - interceptUrl '/secure*', 'DELETE', 'ROLE_SUPERVISOR' - interceptUrl '/secure*', 'POST', 'ROLE_A,ROLE_B' - interceptUrl '/**', 'ROLE_C' - } - createAppContext() - - def fids = getFilter(FilterSecurityInterceptor).getSecurityMetadataSource(); - def attrs = fids.getAttributes(createFilterinvocation("/secure", "POST")); - - expect: - attrs.size() == 2 - attrs.contains(new SecurityConfig("ROLE_A")) - attrs.contains(new SecurityConfig("ROLE_B")) - } - - def httpMethodMatchIsSupportedForRequiresChannel() { - httpAutoConfig { - 'intercept-url'(pattern: '/anyurl') - 'intercept-url'(pattern: '/anyurl', 'method':'GET',access: 'ROLE_ADMIN', 'requires-channel': 'https') - } - createAppContext() - - def fids = getFilter(ChannelProcessingFilter).getSecurityMetadataSource(); - def attrs = fids.getAttributes(createFilterinvocation("/anyurl", "GET")); - def attrsPost = fids.getAttributes(createFilterinvocation("/anyurl", "POST")); - - expect: - attrs.size() == 1 - attrs.contains(new SecurityConfig("REQUIRES_SECURE_CHANNEL")) - attrsPost == null - } - - def httpMethodMatchIsSupportedForRequiresChannelAny() { - httpAutoConfig { - 'intercept-url'(pattern: '/**') - 'intercept-url'(pattern: '/**', 'method':'GET',access: 'ROLE_ADMIN', 'requires-channel': 'https') - } - createAppContext() - - def fids = getFilter(ChannelProcessingFilter).getSecurityMetadataSource(); - def attrs = fids.getAttributes(createFilterinvocation("/anyurl", "GET")); - def attrsPost = fids.getAttributes(createFilterinvocation("/anyurl", "POST")); - - expect: - attrs.size() == 1 - attrs.contains(new SecurityConfig("REQUIRES_SECURE_CHANNEL")) - attrsPost == null - } - - def oncePerRequestAttributeIsSupported() { - xml.http('once-per-request': 'false') { - 'http-basic'() - } - createAppContext() - - expect: - !getFilter(FilterSecurityInterceptor).isObserveOncePerRequest() - } - - def httpBasicSupportsSeparateEntryPoint() { - xml.http() { - 'http-basic'('entry-point-ref': 'ep') - } - bean('ep', BasicAuthenticationEntryPoint.class.name, ['realmName':'whocares'],[:]) - createAppContext(); - - def baf = getFilter(BasicAuthenticationFilter) - def etf = getFilter(ExceptionTranslationFilter) - def ep = appContext.getBean("ep") - - expect: - baf.authenticationEntryPoint == ep - // Since no other authentication system is in use, this should also end up on the ETF - etf.authenticationEntryPoint == ep - } - - def interceptUrlWithRequiresChannelAddsChannelFilterToStack() { - httpAutoConfig { - 'intercept-url'(pattern: '/**', 'requires-channel': 'https') - } - createAppContext(); - List filters = getFilters("/someurl"); - - expect: - filters.size() == AUTO_CONFIG_FILTERS + 1 - filters[0] instanceof ChannelProcessingFilter - } - - def portMappingsAreParsedCorrectly() { - httpAutoConfig { - 'port-mappings'() { - 'port-mapping'(http: '9080', https: '9443') - } - } - createAppContext(); - - def pm = (appContext.getBeansOfType(PortMapperImpl).values() as List)[0]; - - expect: - pm.getTranslatedPortMappings().size() == 1 - pm.lookupHttpPort(9443) == 9080 - pm.lookupHttpsPort(9080) == 9443 - } - - def externalFiltersAreTreatedCorrectly() { - httpAutoConfig { - 'custom-filter'(position: 'FIRST', ref: '${customFilterRef}') - 'custom-filter'(after: 'LOGOUT_FILTER', ref: 'userFilter') - 'custom-filter'(before: 'SECURITY_CONTEXT_FILTER', ref: 'userFilter1') - } - bean('phc', PropertyPlaceholderConfigurer) - bean('userFilter', SecurityContextHolderAwareRequestFilter) - bean('userFilter1', SecurityContextPersistenceFilter) - - System.setProperty('customFilterRef', 'userFilter') - createAppContext(); - - def filters = getFilters("/someurl"); - - expect: - AUTO_CONFIG_FILTERS + 3 == filters.size(); - filters[0] instanceof SecurityContextHolderAwareRequestFilter - filters[1] instanceof SecurityContextPersistenceFilter - filters[7] instanceof SecurityContextHolderAwareRequestFilter - filters[1] instanceof SecurityContextPersistenceFilter - } - - def twoFiltersWithSameOrderAreRejected() { - when: - httpAutoConfig { - 'custom-filter'(position: 'LOGOUT_FILTER', ref: 'userFilter') - } - bean('userFilter', SecurityContextHolderAwareRequestFilter) - createAppContext(); - - then: - thrown(BeanDefinitionParsingException) - } - - def x509SupportAddsFilterAtExpectedPosition() { - httpAutoConfig { - x509() - } - createAppContext() - - expect: - getFilters("/someurl")[5] instanceof X509AuthenticationFilter - } - - def x509SubjectPrincipalRegexCanBeSetUsingPropertyPlaceholder() { - httpAutoConfig { - x509('subject-principal-regex':'${subject-principal-regex}') - } - bean('phc', PropertyPlaceholderConfigurer.class.name) - System.setProperty("subject-principal-regex", "uid=(.*),"); - createAppContext() - def filter = getFilter(X509AuthenticationFilter) - - expect: - filter.principalExtractor.subjectDnPattern.pattern() == "uid=(.*)," - } - - def invalidLogoutSuccessUrlIsDetected() { - when: - xml.http { - 'form-login'() - 'logout'('logout-success-url': 'noLeadingSlash') - } - createAppContext() - - then: - BeanCreationException e = thrown() - } - - def cookiesToDeleteOnLogoutUrlAddsCorrectLogoutHandler() { - xml.http { - 'logout'('delete-cookies': 'JSESSIONID, mycookie') - 'form-login'() - } - createAppContext() - def handlers = getFilter(LogoutFilter).handler.logoutHandlers - - expect: - handlers[2] instanceof CookieClearingLogoutHandler - handlers[2].cookiesToClear[0] == 'JSESSIONID' - handlers[2].cookiesToClear[1] == 'mycookie' - } - - def logoutSuccessHandlerIsSetCorrectly() { - xml.http { - 'form-login'() - 'logout'('success-handler-ref': 'logoutHandler') - } - bean('logoutHandler', SimpleUrlLogoutSuccessHandler) - createAppContext() - - LogoutFilter filter = getFilter(LogoutFilter); - - expect: - FieldUtils.getFieldValue(filter, "logoutSuccessHandler") == appContext.getBean("logoutHandler") - } - - def externalRequestCacheIsConfiguredCorrectly() { - httpAutoConfig { - 'request-cache'(ref: 'cache') - } - bean('cache', HttpSessionRequestCache.class.name) - createAppContext() - - expect: - appContext.getBean("cache") == getFilter(ExceptionTranslationFilter.class).requestCache - } - - def customEntryPointIsSupported() { - xml.http('auto-config': 'true', 'entry-point-ref': 'entryPoint') {} - bean('entryPoint', MockEntryPoint.class.name) - createAppContext() - - expect: - getFilter(ExceptionTranslationFilter).getAuthenticationEntryPoint() instanceof MockEntryPoint - } - - /** - * See SEC-750. If the http security post processor causes beans to be instantiated too eagerly, they way miss - * additional processing. In this method we have a UserDetailsService which is referenced from the namespace - * and also has a post processor registered which will modify it. - */ - def httpElementDoesntInterfereWithBeanPostProcessing() { - xml.http('auto-config': 'true', 'entry-point-ref': 'entryPoint') {} - xml.'authentication-manager'() { - 'authentication-provider'('user-service-ref': 'myUserService') - 'authentication-provider'('ref': 'authProvider') - } - bean('authProvider', DaoAuthenticationProvider.class.name, [:], [userDetailsService: 'myUserService']) - bean('entryPoint', MockEntryPoint.class.name) - bean('myUserService', PostProcessedMockUserDetailsService) - bean('userServicePostProcessor', MockUserServiceBeanPostProcessor) - bean('nameCollectingPostProcessor', BeanNameCollectingPostProcessor) - createAppContext("") - def beanPP = appContext.getBean("nameCollectingPostProcessor") - Set preInitPPBeans = beanPP.beforeInitPostProcessedBeans - Set postInitPPBeans = beanPP.afterInitPostProcessedBeans - Set expectedBeans = ['authProvider', 'entryPoint', 'myUserService'] as Set - - expect: - appContext.getBean("myUserService").getPostProcessorWasHere() == "Hello from the post processor!" - preInitPPBeans.containsAll(expectedBeans) - postInitPPBeans.containsAll(expectedBeans) - } - - /* SEC-934 */ - def supportsTwoIdenticalInterceptUrls() { - httpAutoConfig { - interceptUrl ('/someUrl', 'ROLE_A') - interceptUrl ('/someUrl', 'ROLE_B') - } - createAppContext() - def fis = getFilter(FilterSecurityInterceptor) - def fids = fis.securityMetadataSource - Collection attrs = fids.getAttributes(createFilterinvocation("/someUrl", null)); - - expect: - attrs.size() == 1 - attrs.contains(new SecurityConfig("ROLE_B")) - } - - def supportsExternallyDefinedSecurityContextRepository() { - xml.http('create-session': 'always', 'security-context-repository-ref': 'repo') { - 'http-basic'() - } - bean('repo', HttpSessionSecurityContextRepository) - createAppContext() - - def filter = getFilter(SecurityContextPersistenceFilter) - - expect: - filter.repo == appContext.getBean('repo') - filter.forceEagerSessionCreation - } - - def expressionBasedAccessAllowsAndDeniesAccessAsExpected() { - setup: - xml.http('auto-config': 'true', 'use-expressions': 'true') { - interceptUrl('/secure*', "hasAnyRole('ROLE_A','ROLE_C')") - interceptUrl('/**', 'permitAll') - } - createAppContext() - - def fis = getFilter(FilterSecurityInterceptor) - def fids = fis.getSecurityMetadataSource() - Collection attrs = fids.getAttributes(createFilterinvocation("/secure", null)); - assert 1 == attrs.size() - - when: "Unprotected URL" - SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("joe", "", "ROLE_A")); - fis.invoke(createFilterinvocation("/permitallurl", null)); - then: - notThrown(AccessDeniedException) - - when: "Invoking secure Url as a valid user" - fis.invoke(createFilterinvocation("/secure", null)); - then: - notThrown(AccessDeniedException) - - when: "User does not have the required role" - SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("joe", "", "ROLE_B")); - fis.invoke(createFilterinvocation("/secure", null)); - then: - thrown(AccessDeniedException) - } - - def expressionBasedAccessSupportsExternalExpressionHandler() { - setup: - xml.http('auto-config': 'true', 'use-expressions': 'true') { - interceptUrl('/**', "hasPermission('AnyObject','R')") - 'expression-handler'(ref: 'expressionHandler') - } - bean('expressionHandler', DefaultWebSecurityExpressionHandler.class.name, [:], [permissionEvaluator: 'pe']) - bean('pe', MockPermissionEvaluator) - createAppContext() - - def fis = getFilter(FilterSecurityInterceptor) - - when: "Invoking allowed URL protected by hasPermission() expression succeeds" - SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("joe", "", "ANY")); - fis.invoke(createFilterinvocation("/secure", null)); - then: - notThrown(AccessDeniedException) - } - - def protectedLoginPageReportsWarning() { - when: - xml.http('use-expressions': 'true') { - 'form-login'('login-page': '/login') - interceptUrl('/login*', "hasRole('ROLE_A')") - } - createAppContext() - then: - notThrown(BeansException) - } - - def disablingUrlRewritingThroughTheNamespaceSetsCorrectPropertyOnContextRepo() { - xml.http('auto-config': 'true', 'disable-url-rewriting': 'true') - createAppContext() - - expect: - getFilter(SecurityContextPersistenceFilter).repo.disableUrlRewriting - } - - def userDetailsServiceInParentContextIsLocatedSuccessfully() { - when: - createAppContext() - httpAutoConfig { - 'remember-me' - } - appContext = new InMemoryXmlApplicationContext(writer.toString(), appContext) - - then: - notThrown(BeansException) - } - - def httpConfigWithNoAuthProvidersWorksOk() { - when: "Http config has no internal authentication providers" - xml.debug() - xml.http() { - 'form-login'() - csrf(disabled:true) - anonymous(enabled: 'false') - } - createAppContext() - MockHttpServletRequest request = new MockHttpServletRequest("POST", "/login"); - request.setServletPath("/login"); - request.addParameter("username", "bob"); - request.addParameter("password", "bobspassword"); - then: "App context creation and login request succeed" - DebugFilter debugFilter = appContext.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN); - debugFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()); - appListener.events.size() == 2 - appListener.authenticationEvents.size() == 2 - } - - def eraseCredentialsDefaultsToTrue() { - xml.http() { - 'form-login'() - } - createAppContext() - expect: - getFilter(UsernamePasswordAuthenticationFilter).authenticationManager.eraseCredentialsAfterAuthentication - } - - def eraseCredentialsIsSetFromParentAuthenticationManager() { - xml.http() { - 'form-login'() - } - createAppContext(""); - expect: - !getFilter(UsernamePasswordAuthenticationFilter).authenticationManager.eraseCredentialsAfterAuthentication - } - - def 'SEC-2020 authentication-manager@erase-credentials with http@authentication-manager-ref'() { - xml.http('authentication-manager-ref':'authMgr') { - 'form-login'() - } - createAppContext(""); - expect: - def authManager = getFilter(UsernamePasswordAuthenticationFilter).authenticationManager - !authManager.eraseCredentialsAfterAuthentication - !authManager.parent.eraseCredentialsAfterAuthentication - } - - def 'authentication-manager@erase-credentials with http@authentication-manager-ref not ProviderManager'() { - xml.http('authentication-manager-ref':'authMgr') { - 'form-login'() - } - xml.'b:bean'(id: 'authMgr', 'class': MockAuthenticationManager.class.name) - createAppContext() - expect: - def authManager = getFilter(UsernamePasswordAuthenticationFilter).authenticationManager - !authManager.eraseCredentialsAfterAuthentication - authManager.parent instanceof MockAuthenticationManager - } - - def jeeFilterExtractsExpectedRoles() { - xml.http() { - jee('mappable-roles': 'admin,user,a,b,c') - } - createAppContext() - FilterChainProxy fcp = appContext.getBean(BeanIds.FILTER_CHAIN_PROXY) - Principal p = Mock(Principal) - p.getName() >> 'joe' - - when: - - MockHttpServletRequest request = new MockHttpServletRequest("GET","/something") - request.setUserPrincipal(p) - request.addUserRole('admin') - request.addUserRole('user') - request.addUserRole('c') - request.addUserRole('notmapped') - fcp.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()) - SecurityContext ctx = request.getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); - Set roles = AuthorityUtils.authorityListToSet(ctx.getAuthentication().getAuthorities()); - - then: - roles.size() == 3 - roles.contains 'ROLE_admin' - roles.contains 'ROLE_user' - roles.contains 'ROLE_c' - } - - def authenticationDetailsSourceInjectionSucceeds() { - xml.http() { - 'form-login'('authentication-details-source-ref' : 'adsr') - 'openid-login' ('authentication-details-source-ref' : 'adsr') - 'http-basic' ('authentication-details-source-ref' : 'adsr') - 'x509' ('authentication-details-source-ref' : 'adsr') - } - bean('adsr', 'org.springframework.security.web.authentication.WebAuthenticationDetailsSource') - createAppContext() - def adsr = appContext.getBean('adsr') - expect: - getFilter(UsernamePasswordAuthenticationFilter).authenticationDetailsSource == adsr - getFilter(OpenIDAuthenticationFilter).authenticationDetailsSource == adsr - getFilter(BasicAuthenticationFilter).authenticationDetailsSource == adsr - getFilter(X509AuthenticationFilter).authenticationDetailsSource == adsr - } - - def includeJaasApiIntegrationFilter() { - xml.http(['auto-config':'true','jaas-api-provision':'true']) - createAppContext() - expect: - getFilter(JaasApiIntegrationFilter.class) != null - } - - def httpFirewallInjectionIsSupported() { - xml.'http-firewall'(ref: 'fw') - xml.http() { - 'form-login'() - } - bean('fw', DefaultHttpFirewall) - createAppContext() - FilterChainProxy fcp = appContext.getBean(BeanIds.FILTER_CHAIN_PROXY) - expect: - fcp.firewall == appContext.getBean('fw') - } - - def customAccessDecisionManagerIsSupported() { - xml.http('auto-config': 'true', 'access-decision-manager-ref': 'adm') - xml.'b:bean'(id: 'adm', 'class': AffirmativeBased.class.name) { - 'b:constructor-arg' { - 'b:list'() { - 'b:bean'('class': RoleVoter.class.name) - 'b:bean'('class': RoleVoter.class.name) - 'b:bean'('class': RoleVoter.class.name) - 'b:bean'('class': WebExpressionVoter.class.name) - } - } - } - createAppContext() - expect: - getFilter(FilterSecurityInterceptor.class).accessDecisionManager.decisionVoters[3] instanceof WebExpressionVoter - } - - def customAuthenticationManagerIsSupported() { - xml.http('auto-config': 'true', 'authentication-manager-ref': 'am') - xml.'b:bean'(id: 'am', 'class': MockAuthenticationManager.class.name) - createAppContext("") - expect: - getFilter(UsernamePasswordAuthenticationFilter.class).authenticationManager.parent instanceof MockAuthenticationManager - } - - // SEC-1893 - def customPortMappings() { - when: 'A custom port-mappings is registered' - def expectedHttpsPortMappings = [8443:8080] - xml.http('auto-config': 'true') { - 'intercept-url'('pattern':'/**','requires-channel':'https') - 'port-mappings' { - 'port-mapping'(http:'8443',https:'8080') - } - } - createAppContext() - - then: 'All the components created by the namespace use that port mapping' - getFilter(RequestCacheAwareFilter.class).requestCache.portResolver.portMapper.httpsPortMappings == expectedHttpsPortMappings - - def channelProcessors = getFilter(ChannelProcessingFilter.class).channelDecisionManager.channelProcessors - channelProcessors.size() == 2 - channelProcessors.each { cp-> - cp.entryPoint.portMapper.httpsPortMappings == expectedHttpsPortMappings - cp.entryPoint.portResolver.portMapper.httpsPortMappings == expectedHttpsPortMappings - } - - def authEntryPoint = getFilter(ExceptionTranslationFilter.class).authenticationEntryPoint - authEntryPoint.portMapper.httpsPortMappings == expectedHttpsPortMappings - authEntryPoint.portResolver.portMapper.httpsPortMappings == expectedHttpsPortMappings - } -} - -class MockAuthenticationManager implements AuthenticationManager { - Authentication authenticate(Authentication authentication) { - return null - } -} - -class MockPermissionEvaluator implements PermissionEvaluator { - boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) { - return true - } - - boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) { - return true - } - -} - -class MockEntryPoint extends LoginUrlAuthenticationEntryPoint { - public MockEntryPoint() { - super("/notused"); - } -} diff --git a/config/src/test/java/org/springframework/security/BeanNameCollectingPostProcessor.java b/config/src/test/java/org/springframework/security/BeanNameCollectingPostProcessor.java index 70d308aa54..690cfcba50 100644 --- a/config/src/test/java/org/springframework/security/BeanNameCollectingPostProcessor.java +++ b/config/src/test/java/org/springframework/security/BeanNameCollectingPostProcessor.java @@ -15,11 +15,12 @@ */ package org.springframework.security; +import java.util.HashSet; +import java.util.Set; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; -import java.util.*; - /** * @author Luke Taylor */ @@ -42,4 +43,12 @@ public class BeanNameCollectingPostProcessor implements BeanPostProcessor { } return bean; } + + public Set getBeforeInitPostProcessedBeans() { + return beforeInitPostProcessedBeans; + } + + public Set getAfterInitPostProcessedBeans() { + return afterInitPostProcessedBeans; + } } diff --git a/config/src/test/java/org/springframework/security/config/http/MiscHttpConfigTests.java b/config/src/test/java/org/springframework/security/config/http/MiscHttpConfigTests.java new file mode 100644 index 0000000000..3f71937e17 --- /dev/null +++ b/config/src/test/java/org/springframework/security/config/http/MiscHttpConfigTests.java @@ -0,0 +1,987 @@ +/* + * Copyright 2002-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.security.config.http; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.security.AccessController; +import java.security.Principal; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import javax.security.auth.Subject; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.login.LoginException; +import javax.security.auth.spi.LoginModule; +import javax.servlet.Filter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponseWrapper; + +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.Appender; +import org.apache.http.HttpStatus; +import org.assertj.core.api.iterable.Extractor; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.stubbing.Answer; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanCreationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.mock.web.MockHttpSession; +import org.springframework.security.BeanNameCollectingPostProcessor; +import org.springframework.security.access.AccessDecisionManager; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.access.ConfigAttribute; +import org.springframework.security.access.PermissionEvaluator; +import org.springframework.security.authentication.AnonymousAuthenticationToken; +import org.springframework.security.authentication.AuthenticationDetailsSource; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.InsufficientAuthenticationException; +import org.springframework.security.authentication.TestingAuthenticationToken; +import org.springframework.security.authentication.jaas.AuthorityGranter; +import org.springframework.security.config.test.SpringTestRule; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.core.authority.AuthorityUtils; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.context.SecurityContextImpl; +import org.springframework.security.openid.OpenIDAuthenticationFilter; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.security.web.FilterChainProxy; +import org.springframework.security.web.access.ExceptionTranslationFilter; +import org.springframework.security.web.access.channel.ChannelProcessingFilter; +import org.springframework.security.web.access.intercept.FilterSecurityInterceptor; +import org.springframework.security.web.authentication.AnonymousAuthenticationFilter; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.authentication.logout.LogoutFilter; +import org.springframework.security.web.authentication.preauth.x509.X509AuthenticationFilter; +import org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter; +import org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter; +import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; +import org.springframework.security.web.context.HttpRequestResponseHolder; +import org.springframework.security.web.context.SecurityContextPersistenceFilter; +import org.springframework.security.web.context.SecurityContextRepository; +import org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter; +import org.springframework.security.web.csrf.CsrfFilter; +import org.springframework.security.web.firewall.FirewalledRequest; +import org.springframework.security.web.firewall.HttpFirewall; +import org.springframework.security.web.header.HeaderWriterFilter; +import org.springframework.security.web.savedrequest.RequestCache; +import org.springframework.security.web.savedrequest.RequestCacheAwareFilter; +import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter; +import org.springframework.security.web.session.SessionManagementFilter; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.support.XmlWebApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.x509; +import static org.springframework.test.util.ReflectionTestUtils.getField; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + + +/** + * + * @author Luke Taylor + * @author Rob Winch + */ +public class MiscHttpConfigTests { + private static final String CONFIG_LOCATION_PREFIX = + "classpath:org/springframework/security/config/http/MiscHttpConfigTests"; + + @Autowired + MockMvc mvc; + + @Rule + public final SpringTestRule spring = new SpringTestRule(); + + @Test + public void configureWhenUsingMinimalConfigurationThenParses() { + this.spring.configLocations(xml("MinimalConfiguration")).autowire(); + } + + @Test + public void configureWhenUsingAutoConfigThenSetsUpCorrectFilterList() { + this.spring.configLocations(xml("AutoConfig")).autowire(); + assertThatFiltersMatchExpectedAutoConfigList(); + } + + @Test + public void configureWhenUsingSecurityNoneThenNoFiltersAreSetUp() { + this.spring.configLocations(xml("NoSecurityForPattern")).autowire(); + assertThat(getFilters("/unprotected")).isEmpty(); + } + + @Test + public void requestWhenUsingDebugFilterAndPatternIsNotConfigureForSecurityThenRespondsOk() + throws Exception { + + this.spring.configLocations(xml("NoSecurityForPattern")).autowire(); + + this.mvc.perform(get("/unprotected")) + .andExpect(status().isNotFound()); + + this.mvc.perform(get("/nomatch")) + .andExpect(status().isNotFound()); + } + + @Test + public void requestWhenHttpPatternUsesRegexMatchingThenMatchesAccordingly() + throws Exception { + + this.spring.configLocations(xml("RegexSecurityPattern")).autowire(); + + this.mvc.perform(get("/protected")) + .andExpect(status().isUnauthorized()); + + this.mvc.perform(get("/unprotected")) + .andExpect(status().isNotFound()); + } + + @Test + public void requestWhenHttpPatternUsesCiRegexMatchingThenMatchesAccordingly() + throws Exception { + + this.spring.configLocations(xml("CiRegexSecurityPattern")).autowire(); + + this.mvc.perform(get("/ProTectEd")) + .andExpect(status().isUnauthorized()); + + this.mvc.perform(get("/UnProTectEd")) + .andExpect(status().isNotFound()); + } + + @Test + public void requestWhenHttpPatternUsesCustomRequestMatcherThenMatchesAccordingly() + throws Exception { + + this.spring.configLocations(xml("CustomRequestMatcher")).autowire(); + + this.mvc.perform(get("/protected")) + .andExpect(status().isUnauthorized()); + + this.mvc.perform(get("/unprotected")) + .andExpect(status().isNotFound()); + } + + /** + * SEC-1152 + */ + @Test + public void requestWhenUsingMinimalConfigurationThenHonorsAnonymousEndpoints() + throws Exception { + + this.spring.configLocations(xml("AnonymousEndpoints")).autowire(); + + this.mvc.perform(get("/protected")) + .andExpect(status().isUnauthorized()); + + this.mvc.perform(get("/unprotected")) + .andExpect(status().isNotFound()); + + assertThat(getFilter(AnonymousAuthenticationFilter.class)).isNotNull(); + } + + @Test + public void requestWhenAnonymousIsDisabledThenRejectsAnonymousEndpoints() + throws Exception { + + this.spring.configLocations(xml("AnonymousDisabled")).autowire(); + + this.mvc.perform(get("/protected")) + .andExpect(status().isUnauthorized()); + + this.mvc.perform(get("/unprotected")) + .andExpect(status().isUnauthorized()); + + assertThat(getFilter(AnonymousAuthenticationFilter.class)).isNull(); + } + + @Test + public void requestWhenAnonymousUsesCustomAttributesThenRespondsWithThoseAttributes() + throws Exception { + + this.spring.configLocations(xml("AnonymousCustomAttributes")).autowire(); + + this.mvc.perform(get("/protected") + .with(httpBasic("user", "password"))) + .andExpect(status().isForbidden()); + + this.mvc.perform(get("/protected")) + .andExpect(status().isOk()) + .andExpect(content().string("josh")); + + this.mvc.perform(get("/customKey")) + .andExpect(status().isOk()) + .andExpect(content().string(String.valueOf("myCustomKey".hashCode()))); + } + + @Test + public void requestWhenAnonymousUsesMultipleGrantedAuthoritiesThenRespondsWithThoseAttributes() + throws Exception { + + this.spring.configLocations(xml("AnonymousMultipleAuthorities")).autowire(); + + this.mvc.perform(get("/protected") + .with(httpBasic("user", "password"))) + .andExpect(status().isForbidden()); + + this.mvc.perform(get("/protected")) + .andExpect(status().isOk()) + .andExpect(content().string("josh")); + + this.mvc.perform(get("/customKey")) + .andExpect(status().isOk()) + .andExpect(content().string(String.valueOf("myCustomKey".hashCode()))); + } + + @Test + public void requestWhenInterceptUrlMatchesMethodThenSecuresAccordingly() + throws Exception { + + this.spring.configLocations(xml("InterceptUrlMethod")).autowire(); + + this.mvc.perform(get("/protected") + .with(httpBasic("user", "password"))) + .andExpect(status().isOk()); + + this.mvc.perform(post("/protected") + .with(httpBasic("user", "password"))) + .andExpect(status().isForbidden()); + + this.mvc.perform(post("/protected") + .with(httpBasic("poster", "password"))) + .andExpect(status().isOk()); + + this.mvc.perform(delete("/protected") + .with(httpBasic("poster", "password"))) + .andExpect(status().isForbidden()); + + this.mvc.perform(delete("/protected") + .with(httpBasic("admin", "password"))) + .andExpect(status().isOk()); + } + + @Test + public void requestWhenInterceptUrlMatchesMethodAndRequiresHttpsThenSecuresAccordingly() + throws Exception { + + this.spring.configLocations(xml("InterceptUrlMethodRequiresHttps")).autowire(); + + this.mvc.perform(post("/protected").with(csrf())) + .andExpect(status().isOk()); + + this.mvc.perform(get("/protected") + .secure(true) + .with(httpBasic("user", "password"))) + .andExpect(status().isForbidden()); + + this.mvc.perform(get("/protected") + .secure(true) + .with(httpBasic("admin", "password"))) + .andExpect(status().isOk()); + } + + @Test + public void requestWhenInterceptUrlMatchesAnyPatternAndRequiresHttpsThenSecuresAccordingly() + throws Exception { + + this.spring.configLocations(xml("InterceptUrlMethodRequiresHttpsAny")).autowire(); + + this.mvc.perform(post("/protected").with(csrf())) + .andExpect(status().isOk()); + + this.mvc.perform(get("/protected") + .secure(true) + .with(httpBasic("user", "password"))) + .andExpect(status().isForbidden()); + + this.mvc.perform(get("/protected") + .secure(true) + .with(httpBasic("admin", "password"))) + .andExpect(status().isOk()); + } + + @Test + public void configureWhenOncePerRequestIsFalseThenFilterSecurityInterceptorExercisedForForwards() { + this.spring.configLocations(xml("OncePerRequest")).autowire(); + + FilterSecurityInterceptor filterSecurityInterceptor = getFilter(FilterSecurityInterceptor.class); + assertThat(filterSecurityInterceptor.isObserveOncePerRequest()).isFalse(); + } + + @Test + public void requestWhenCustomHttpBasicEntryPointRefThenInvokesOnCommence() + throws Exception { + + this.spring.configLocations(xml("CustomHttpBasicEntryPointRef")).autowire(); + + AuthenticationEntryPoint entryPoint = this.spring.getContext().getBean(AuthenticationEntryPoint.class); + + this.mvc.perform(get("/protected")) + .andExpect(status().isOk()); + + verify(entryPoint).commence( + any(HttpServletRequest.class), any(HttpServletResponse.class), any(AuthenticationException.class)); + } + + @Test + public void configureWhenInterceptUrlWithRequiresChannelThenAddedChannelFilterToChain() { + this.spring.configLocations(xml("InterceptUrlMethodRequiresHttpsAny")).autowire(); + assertThat(getFilter(ChannelProcessingFilter.class)).isNotNull(); + } + + @Test + public void getWhenPortsMappedThenRedirectedAccordingly() throws Exception { + this.spring.configLocations(xml("PortsMappedInterceptUrlMethodRequiresAny")).autowire(); + + this.mvc.perform(get("http://localhost:9080/protected")) + .andExpect(redirectedUrl("https://localhost:9443/protected")); + } + + @Test + public void configureWhenCustomFiltersThenAddedToChainInCorrectOrder() { + System.setProperty("customFilterRef", "userFilter"); + this.spring.configLocations(xml("CustomFilters")).autowire(); + + List filters = getFilters("/"); + + Class userFilterClass = this.spring.getContext().getBean("userFilter").getClass(); + + assertThat(filters) + .extracting((Extractor>) filter -> filter.getClass()) + .containsSubsequence( + userFilterClass, userFilterClass, + SecurityContextPersistenceFilter.class, LogoutFilter.class, + userFilterClass); + } + + @Test + public void configureWhenTwoFiltersWithSameOrderThenException() { + assertThatCode(() -> this.spring.configLocations(xml("CollidingFilters")).autowire()) + .isInstanceOf(BeanDefinitionParsingException.class); + } + + @Test + public void configureWhenUsingX509ThenAddsX509FilterCorrectly() { + this.spring.configLocations(xml("X509")).autowire(); + + assertThat(getFilters("/")) + .extracting((Extractor>) filter -> filter.getClass()) + .containsSubsequence( + CsrfFilter.class, X509AuthenticationFilter.class, ExceptionTranslationFilter.class); + } + + + @Test + public void getWhenUsingX509AndPropertyPlaceholderThenSubjectPrincipalRegexIsConfigured() throws Exception { + System.setProperty("subject_principal_regex", "OU=(.*?)(?:,|$)"); + this.spring.configLocations(xml("X509")).autowire(); + + this.mvc.perform(get("/protected") + .with(x509("classpath:org/springframework/security/config/http/MiscHttpConfigTests-certificate.pem"))) + .andExpect(status().isOk()); + } + + @Test + public void configureWhenUsingInvalidLogoutSuccessUrlThenThrowsException() { + assertThatCode(() -> this.spring.configLocations(xml("InvalidLogoutSuccessUrl")).autowire()) + .isInstanceOf(BeanCreationException.class); + } + + @Test + public void logoutWhenSpecifyingCookiesToDeleteThenSetCookieAdded() throws Exception { + this.spring.configLocations(xml("DeleteCookies")).autowire(); + + MvcResult result = + this.mvc.perform(post("/logout").with(csrf())).andReturn(); + + List values = result.getResponse().getHeaders("Set-Cookie"); + assertThat(values.size()).isEqualTo(2); + assertThat(values).extracting(value -> value.split("=")[0]).contains("JSESSIONID", "mycookie"); + } + + @Test + public void logoutWhenSpecifyingSuccessHandlerRefThenResponseHandledAccordingly() throws Exception { + this.spring.configLocations(xml("LogoutSuccessHandlerRef")).autowire(); + + this.mvc.perform(post("/logout").with(csrf())) + .andExpect(redirectedUrl("/logoutSuccessEndpoint")); + } + + @Test + public void getWhenUnauthenticatedThenUsesConfiguredRequestCache() throws Exception { + this.spring.configLocations(xml("RequestCache")).autowire(); + + RequestCache requestCache = this.spring.getContext().getBean(RequestCache.class); + + this.mvc.perform(get("/")); + + verify(requestCache).saveRequest(any(HttpServletRequest.class), any(HttpServletResponse.class)); + } + + @Test + public void getWhenUnauthenticatedThenUsesConfiguredAuthenticationEntryPoint() throws Exception { + this.spring.configLocations(xml("EntryPoint")).autowire(); + + AuthenticationEntryPoint entryPoint = this.spring.getContext().getBean(AuthenticationEntryPoint.class); + + this.mvc.perform(get("/")); + + verify(entryPoint).commence( + any(HttpServletRequest.class), + any(HttpServletResponse.class), + any(AuthenticationException.class)); + } + + /** + * See SEC-750. If the http security post processor causes beans to be instantiated too eagerly, they way miss + * additional processing. In this method we have a UserDetailsService which is referenced from the namespace + * and also has a post processor registered which will modify it. + */ + @Test + public void configureWhenUsingCustomUserDetailsServiceThenBeanPostProcessorsAreStillApplied() { + this.spring.configLocations(xml("Sec750")).autowire(); + + BeanNameCollectingPostProcessor postProcessor = + this.spring.getContext().getBean(BeanNameCollectingPostProcessor.class); + + assertThat(postProcessor.getBeforeInitPostProcessedBeans()) + .contains("authenticationProvider", "userService"); + assertThat(postProcessor.getAfterInitPostProcessedBeans()) + .contains("authenticationProvider", "userService"); + + } + + /* SEC-934 */ + @Test + public void getWhenUsingTwoIdenticalInterceptUrlsThenTheSecondTakesPrecedence() throws Exception { + this.spring.configLocations(xml("Sec934")).autowire(); + + this.mvc.perform(get("/protected") + .with(httpBasic("user", "password"))) + .andExpect(status().isOk()); + + this.mvc.perform(get("/protected") + .with(httpBasic("admin", "password"))) + .andExpect(status().isForbidden()); + } + + @Test + public void getWhenAuthenticatingThenConsultsCustomSecurityContextRepository() throws Exception { + this.spring.configLocations(xml("SecurityContextRepository")).autowire(); + + SecurityContextRepository repository = this.spring.getContext().getBean(SecurityContextRepository.class); + SecurityContext context = new SecurityContextImpl(new TestingAuthenticationToken("user", "password")); + when(repository.loadContext(any(HttpRequestResponseHolder.class))).thenReturn(context); + + MvcResult result = + this.mvc.perform(get("/protected") + .with(httpBasic("user", "password"))) + .andExpect(status().isOk()) + .andReturn(); + + assertThat(result.getRequest().getSession(false)).isNotNull(); + + verify(repository, atLeastOnce()).saveContext( + any(SecurityContext.class), + any(HttpServletRequest.class), + any(HttpServletResponse.class)); + } + + @Test + public void getWhenUsingInterceptUrlExpressionsThenAuthorizesAccordingly() throws Exception { + this.spring.configLocations(xml("InterceptUrlExpressions")).autowire(); + + this.mvc.perform(get("/protected") + .with(httpBasic("admin", "password"))) + .andExpect(status().isOk()); + + this.mvc.perform(get("/protected") + .with(httpBasic("user", "password"))) + .andExpect(status().isForbidden()); + + this.mvc.perform(get("/unprotected") + .with(httpBasic("user", "password"))) + .andExpect(status().isOk()); + + } + + @Test + public void getWhenUsingCustomExpressionHandlerThenAuthorizesAccordingly() throws Exception { + this.spring.configLocations(xml("ExpressionHandler")).autowire(); + + PermissionEvaluator permissionEvaluator = this.spring.getContext().getBean(PermissionEvaluator.class); + when(permissionEvaluator.hasPermission(any(Authentication.class), any(Object.class), any(Object.class))) + .thenReturn(false); + + this.mvc.perform(get("/") + .with(httpBasic("user", "password"))) + .andExpect(status().isForbidden()); + + verify(permissionEvaluator).hasPermission(any(Authentication.class), any(Object.class), any(Object.class)); + } + + @Test + public void configureWhenProtectingLoginPageThenWarningLogged() { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + redirectLogsTo(baos, DefaultFilterChainValidator.class); + + this.spring.configLocations(xml("ProtectedLoginPage")).autowire(); + + assertThat(baos.toString()).contains("[WARN]"); + } + + @Test + public void configureWhenUsingDisableUrlRewritingThenRedirectIsNotEncodedByResponse() + throws IOException, ServletException { + + this.spring.configLocations(xml("DisableUrlRewriting")).autowire(); + + MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); + MockHttpServletResponse response = new MockHttpServletResponse(); + + FilterChainProxy proxy = this.spring.getContext().getBean(FilterChainProxy.class); + + proxy.doFilter( + request, + new EncodeUrlDenyingHttpServletResponseWrapper(response), + (req, resp) -> {}); + + assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_MOVED_TEMPORARILY); + assertThat(response.getRedirectedUrl()).isEqualTo("http://localhost/login"); + } + + @Test + public void configureWhenUserDetailsServiceInParentContextThenLocatesSuccessfully() { + assertThatCode(() -> this.spring.configLocations(this.xml("MissingUserDetailsService")).autowire()) + .isInstanceOf(BeansException.class); + + try ( XmlWebApplicationContext parent = new XmlWebApplicationContext() ) { + parent.setConfigLocations(this.xml("AutoConfig")); + parent.refresh(); + + try ( XmlWebApplicationContext child = new XmlWebApplicationContext() ) { + child.setParent(parent); + child.setConfigLocation(this.xml("MissingUserDetailsService")); + child.refresh(); + } + } + } + + @Test + public void loginWhenConfiguredWithNoInternalAuthenticationProvidersThenSuccessfullyAuthenticates() + throws Exception { + + this.spring.configLocations(xml("NoInternalAuthenticationProviders")).autowire(); + + this.mvc.perform(post("/login") + .param("username", "user") + .param("password", "password")) + .andExpect(redirectedUrl("/")); + } + + @Test + public void loginWhenUsingDefaultsThenErasesCredentialsAfterAuthentication() throws Exception { + this.spring.configLocations(xml("HttpBasic")).autowire(); + + this.mvc.perform(get("/password") + .with(httpBasic("user", "password"))) + .andExpect(content().string("")); + } + + @Test + public void loginWhenAuthenticationManagerConfiguredToEraseCredentialsThenErasesCredentialsAfterAuthentication() + throws Exception { + + this.spring.configLocations(xml("AuthenticationManagerEraseCredentials")).autowire(); + + this.mvc.perform(get("/password") + .with(httpBasic("user", "password"))) + .andExpect(content().string("")); + } + + /** + * SEC-2020 + */ + @Test + public void loginWhenAuthenticationManagerRefConfiguredToKeepCredentialsThenKeepsCredentialsAfterAuthentication() + throws Exception { + + this.spring.configLocations(xml("AuthenticationManagerRefKeepCredentials")).autowire(); + + this.mvc.perform(get("/password") + .with(httpBasic("user", "password"))) + .andExpect(content().string("password")); + } + + @Test + public void loginWhenAuthenticationManagerRefIsNotAProviderManagerThenKeepsCredentialsAccordingly() + throws Exception { + + this.spring.configLocations(xml("AuthenticationManagerRefNotProviderManager")).autowire(); + + this.mvc.perform(get("/password") + .with(httpBasic("user", "password"))) + .andExpect(content().string("password")); + } + + @Test + public void loginWhenJeeFilterThenExtractsRoles() throws Exception { + this.spring.configLocations(xml("JeeFilter")).autowire(); + + Principal user = mock(Principal.class); + when(user.getName()).thenReturn("joe"); + + this.mvc.perform(get("/roles") + .principal(user) + .with(request -> { + request.addUserRole("admin"); + request.addUserRole("user"); + request.addUserRole("unmapped"); + return request; + })) + .andExpect(content().string("ROLE_admin,ROLE_user")); + } + + @Test + public void loginWhenUsingCustomAuthenticationDetailsSourceRefThenAuthenticationSourcesDetailsAccordingly() + throws Exception { + + this.spring.configLocations(xml("CustomAuthenticationDetailsSourceRef")).autowire(); + + Object details = mock(Object.class); + AuthenticationDetailsSource source = this.spring.getContext().getBean(AuthenticationDetailsSource.class); + when(source.buildDetails(any(Object.class))).thenReturn(details); + + this.mvc.perform(get("/details") + .with(httpBasic("user", "password"))) + .andExpect(content().string(details.getClass().getName())); + + this.mvc.perform(get("/details") + .with(x509("classpath:org/springframework/security/config/http/MiscHttpConfigTests-certificate.pem"))) + .andExpect(content().string(details.getClass().getName())); + + MockHttpSession session = (MockHttpSession) + this.mvc.perform(post("/login") + .param("username", "user") + .param("password", "password") + .with(csrf())) + .andReturn().getRequest().getSession(false); + + this.mvc.perform(get("/details") + .session(session)) + .andExpect(content().string(details.getClass().getName())); + + assertThat(getField(getFilter(OpenIDAuthenticationFilter.class), "authenticationDetailsSource")) + .isEqualTo(source); + } + + @Test + public void loginWhenUsingJaasApiProvisionThenJaasSubjectContainsUsername() throws Exception { + this.spring.configLocations(xml("Jaas")).autowire(); + + AuthorityGranter granter = this.spring.getContext().getBean(AuthorityGranter.class); + when(granter.grant(any(Principal.class))).thenReturn(new HashSet<>(Arrays.asList("USER"))); + + this.mvc.perform(get("/username") + .with(httpBasic("user", "password"))) + .andExpect(content().string("user")); + } + + @Test + public void getWhenUsingCustomHttpFirewallThenFirewallIsInvoked() throws Exception { + this.spring.configLocations(xml("HttpFirewall")).autowire(); + + FirewalledRequest request = new FirewalledRequest(new MockHttpServletRequest()) { + @Override + public void reset() { } + }; + HttpServletResponse response = new MockHttpServletResponse(); + + HttpFirewall firewall = this.spring.getContext().getBean(HttpFirewall.class); + when(firewall.getFirewalledRequest(any(HttpServletRequest.class))).thenReturn(request); + when(firewall.getFirewalledResponse(any(HttpServletResponse.class))).thenReturn(response); + this.mvc.perform(get("/unprotected")); + + verify(firewall).getFirewalledRequest(any(HttpServletRequest.class)); + verify(firewall).getFirewalledResponse(any(HttpServletResponse.class)); + } + + @Test + public void getWhenUsingCustomAccessDecisionManagerThenAuthorizesAccordingly() throws Exception { + this.spring.configLocations(xml("CustomAccessDecisionManager")).autowire(); + + this.mvc.perform(get("/unprotected") + .with(httpBasic("user", "password"))) + .andExpect(status().isForbidden()); + } + + /** + * SEC-1893 + */ + @Test + public void authenticateWhenUsingPortMapperThenRedirectsAppropriately() throws Exception { + this.spring.configLocations(xml("PortsMappedRequiresHttps")).autowire(); + + MockHttpSession session = (MockHttpSession) + this.mvc.perform(get("https://localhost:9080/protected")) + .andExpect(redirectedUrl("https://localhost:9443/login")) + .andReturn().getRequest().getSession(false); + + session = (MockHttpSession) + this.mvc.perform(post("/login") + .param("username", "user") + .param("password", "password") + .session(session) + .with(csrf())) + .andExpect(redirectedUrl("https://localhost:9443/protected")) + .andReturn().getRequest().getSession(false); + + this.mvc.perform(get("http://localhost:9080/protected") + .session(session)) + .andExpect(redirectedUrl("https://localhost:9443/protected")); + } + + @RestController + static class BasicController { + @RequestMapping("/unprotected") + public String unprotected() { + return "ok"; + } + + @RequestMapping("/protected") + public String protectedMethod(@AuthenticationPrincipal String name) { + return name; + } + } + + @RestController + static class CustomKeyController { + @GetMapping("/customKey") + public String customKey() { + Authentication authentication = + SecurityContextHolder.getContext().getAuthentication(); + + if ( authentication != null && + authentication instanceof AnonymousAuthenticationToken ) { + return String.valueOf( + ((AnonymousAuthenticationToken) authentication).getKeyHash()); + } + + return null; + } + } + + @RestController + static class AuthenticationController { + @GetMapping("/password") + public String password(@AuthenticationPrincipal Authentication authentication) { + return (String) authentication.getCredentials(); + } + + @GetMapping("/roles") + public String roles(@AuthenticationPrincipal Authentication authentication) { + return authentication.getAuthorities().stream() + .map(GrantedAuthority::getAuthority) + .collect(Collectors.joining(",")); + } + + @GetMapping("/details") + public String details(@AuthenticationPrincipal Authentication authentication) { + return authentication.getDetails().getClass().getName(); + } + } + + @RestController + static class JaasController { + @GetMapping("/username") + public String username() { + Subject subject = Subject.getSubject(AccessController.getContext()); + return subject.getPrincipals().iterator().next().getName(); + } + } + + public static class JaasLoginModule implements LoginModule { + private Subject subject; + + @Override + public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { + this.subject = subject; + } + + @Override + public boolean login() throws LoginException { + return this.subject.getPrincipals().add(() -> "user"); + } + + @Override + public boolean commit() throws LoginException { + return true; + } + + @Override + public boolean abort() throws LoginException { + return true; + } + + @Override + public boolean logout() throws LoginException { + return true; + } + } + + static class MockAccessDecisionManager implements AccessDecisionManager { + + @Override + public void decide(Authentication authentication, Object object, Collection configAttributes) throws AccessDeniedException, InsufficientAuthenticationException { + throw new AccessDeniedException("teapot"); + } + + @Override + public boolean supports(ConfigAttribute attribute) { + return true; + } + + @Override + public boolean supports(Class clazz) { + return true; + } + } + + static class MockAuthenticationManager implements AuthenticationManager { + public Authentication authenticate(Authentication authentication) { + return new TestingAuthenticationToken(authentication.getPrincipal(), + authentication.getCredentials(), + AuthorityUtils.createAuthorityList("ROLE_USER")); + } + } + + static class EncodeUrlDenyingHttpServletResponseWrapper + extends HttpServletResponseWrapper { + + public EncodeUrlDenyingHttpServletResponseWrapper(HttpServletResponse response) { + super(response); + } + + @Override + public String encodeURL(String url) { + throw new RuntimeException("Unexpected invocation of encodeURL"); + } + + @Override + public String encodeRedirectURL(String url) { + throw new RuntimeException("Unexpected invocation of encodeURL"); + } + + @Override + public String encodeUrl(String url) { + throw new RuntimeException("Unexpected invocation of encodeURL"); + } + + @Override + public String encodeRedirectUrl(String url) { + throw new RuntimeException("Unexpected invocation of encodeURL"); + } + } + + private void redirectLogsTo(OutputStream os, Class clazz) { + Logger logger = (Logger) LoggerFactory.getLogger(clazz); + Appender appender = mock(Appender.class); + when(appender.isStarted()).thenReturn(true); + doAnswer(writeTo(os)).when(appender).doAppend(any(ILoggingEvent.class)); + logger.addAppender(appender); + } + + private Answer writeTo(OutputStream os) { + return invocation -> { + os.write(invocation.getArgument(0).toString().getBytes()); + return null; + }; + } + + private void assertThatFiltersMatchExpectedAutoConfigList() { + assertThatFiltersMatchExpectedAutoConfigList("/"); + } + + private void assertThatFiltersMatchExpectedAutoConfigList(String url) { + Iterator filters = getFilters(url).iterator(); + + assertThat(filters.next()).isInstanceOf(SecurityContextPersistenceFilter.class); + assertThat(filters.next()).isInstanceOf(WebAsyncManagerIntegrationFilter.class); + assertThat(filters.next()).isInstanceOf(HeaderWriterFilter.class); + assertThat(filters.next()).isInstanceOf(CsrfFilter.class); + assertThat(filters.next()).isInstanceOf(LogoutFilter.class); + assertThat(filters.next()).isInstanceOf(UsernamePasswordAuthenticationFilter.class); + assertThat(filters.next()).isInstanceOf(DefaultLoginPageGeneratingFilter.class); + assertThat(filters.next()).isInstanceOf(DefaultLogoutPageGeneratingFilter.class); + assertThat(filters.next()).isInstanceOf(BasicAuthenticationFilter.class); + assertThat(filters.next()).isInstanceOf(RequestCacheAwareFilter.class); + assertThat(filters.next()).isInstanceOf(SecurityContextHolderAwareRequestFilter.class); + assertThat(filters.next()).isInstanceOf(AnonymousAuthenticationFilter.class); + assertThat(filters.next()).isInstanceOf(SessionManagementFilter.class); + assertThat(filters.next()).isInstanceOf(ExceptionTranslationFilter.class); + assertThat(filters.next()).isInstanceOf(FilterSecurityInterceptor.class) + .hasFieldOrPropertyWithValue("observeOncePerRequest", true); + } + + private T getFilter(Class filterClass) { + return (T) getFilters("/").stream().filter(filterClass::isInstance).findFirst().orElse(null); + } + + private List getFilters(String url) { + FilterChainProxy proxy = this.spring.getContext().getBean(FilterChainProxy.class); + return proxy.getFilters(url); + } + + private static String xml(String configName) { + return CONFIG_LOCATION_PREFIX + "-" + configName + ".xml"; + } +} diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousCustomAttributes.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousCustomAttributes.xml new file mode 100644 index 0000000000..3a3be47abd --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousCustomAttributes.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousDisabled.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousDisabled.xml new file mode 100644 index 0000000000..b98e95d7b7 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousDisabled.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousEndpoints.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousEndpoints.xml new file mode 100644 index 0000000000..90cd2a6fb9 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousEndpoints.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousMultipleAuthorities.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousMultipleAuthorities.xml new file mode 100644 index 0000000000..99069f9f79 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AnonymousMultipleAuthorities.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AuthenticationManagerEraseCredentials.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AuthenticationManagerEraseCredentials.xml new file mode 100644 index 0000000000..168f64d575 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AuthenticationManagerEraseCredentials.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AuthenticationManagerRefKeepCredentials.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AuthenticationManagerRefKeepCredentials.xml new file mode 100644 index 0000000000..6d4dfd6fc5 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AuthenticationManagerRefKeepCredentials.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AuthenticationManagerRefNotProviderManager.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AuthenticationManagerRefNotProviderManager.xml new file mode 100644 index 0000000000..4471528406 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AuthenticationManagerRefNotProviderManager.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AutoConfig.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AutoConfig.xml new file mode 100644 index 0000000000..e83e4ad1aa --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-AutoConfig.xml @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CiRegexSecurityPattern.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CiRegexSecurityPattern.xml new file mode 100644 index 0000000000..02945561cf --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CiRegexSecurityPattern.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CollidingFilters.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CollidingFilters.xml new file mode 100644 index 0000000000..a3db56139d --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CollidingFilters.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomAccessDecisionManager.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomAccessDecisionManager.xml new file mode 100644 index 0000000000..bf8d9f683a --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomAccessDecisionManager.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomAuthenticationDetailsSourceRef.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomAuthenticationDetailsSourceRef.xml new file mode 100644 index 0000000000..3ffcf691ab --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomAuthenticationDetailsSourceRef.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomFilters.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomFilters.xml new file mode 100644 index 0000000000..42712c2af1 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomFilters.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomHttpBasicEntryPointRef.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomHttpBasicEntryPointRef.xml new file mode 100644 index 0000000000..148d64d38c --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomHttpBasicEntryPointRef.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomRequestMatcher.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomRequestMatcher.xml new file mode 100644 index 0000000000..4d4845b094 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-CustomRequestMatcher.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-DeleteCookies.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-DeleteCookies.xml new file mode 100644 index 0000000000..e09b8f34d3 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-DeleteCookies.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-DisableUrlRewriting.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-DisableUrlRewriting.xml new file mode 100644 index 0000000000..58672d9b88 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-DisableUrlRewriting.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-EntryPoint.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-EntryPoint.xml new file mode 100644 index 0000000000..9d0bf0af33 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-EntryPoint.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-ExpressionHandler.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-ExpressionHandler.xml new file mode 100644 index 0000000000..fe212c4ef7 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-ExpressionHandler.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-HttpBasic.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-HttpBasic.xml new file mode 100644 index 0000000000..bd3777800b --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-HttpBasic.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-HttpFirewall.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-HttpFirewall.xml new file mode 100644 index 0000000000..fd498026f2 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-HttpFirewall.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlExpressions.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlExpressions.xml new file mode 100644 index 0000000000..77555f755b --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlExpressions.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlMethod.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlMethod.xml new file mode 100644 index 0000000000..99436ccebf --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlMethod.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlMethodRequiresHttps.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlMethodRequiresHttps.xml new file mode 100644 index 0000000000..4fc2d84275 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlMethodRequiresHttps.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlMethodRequiresHttpsAny.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlMethodRequiresHttpsAny.xml new file mode 100644 index 0000000000..9c40b5b731 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InterceptUrlMethodRequiresHttpsAny.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InvalidLogoutSuccessUrl.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InvalidLogoutSuccessUrl.xml new file mode 100644 index 0000000000..c2d3fdbffb --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-InvalidLogoutSuccessUrl.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Jaas.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Jaas.xml new file mode 100644 index 0000000000..38f72babc4 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Jaas.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-JeeFilter.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-JeeFilter.xml new file mode 100644 index 0000000000..6d83eacb1d --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-JeeFilter.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-LogoutSuccessHandlerRef.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-LogoutSuccessHandlerRef.xml new file mode 100644 index 0000000000..488ce8ce94 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-LogoutSuccessHandlerRef.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-MinimalConfiguration.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-MinimalConfiguration.xml new file mode 100644 index 0000000000..1d7658b349 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-MinimalConfiguration.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-MissingUserDetailsService.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-MissingUserDetailsService.xml new file mode 100644 index 0000000000..13a14f280a --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-MissingUserDetailsService.xml @@ -0,0 +1,28 @@ + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-NoAuthProviders.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-NoAuthProviders.xml new file mode 100644 index 0000000000..a5845c6356 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-NoAuthProviders.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-NoInternalAuthenticationProviders.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-NoInternalAuthenticationProviders.xml new file mode 100644 index 0000000000..a5845c6356 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-NoInternalAuthenticationProviders.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-NoSecurityForPattern.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-NoSecurityForPattern.xml new file mode 100644 index 0000000000..110257c822 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-NoSecurityForPattern.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-OncePerRequest.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-OncePerRequest.xml new file mode 100644 index 0000000000..b59582d494 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-OncePerRequest.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-PortsMappedInterceptUrlMethodRequiresAny.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-PortsMappedInterceptUrlMethodRequiresAny.xml new file mode 100644 index 0000000000..eb663a1987 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-PortsMappedInterceptUrlMethodRequiresAny.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-PortsMappedRequiresHttps.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-PortsMappedRequiresHttps.xml new file mode 100644 index 0000000000..fc6211c4ed --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-PortsMappedRequiresHttps.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-ProtectedLoginPage.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-ProtectedLoginPage.xml new file mode 100644 index 0000000000..6d9006176b --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-ProtectedLoginPage.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-RegexSecurityPattern.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-RegexSecurityPattern.xml new file mode 100644 index 0000000000..7a2dfd7ad1 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-RegexSecurityPattern.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-RequestCache.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-RequestCache.xml new file mode 100644 index 0000000000..4e095d6705 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-RequestCache.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Sec750.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Sec750.xml new file mode 100644 index 0000000000..e2f825503e --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Sec750.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Sec934.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Sec934.xml new file mode 100644 index 0000000000..df5c4c4892 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Sec934.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-SecurityContextRepository.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-SecurityContextRepository.xml new file mode 100644 index 0000000000..d4f7cfc25a --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-SecurityContextRepository.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-X509.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-X509.xml new file mode 100644 index 0000000000..e433a39601 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-X509.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-certificate.pem b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-certificate.pem new file mode 100644 index 0000000000..a4d7eaa1ea --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-certificate.pem @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDfTCCAmWgAwIBAgIJAISE1BLq+ZUNMA0GCSqGSIb3DQEBCwUAMFUxCzAJBgNV +BAYTAlVTMQ0wCwYDVQQIDARVdGFoMRcwFQYDVQQHDA5TYWx0IExha2UgQ2l0eTEP +MA0GA1UECgwGU3ByaW5nMQ0wCwYDVQQLDAR1c2VyMB4XDTE4MTAwNjAwMjMyMVoX +DTQ2MDIyMTAwMjMyMVowVTELMAkGA1UEBhMCVVMxDTALBgNVBAgMBFV0YWgxFzAV +BgNVBAcMDlNhbHQgTGFrZSBDaXR5MQ8wDQYDVQQKDAZTcHJpbmcxDTALBgNVBAsM +BHVzZXIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC1pXMFNiDXHWkl +59GMRBW7RsOyqpMzU5PqgLc8josbty4wjvxlM9td00+s94fS/S9a6m/thJi8E4pb +MwQgckHhaUyiAYW1N3nv3Tj/3+/vhXGKoclTt2NNgTj8eFNx0x20+q0H8nyx0tJu +7I5rFLWXf3uaOg3DPWGxxLWwN8GNDKMeusjx7/mMpoYnxYRWhcekUHxrLY4gsE6E +rxJqa0DjmPAeaVMqBsXKBb0JKbyVI4P9t+tIGoNX0hWtudr/R14b+rnAugkfBOUH +3GgKXS5RjtwIJsRy7RhzoZBISuNQuZsS2N3kJp6lkmveN+trr6HX0COZA5JNs8FH +26+NVjYpAgMBAAGjUDBOMB0GA1UdDgQWBBSV8HXGF2favXivbmNoqPNDvMiwEDAf +BgNVHSMEGDAWgBSV8HXGF2favXivbmNoqPNDvMiwEDAMBgNVHRMEBTADAQH/MA0G +CSqGSIb3DQEBCwUAA4IBAQCMq2XZR2q7IcKyt6lRD+OabprBQapiwmVokovf9s23 +lVD2twEpSW27AIa3V2SpZau1lqy7Rk/KepBKfaXa2FJcxhqLtyaPwDxzYichrl4e +0zbrpE7sHnTxPtAaefpWZog6Q+HQ4KrJcBsCKwAaol+COzrLebWa9oIn6o1MYmRj +cNWM+uClUDmjoIRuwPCnEWHadxUcoKxnKiAmisOuer49DsN4dsskaT3Bc1MXrtqf +5+ZzdHjFKAtLMBPikdj6zG4B6r/1Ytdm/dQv56WWbs2L0iz0BRA5ul8bx94ZZeYb +oT/9kQxvDGRTykKR5MrQDZXW9Hsg/pQnp0f2aNNhMCw9 +-----END CERTIFICATE----- diff --git a/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-controllers.xml b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-controllers.xml new file mode 100644 index 0000000000..5b4ede5e8a --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-controllers.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/config/src/test/resources/org/springframework/security/config/http/jaas-login.conf b/config/src/test/resources/org/springframework/security/config/http/jaas-login.conf new file mode 100644 index 0000000000..a899f08ac3 --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/jaas-login.conf @@ -0,0 +1,3 @@ +JAASTest { + org.springframework.security.config.http.MiscHttpConfigTests$JaasLoginModule required; +}; diff --git a/config/src/test/resources/org/springframework/security/config/http/key.pem b/config/src/test/resources/org/springframework/security/config/http/key.pem new file mode 100644 index 0000000000..3f84c92a3e --- /dev/null +++ b/config/src/test/resources/org/springframework/security/config/http/key.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC1pXMFNiDXHWkl +59GMRBW7RsOyqpMzU5PqgLc8josbty4wjvxlM9td00+s94fS/S9a6m/thJi8E4pb +MwQgckHhaUyiAYW1N3nv3Tj/3+/vhXGKoclTt2NNgTj8eFNx0x20+q0H8nyx0tJu +7I5rFLWXf3uaOg3DPWGxxLWwN8GNDKMeusjx7/mMpoYnxYRWhcekUHxrLY4gsE6E +rxJqa0DjmPAeaVMqBsXKBb0JKbyVI4P9t+tIGoNX0hWtudr/R14b+rnAugkfBOUH +3GgKXS5RjtwIJsRy7RhzoZBISuNQuZsS2N3kJp6lkmveN+trr6HX0COZA5JNs8FH +26+NVjYpAgMBAAECggEAdj9RRBg7gq3jsEhb0krUNsjXRqziDGyhAuxt3F8S0aUK +zZOXXK5IZKjV2kx9P+2P8UhiOqWx4+V4kOwCCLk4h+vLdj81coW9vFcv7uoxwKQH +CO9PJ09ftqmjlj8iWxvK3/C7yUuivwP19z3JbI3btNbJeNnH8cw4l8ftWtzBA/cW +3F87sjM3J59KFMjaNwDmgpCx6xVfk1E+R1e2tcgbjGdy5h14BUkS5kMHSgk13bj4 +1Pg9QZBeV7L3oui/PPz/wt7MDY7qerI8+gJ1vR3wqbX30F+o+K1rJ4ZEYM3OaxnF +cpdvfUGNXApZD3mdSZenDahtGhlVcLUID9IHaKjGTQKBgQDuiwlKLxPBWDpFzXU5 +WaLRInyULq0E9jj4CcMX509vl6fbRf8vsULDzg9nD3bjWF8dakJBl811iSvHsOQv +7SaIS6aTW4cyhEpSGqWyJrv6C5EnWxrgbtED85OVcFi2HIoPpQgke+ORNur4ceZp +33BXI2wqYF2FM/4n4MakLnu8JwKBgQDC8HwYnifV/syxhaZXHyq1P61F4C6yYqHP +19PsE/NAiYHMz9HVKRWQznX1HuSQPdMCNKtGrmzSO9PAIt0VgOiKNUQa5Wx9s/4f +qs8z/6FKHgw96u7T/6erzCyz/TCqJCIZpqiurJh1yibXWcv3S3KxwXHcMxuIM2UO +QfHItOfdLwKBgHPIZI/vXcVgz5gF67oUeeTMum8qYKyh3nD2PA2kJnhhwgW6aex6 +O4/SusMpTGl5AWHDq7kut3kvRWK9x2RD1YoePhIUQQESGQjVCkv4ZREvABt8KwV4 +hFdIqP/F8ikinRiO3+7le0WGxHImxtHotBx3gw7miz4WSGyOu5wBO+nNAoGAdA8N +MvLmMKe0YnR5piDuIl644IMqChZi1AVhLIpsJp43YyLPgKMnLcFdxQQRfDbyq7uD +xV8PdtMbrKaVDbpjt/UiiQjSYLyKrXvaRNEKy7+79hkq+5iX0NaMPtSc5o8Apljs +0KH9WxNxsIDLyH1o2Z+cFEdxOtOudKCaPK5H5Q0CgYBsCK4rCO3pXU+bWiwn401E +i5SaYHGH33eBYgle+CAyzj0dNKogow+5Yfo6AkiXyng/PKY95DRXsSH3z6hGzU65 +NjbuNK2YdfCem2sdY3PRLJdIu7JK6fW3q3nQLZ6G4QUXH+9mmRDsrh9fNCNfOStl +V6tGbgS0ay+H6oMRfUQfNw== +-----END PRIVATE KEY-----