1
0
mirror of synced 2026-05-22 21:33:16 +00:00

Remove PortResolver

Closes gh-15971

Signed-off-by: DingHao <dh.hiekn@gmail.com>
This commit is contained in:
DingHao
2025-07-14 20:31:01 +08:00
committed by Rob Winch
parent f0f272d17b
commit 10935632ee
32 changed files with 69 additions and 625 deletions
@@ -29,7 +29,6 @@ import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.PortMapper;
import org.springframework.security.web.PortResolver;
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
@@ -274,10 +273,6 @@ public abstract class AbstractAuthenticationFilterConfigurer<B extends HttpSecur
if (portMapper != null) {
this.authenticationEntryPoint.setPortMapper(portMapper);
}
PortResolver portResolver = getBeanOrNull(http, PortResolver.class);
if (portResolver != null) {
this.authenticationEntryPoint.setPortResolver(portResolver);
}
RequestCache requestCache = http.getSharedObject(RequestCache.class);
if (requestCache != null) {
this.defaultSuccessHandler.setRequestCache(requestCache);
@@ -83,7 +83,6 @@ import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.security.oauth2.jwt.JwtDecoderFactory;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.PortResolver;
import org.springframework.security.web.RedirectStrategy;
import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
@@ -556,10 +555,6 @@ public final class OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>>
RequestMatcher formLoginNotEnabled = getFormLoginNotEnabledRequestMatcher(http);
LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPoints = new LinkedHashMap<>();
LoginUrlAuthenticationEntryPoint loginUrlEntryPoint = new LoginUrlAuthenticationEntryPoint(providerLoginPage);
PortResolver portResolver = getBeanOrNull(ResolvableType.forClass(PortResolver.class));
if (portResolver != null) {
loginUrlEntryPoint.setPortResolver(portResolver);
}
entryPoints.put(new AndRequestMatcher(notXRequestedWith, new NegatedRequestMatcher(defaultLoginPageMatcher),
formLoginNotEnabled), loginUrlEntryPoint);
DelegatingAuthenticationEntryPoint loginEntryPoint = new DelegatingAuthenticationEntryPoint(entryPoints);
@@ -48,7 +48,6 @@ import org.springframework.security.saml2.provider.service.web.authentication.Op
import org.springframework.security.saml2.provider.service.web.authentication.Saml2AuthenticationRequestResolver;
import org.springframework.security.saml2.provider.service.web.authentication.Saml2WebSsoAuthenticationFilter;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.PortResolver;
import org.springframework.security.web.authentication.AuthenticationConverter;
import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
@@ -342,10 +341,6 @@ public final class Saml2LoginConfigurer<B extends HttpSecurityBuilder<B>>
new RequestHeaderRequestMatcher("X-Requested-With", "XMLHttpRequest"));
LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPoints = new LinkedHashMap<>();
LoginUrlAuthenticationEntryPoint loginUrlEntryPoint = new LoginUrlAuthenticationEntryPoint(providerLoginPage);
PortResolver portResolver = getBeanOrNull(http, PortResolver.class);
if (portResolver != null) {
loginUrlEntryPoint.setPortResolver(portResolver);
}
entryPoints.put(new AndRequestMatcher(notXRequestedWith, new NegatedRequestMatcher(defaultLoginPageMatcher)),
loginUrlEntryPoint);
DelegatingAuthenticationEntryPoint loginEntryPoint = new DelegatingAuthenticationEntryPoint(entryPoints);
@@ -164,8 +164,6 @@ final class AuthenticationConfigBuilder {
private final BeanReference portMapper;
private final BeanReference portResolver;
private final BeanMetadataElement csrfLogoutHandler;
private String loginProcessingUrl;
@@ -227,7 +225,7 @@ final class AuthenticationConfigBuilder {
SessionCreationPolicy sessionPolicy, BeanReference requestCache, BeanReference authenticationManager,
BeanMetadataElement authenticationFilterSecurityContextHolderStrategyRef,
BeanReference authenticationFilterSecurityContextRepositoryRef, BeanReference sessionStrategy,
BeanReference portMapper, BeanReference portResolver, BeanMetadataElement csrfLogoutHandler) {
BeanReference portMapper, BeanMetadataElement csrfLogoutHandler) {
this.httpElt = element;
this.pc = pc;
this.requestCache = requestCache;
@@ -235,7 +233,6 @@ final class AuthenticationConfigBuilder {
this.allowSessionCreation = sessionPolicy != SessionCreationPolicy.NEVER
&& sessionPolicy != SessionCreationPolicy.STATELESS;
this.portMapper = portMapper;
this.portResolver = portResolver;
this.csrfLogoutHandler = csrfLogoutHandler;
createAnonymousFilter(authenticationFilterSecurityContextHolderStrategyRef);
createRememberMeFilter(authenticationManager, authenticationFilterSecurityContextHolderStrategyRef);
@@ -291,7 +288,7 @@ final class AuthenticationConfigBuilder {
if (formLoginElt != null || this.autoConfig) {
FormLoginBeanDefinitionParser parser = new FormLoginBeanDefinitionParser("/login", "POST",
AUTHENTICATION_PROCESSING_FILTER_CLASS, this.requestCache, sessionStrategy,
this.allowSessionCreation, this.portMapper, this.portResolver);
this.allowSessionCreation, this.portMapper);
parser.parse(formLoginElt, this.pc);
formFilter = parser.getFilterBean();
this.formEntryPoint = parser.getEntryPointBean();
@@ -334,8 +331,7 @@ final class AuthenticationConfigBuilder {
}
this.oauth2LoginEnabled = true;
OAuth2LoginBeanDefinitionParser parser = new OAuth2LoginBeanDefinitionParser(this.requestCache, this.portMapper,
this.portResolver, sessionStrategy, this.allowSessionCreation,
authenticationFilterSecurityContextHolderStrategy);
sessionStrategy, this.allowSessionCreation, authenticationFilterSecurityContextHolderStrategy);
BeanDefinition oauth2LoginFilterBean = parser.parse(oauth2LoginElt, this.pc);
BeanDefinition defaultAuthorizedClientRepository = parser.getDefaultAuthorizedClientRepository();
registerDefaultAuthorizedClientRepositoryIfNecessary(defaultAuthorizedClientRepository);
@@ -437,7 +433,7 @@ final class AuthenticationConfigBuilder {
return;
}
Saml2LoginBeanDefinitionParser parser = new Saml2LoginBeanDefinitionParser(this.csrfIgnoreRequestMatchers,
this.portMapper, this.portResolver, this.requestCache, this.allowSessionCreation, authenticationManager,
this.portMapper, this.requestCache, this.allowSessionCreation, authenticationManager,
authenticationFilterSecurityContextRepositoryRef, this.authenticationProviders,
this.defaultEntryPointMappings);
BeanDefinition saml2WebSsoAuthenticationFilter = parser.parse(saml2LoginElt, this.pc);
@@ -85,8 +85,6 @@ public class FormLoginBeanDefinitionParser {
private final BeanReference portMapper;
private final BeanReference portResolver;
private RootBeanDefinition filterBean;
private RootBeanDefinition entryPointBean;
@@ -99,7 +97,7 @@ public class FormLoginBeanDefinitionParser {
FormLoginBeanDefinitionParser(String defaultLoginProcessingUrl, String loginMethod, String filterClassName,
BeanReference requestCache, BeanReference sessionStrategy, boolean allowSessionCreation,
BeanReference portMapper, BeanReference portResolver) {
BeanReference portMapper) {
this.defaultLoginProcessingUrl = defaultLoginProcessingUrl;
this.loginMethod = loginMethod;
this.filterClassName = filterClassName;
@@ -107,7 +105,6 @@ public class FormLoginBeanDefinitionParser {
this.sessionStrategy = sessionStrategy;
this.allowSessionCreation = allowSessionCreation;
this.portMapper = portMapper;
this.portResolver = portResolver;
}
public BeanDefinition parse(Element elt, ParserContext pc) {
@@ -163,7 +160,6 @@ public class FormLoginBeanDefinitionParser {
entryPointBuilder.getRawBeanDefinition().setSource(source);
entryPointBuilder.addConstructorArgValue((this.loginPage != null) ? this.loginPage : DEF_LOGIN_PAGE);
entryPointBuilder.addPropertyValue("portMapper", this.portMapper);
entryPointBuilder.addPropertyValue("portResolver", this.portResolver);
this.entryPointBean = (RootBeanDefinition) entryPointBuilder.getBeanDefinition();
return null;
}
@@ -201,8 +201,6 @@ class HttpConfigurationBuilder {
private final BeanReference portMapper;
private final BeanReference portResolver;
private BeanReference fsi;
private BeanReference requestCache;
@@ -228,12 +226,11 @@ class HttpConfigurationBuilder {
private boolean addAllAuth;
HttpConfigurationBuilder(Element element, boolean addAllAuth, ParserContext pc, BeanReference portMapper,
BeanReference portResolver, BeanReference authenticationManager, BeanMetadataElement observationRegistry) {
BeanReference authenticationManager, BeanMetadataElement observationRegistry) {
this.httpElt = element;
this.addAllAuth = addAllAuth;
this.pc = pc;
this.portMapper = portMapper;
this.portResolver = portResolver;
this.matcherType = MatcherType.fromElementOrMvc(element);
this.interceptUrls = DomUtils.getChildElementsByTagName(element, Elements.INTERCEPT_URL);
validateInterceptUrls(pc);
@@ -693,9 +690,7 @@ class HttpConfigurationBuilder {
RootBeanDefinition retryWithHttp = new RootBeanDefinition(RetryWithHttpEntryPoint.class);
RootBeanDefinition retryWithHttps = new RootBeanDefinition(RetryWithHttpsEntryPoint.class);
retryWithHttp.getPropertyValues().addPropertyValue("portMapper", this.portMapper);
retryWithHttp.getPropertyValues().addPropertyValue("portResolver", this.portResolver);
retryWithHttps.getPropertyValues().addPropertyValue("portMapper", this.portMapper);
retryWithHttps.getPropertyValues().addPropertyValue("portResolver", this.portResolver);
secureChannelProcessor.getPropertyValues().addPropertyValue("entryPoint", retryWithHttps);
RootBeanDefinition inSecureChannelProcessor = new RootBeanDefinition(InsecureChannelProcessor.class);
inSecureChannelProcessor.getPropertyValues().addPropertyValue("entryPoint", retryWithHttp);
@@ -751,7 +746,6 @@ class HttpConfigurationBuilder {
requestCacheBldr = BeanDefinitionBuilder.rootBeanDefinition(HttpSessionRequestCache.class);
requestCacheBldr.addPropertyValue("createSessionAllowed",
this.sessionPolicy == SessionCreationPolicy.IF_REQUIRED);
requestCacheBldr.addPropertyValue("portResolver", this.portResolver);
if (this.csrfFilter != null) {
BeanDefinitionBuilder requestCacheMatcherBldr = BeanDefinitionBuilder
.rootBeanDefinition(RequestMatcherFactoryBean.class);
@@ -57,7 +57,6 @@ import org.springframework.security.config.authentication.AuthenticationManagerF
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.FilterChainProxy;
import org.springframework.security.web.ObservationFilterChainDecorator;
import org.springframework.security.web.PortResolverImpl;
import org.springframework.security.web.firewall.ObservationMarkingRequestRejectedHandler;
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
import org.springframework.util.StringUtils;
@@ -151,19 +150,18 @@ public class HttpSecurityBeanDefinitionParser implements BeanDefinitionParser {
return createSecurityFilterChainBean(element, pc, Collections.emptyList());
}
BeanReference portMapper = createPortMapper(element, pc);
BeanReference portResolver = createPortResolver(portMapper, pc);
ManagedList<BeanReference> authenticationProviders = new ManagedList<>();
BeanReference authenticationManager = createAuthenticationManager(element, pc, authenticationProviders);
boolean forceAutoConfig = isDefaultHttpConfig(element);
BeanMetadataElement observationRegistry = getObservationRegistry(element);
HttpConfigurationBuilder httpBldr = new HttpConfigurationBuilder(element, forceAutoConfig, pc, portMapper,
portResolver, authenticationManager, observationRegistry);
authenticationManager, observationRegistry);
httpBldr.getSecurityContextRepositoryForAuthenticationFilters();
AuthenticationConfigBuilder authBldr = new AuthenticationConfigBuilder(element, forceAutoConfig, pc,
httpBldr.getSessionCreationPolicy(), httpBldr.getRequestCache(), authenticationManager,
httpBldr.getSecurityContextHolderStrategyForAuthenticationFilters(),
httpBldr.getSecurityContextRepositoryForAuthenticationFilters(), httpBldr.getSessionStrategy(),
portMapper, portResolver, httpBldr.getCsrfLogoutHandler());
portMapper, httpBldr.getCsrfLogoutHandler());
httpBldr.setLogoutHandlers(authBldr.getLogoutHandlers());
httpBldr.setEntryPoint(authBldr.getEntryPointBean());
httpBldr.setAccessDeniedHandler(authBldr.getAccessDeniedHandlerBean());
@@ -241,18 +239,6 @@ public class HttpSecurityBeanDefinitionParser implements BeanDefinitionParser {
return new RuntimeBeanReference(portMapperName);
}
private RuntimeBeanReference createPortResolver(BeanReference portMapper, ParserContext pc) {
String beanName = "portResolver";
if (pc.getRegistry().containsBeanDefinition(beanName)) {
return new RuntimeBeanReference(beanName);
}
RootBeanDefinition portResolver = new RootBeanDefinition(PortResolverImpl.class);
portResolver.getPropertyValues().addPropertyValue("portMapper", portMapper);
String portResolverName = pc.getReaderContext().generateBeanName(portResolver);
pc.registerBeanComponent(new BeanComponentDefinition(portResolver, portResolverName));
return new RuntimeBeanReference(portResolverName);
}
/**
* Creates the internal AuthenticationManager bean which uses either the externally
* registered (global) one as a parent or the bean specified by
@@ -111,8 +111,6 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser {
private final BeanReference portMapper;
private final BeanReference portResolver;
private final BeanReference sessionStrategy;
private final boolean allowSessionCreation;
@@ -131,12 +129,10 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser {
private BeanDefinition oauth2LoginLinks;
OAuth2LoginBeanDefinitionParser(BeanReference requestCache, BeanReference portMapper, BeanReference portResolver,
BeanReference sessionStrategy, boolean allowSessionCreation,
BeanMetadataElement authenticationFilterSecurityContextHolderStrategy) {
OAuth2LoginBeanDefinitionParser(BeanReference requestCache, BeanReference portMapper, BeanReference sessionStrategy,
boolean allowSessionCreation, BeanMetadataElement authenticationFilterSecurityContextHolderStrategy) {
this.requestCache = requestCache;
this.portMapper = portMapper;
this.portResolver = portResolver;
this.sessionStrategy = sessionStrategy;
this.allowSessionCreation = allowSessionCreation;
this.authenticationFilterSecurityContextHolderStrategy = authenticationFilterSecurityContextHolderStrategy;
@@ -231,7 +227,6 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser {
.rootBeanDefinition(LoginUrlAuthenticationEntryPoint.class)
.addConstructorArgValue(loginPage)
.addPropertyValue("portMapper", this.portMapper)
.addPropertyValue("portResolver", this.portResolver)
.getBeanDefinition();
}
else {
@@ -76,8 +76,6 @@ final class Saml2LoginBeanDefinitionParser implements BeanDefinitionParser {
private final BeanReference portMapper;
private final BeanReference portResolver;
private final BeanReference requestCache;
private final boolean allowSessionCreation;
@@ -97,12 +95,11 @@ final class Saml2LoginBeanDefinitionParser implements BeanDefinitionParser {
private BeanDefinition saml2AuthenticationUrlToProviderName;
Saml2LoginBeanDefinitionParser(List<BeanDefinition> csrfIgnoreRequestMatchers, BeanReference portMapper,
BeanReference portResolver, BeanReference requestCache, boolean allowSessionCreation,
BeanReference authenticationManager, BeanReference authenticationFilterSecurityContextRepositoryRef,
List<BeanReference> authenticationProviders, Map<BeanDefinition, BeanMetadataElement> entryPoints) {
BeanReference requestCache, boolean allowSessionCreation, BeanReference authenticationManager,
BeanReference authenticationFilterSecurityContextRepositoryRef, List<BeanReference> authenticationProviders,
Map<BeanDefinition, BeanMetadataElement> entryPoints) {
this.csrfIgnoreRequestMatchers = csrfIgnoreRequestMatchers;
this.portMapper = portMapper;
this.portResolver = portResolver;
this.requestCache = requestCache;
this.allowSessionCreation = allowSessionCreation;
this.authenticationManager = authenticationManager;
@@ -198,7 +195,6 @@ final class Saml2LoginBeanDefinitionParser implements BeanDefinitionParser {
.rootBeanDefinition(LoginUrlAuthenticationEntryPoint.class)
.addConstructorArgValue(loginPage)
.addPropertyValue("portMapper", this.portMapper)
.addPropertyValue("portResolver", this.portResolver)
.getBeanDefinition();
}
else {
@@ -209,7 +205,6 @@ final class Saml2LoginBeanDefinitionParser implements BeanDefinitionParser {
.rootBeanDefinition(LoginUrlAuthenticationEntryPoint.class)
.addConstructorArgValue(loginUrl)
.addPropertyValue("portMapper", this.portMapper)
.addPropertyValue("portResolver", this.portResolver)
.getBeanDefinition();
}
}
@@ -189,7 +189,6 @@ import org.springframework.security.saml2.provider.service.authentication.logout
import org.springframework.security.saml2.provider.service.registration.OpenSamlAssertingPartyDetails;
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
import org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations;
import org.springframework.security.web.PortResolverImpl;
import org.springframework.security.web.authentication.AuthenticationFilter;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
@@ -605,7 +604,7 @@ final class SerializationSamples {
request.addParameter("parameter", "value");
request.setPathInfo("/path");
request.addPreferredLocale(Locale.ENGLISH);
return new SimpleSavedRequest(new DefaultSavedRequest(request, new PortResolverImpl(), "continue"));
return new SimpleSavedRequest(new DefaultSavedRequest(request, "continue"));
});
generatorByClassName.put(HttpSessionIdChangedEvent.class,
@@ -38,7 +38,6 @@ import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders;
import org.springframework.security.web.PortMapper;
import org.springframework.security.web.PortResolver;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.access.ExceptionTranslationFilter;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
@@ -379,13 +378,6 @@ public class FormLoginConfigurerTests {
verify(ObjectPostProcessorConfig.objectPostProcessor).postProcess(any(ExceptionTranslationFilter.class));
}
@Test
public void configureWhenPortResolverBeanThenPortResolverUsed() throws Exception {
this.spring.register(CustomPortResolverConfig.class).autowire();
this.mockMvc.perform(get("/requires-authentication")).andExpect(status().is3xxRedirection());
verify(this.spring.getContext().getBean(PortResolver.class)).getServerPort(any());
}
@Configuration
@EnableWebSecurity
static class RequestCacheConfig {
@@ -713,35 +705,6 @@ public class FormLoginConfigurerTests {
}
@Configuration
@EnableWebSecurity
static class CustomPortResolverConfig {
@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeHttpRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.formLogin(withDefaults())
.requestCache(withDefaults());
return http.build();
// @formatter:on
}
@Bean
PortResolver portResolver() {
return mock(PortResolver.class);
}
@Bean
UserDetailsService userDetailsService() {
return new InMemoryUserDetailsManager(PasswordEncodedUser.user());
}
}
static class ReflectingObjectPostProcessor implements ObjectPostProcessor<Object> {
@Override
@@ -35,7 +35,6 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolderStrategy;
import org.springframework.security.web.FilterChainProxy;
import org.springframework.security.web.PortResolver;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter;
@@ -46,7 +45,6 @@ import org.springframework.web.bind.annotation.RestController;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.verify;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
@@ -212,17 +210,6 @@ public class FormLoginConfigTests {
// @formatter:on
}
@Test
public void portResolver() throws Exception {
this.spring.configLocations(this.xml("PortResolverBean")).autowire();
// @formatter:off
this.mvc.perform(get("/requires-authentication"))
.andExpect(status().is3xxRedirection());
// @formatter:on
PortResolver portResolver = this.spring.getContext().getBean(PortResolver.class);
verify(portResolver, atLeastOnce()).getServerPort(any());
}
private Filter getFilter(ApplicationContext context, Class<? extends Filter> filterClass) {
FilterChainProxy filterChain = context.getBean(BeanIds.FILTER_CHAIN_PROXY, FilterChainProxy.class);
List<Filter> filters = filterChain.getFilters("/any");
@@ -35,7 +35,6 @@ import org.springframework.security.core.userdetails.User
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf
import org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.authenticated
import org.springframework.security.web.PortResolver
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler
@@ -242,29 +241,6 @@ class FormLoginDslTests {
}
}
@Test
fun `portResolerBean is used`() {
this.spring.register(PortResolverBeanConfig::class.java, AllSecuredConfig::class.java, UserConfig::class.java).autowire()
val portResolver = this.spring.context.getBean(PortResolver::class.java)
every { portResolver.getServerPort(any()) }.returns(1234)
this.mockMvc.get("/")
.andExpect {
status().isFound
redirectedUrl("http://localhost:1234/login")
}
verify { portResolver.getServerPort(any()) }
}
@Configuration
open class PortResolverBeanConfig {
@Bean
open fun portResolverBean(): PortResolver {
return mockk()
}
}
@Test
fun `login when custom failure url then used`() {
this.spring.register(FailureHandlerConfig::class.java, UserConfig::class.java).autowire()
@@ -1,37 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2004-present 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
~
~ https://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.
-->
<b:beans xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/security
https://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<b:bean id="portResolver" class="org.mockito.Mockito" factory-method="mock" scope="singleton">
<b:constructor-arg value="org.springframework.security.web.PortResolver" type="java.lang.Class"/>
</b:bean>
<http auto-config="true">
<csrf disabled="true"/>
<intercept-url pattern="/**" access="authenticated"/>
</http>
<b:import resource="userservice.xml"/>
</b:beans>