Skip to content

Commit ecb59f6

Browse files
committed
Remove PortResolver
Closes gh-15971 Signed-off-by: DingHao <[email protected]>
1 parent f61a8de commit ecb59f6

File tree

32 files changed

+70
-624
lines changed

32 files changed

+70
-624
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/configurers/AbstractAuthenticationFilterConfigurer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
3030
import org.springframework.security.web.AuthenticationEntryPoint;
3131
import org.springframework.security.web.PortMapper;
32-
import org.springframework.security.web.PortResolver;
3332
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
3433
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
3534
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
@@ -274,10 +273,6 @@ public void configure(B http) throws Exception {
274273
if (portMapper != null) {
275274
this.authenticationEntryPoint.setPortMapper(portMapper);
276275
}
277-
PortResolver portResolver = getBeanOrNull(http, PortResolver.class);
278-
if (portResolver != null) {
279-
this.authenticationEntryPoint.setPortResolver(portResolver);
280-
}
281276
RequestCache requestCache = http.getSharedObject(RequestCache.class);
282277
if (requestCache != null) {
283278
this.defaultSuccessHandler.setRequestCache(requestCache);

config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
import org.springframework.security.oauth2.core.user.OAuth2User;
8484
import org.springframework.security.oauth2.jwt.JwtDecoderFactory;
8585
import org.springframework.security.web.AuthenticationEntryPoint;
86-
import org.springframework.security.web.PortResolver;
8786
import org.springframework.security.web.RedirectStrategy;
8887
import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint;
8988
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
@@ -556,10 +555,6 @@ private AuthenticationEntryPoint getLoginEntryPoint(B http, String providerLogin
556555
RequestMatcher formLoginNotEnabled = getFormLoginNotEnabledRequestMatcher(http);
557556
LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPoints = new LinkedHashMap<>();
558557
LoginUrlAuthenticationEntryPoint loginUrlEntryPoint = new LoginUrlAuthenticationEntryPoint(providerLoginPage);
559-
PortResolver portResolver = getBeanOrNull(ResolvableType.forClass(PortResolver.class));
560-
if (portResolver != null) {
561-
loginUrlEntryPoint.setPortResolver(portResolver);
562-
}
563558
entryPoints.put(new AndRequestMatcher(notXRequestedWith, new NegatedRequestMatcher(defaultLoginPageMatcher),
564559
formLoginNotEnabled), loginUrlEntryPoint);
565560
DelegatingAuthenticationEntryPoint loginEntryPoint = new DelegatingAuthenticationEntryPoint(entryPoints);

config/src/main/java/org/springframework/security/config/annotation/web/configurers/saml2/Saml2LoginConfigurer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import org.springframework.security.saml2.provider.service.web.authentication.Saml2AuthenticationRequestResolver;
5252
import org.springframework.security.saml2.provider.service.web.authentication.Saml2WebSsoAuthenticationFilter;
5353
import org.springframework.security.web.AuthenticationEntryPoint;
54-
import org.springframework.security.web.PortResolver;
5554
import org.springframework.security.web.authentication.AuthenticationConverter;
5655
import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint;
5756
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
@@ -345,10 +344,6 @@ private AuthenticationEntryPoint getLoginEntryPoint(B http, String providerLogin
345344
new RequestHeaderRequestMatcher("X-Requested-With", "XMLHttpRequest"));
346345
LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPoints = new LinkedHashMap<>();
347346
LoginUrlAuthenticationEntryPoint loginUrlEntryPoint = new LoginUrlAuthenticationEntryPoint(providerLoginPage);
348-
PortResolver portResolver = getBeanOrNull(http, PortResolver.class);
349-
if (portResolver != null) {
350-
loginUrlEntryPoint.setPortResolver(portResolver);
351-
}
352347
entryPoints.put(new AndRequestMatcher(notXRequestedWith, new NegatedRequestMatcher(defaultLoginPageMatcher)),
353348
loginUrlEntryPoint);
354349
DelegatingAuthenticationEntryPoint loginEntryPoint = new DelegatingAuthenticationEntryPoint(entryPoints);

config/src/main/java/org/springframework/security/config/http/AuthenticationConfigBuilder.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ final class AuthenticationConfigBuilder {
164164

165165
private final BeanReference portMapper;
166166

167-
private final BeanReference portResolver;
168-
169167
private final BeanMetadataElement csrfLogoutHandler;
170168

171169
private String loginProcessingUrl;
@@ -227,15 +225,14 @@ final class AuthenticationConfigBuilder {
227225
SessionCreationPolicy sessionPolicy, BeanReference requestCache, BeanReference authenticationManager,
228226
BeanMetadataElement authenticationFilterSecurityContextHolderStrategyRef,
229227
BeanReference authenticationFilterSecurityContextRepositoryRef, BeanReference sessionStrategy,
230-
BeanReference portMapper, BeanReference portResolver, BeanMetadataElement csrfLogoutHandler) {
228+
BeanReference portMapper, BeanMetadataElement csrfLogoutHandler) {
231229
this.httpElt = element;
232230
this.pc = pc;
233231
this.requestCache = requestCache;
234232
this.autoConfig = forceAutoConfig | "true".equals(element.getAttribute(ATT_AUTO_CONFIG));
235233
this.allowSessionCreation = sessionPolicy != SessionCreationPolicy.NEVER
236234
&& sessionPolicy != SessionCreationPolicy.STATELESS;
237235
this.portMapper = portMapper;
238-
this.portResolver = portResolver;
239236
this.csrfLogoutHandler = csrfLogoutHandler;
240237
createAnonymousFilter(authenticationFilterSecurityContextHolderStrategyRef);
241238
createRememberMeFilter(authenticationManager, authenticationFilterSecurityContextHolderStrategyRef);
@@ -291,7 +288,7 @@ void createFormLoginFilter(BeanReference sessionStrategy, BeanReference authMana
291288
if (formLoginElt != null || this.autoConfig) {
292289
FormLoginBeanDefinitionParser parser = new FormLoginBeanDefinitionParser("/login", "POST",
293290
AUTHENTICATION_PROCESSING_FILTER_CLASS, this.requestCache, sessionStrategy,
294-
this.allowSessionCreation, this.portMapper, this.portResolver);
291+
this.allowSessionCreation, this.portMapper);
295292
parser.parse(formLoginElt, this.pc);
296293
formFilter = parser.getFilterBean();
297294
this.formEntryPoint = parser.getEntryPointBean();
@@ -334,8 +331,7 @@ void createOAuth2LoginFilter(BeanReference sessionStrategy, BeanReference authMa
334331
}
335332
this.oauth2LoginEnabled = true;
336333
OAuth2LoginBeanDefinitionParser parser = new OAuth2LoginBeanDefinitionParser(this.requestCache, this.portMapper,
337-
this.portResolver, sessionStrategy, this.allowSessionCreation,
338-
authenticationFilterSecurityContextHolderStrategy);
334+
sessionStrategy, this.allowSessionCreation, authenticationFilterSecurityContextHolderStrategy);
339335
BeanDefinition oauth2LoginFilterBean = parser.parse(oauth2LoginElt, this.pc);
340336
BeanDefinition defaultAuthorizedClientRepository = parser.getDefaultAuthorizedClientRepository();
341337
registerDefaultAuthorizedClientRepositoryIfNecessary(defaultAuthorizedClientRepository);
@@ -437,7 +433,7 @@ private void createSaml2LoginFilter(BeanReference authenticationManager,
437433
return;
438434
}
439435
Saml2LoginBeanDefinitionParser parser = new Saml2LoginBeanDefinitionParser(this.csrfIgnoreRequestMatchers,
440-
this.portMapper, this.portResolver, this.requestCache, this.allowSessionCreation, authenticationManager,
436+
this.portMapper, this.requestCache, this.allowSessionCreation, authenticationManager,
441437
authenticationFilterSecurityContextRepositoryRef, this.authenticationProviders,
442438
this.defaultEntryPointMappings);
443439
BeanDefinition saml2WebSsoAuthenticationFilter = parser.parse(saml2LoginElt, this.pc);

config/src/main/java/org/springframework/security/config/http/FormLoginBeanDefinitionParser.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ public class FormLoginBeanDefinitionParser {
8585

8686
private final BeanReference portMapper;
8787

88-
private final BeanReference portResolver;
89-
9088
private RootBeanDefinition filterBean;
9189

9290
private RootBeanDefinition entryPointBean;
@@ -99,15 +97,14 @@ public class FormLoginBeanDefinitionParser {
9997

10098
FormLoginBeanDefinitionParser(String defaultLoginProcessingUrl, String loginMethod, String filterClassName,
10199
BeanReference requestCache, BeanReference sessionStrategy, boolean allowSessionCreation,
102-
BeanReference portMapper, BeanReference portResolver) {
100+
BeanReference portMapper) {
103101
this.defaultLoginProcessingUrl = defaultLoginProcessingUrl;
104102
this.loginMethod = loginMethod;
105103
this.filterClassName = filterClassName;
106104
this.requestCache = requestCache;
107105
this.sessionStrategy = sessionStrategy;
108106
this.allowSessionCreation = allowSessionCreation;
109107
this.portMapper = portMapper;
110-
this.portResolver = portResolver;
111108
}
112109

113110
public BeanDefinition parse(Element elt, ParserContext pc) {
@@ -163,7 +160,6 @@ public BeanDefinition parse(Element elt, ParserContext pc) {
163160
entryPointBuilder.getRawBeanDefinition().setSource(source);
164161
entryPointBuilder.addConstructorArgValue((this.loginPage != null) ? this.loginPage : DEF_LOGIN_PAGE);
165162
entryPointBuilder.addPropertyValue("portMapper", this.portMapper);
166-
entryPointBuilder.addPropertyValue("portResolver", this.portResolver);
167163
this.entryPointBean = (RootBeanDefinition) entryPointBuilder.getBeanDefinition();
168164
return null;
169165
}

config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ class HttpConfigurationBuilder {
201201

202202
private final BeanReference portMapper;
203203

204-
private final BeanReference portResolver;
205-
206204
private BeanReference fsi;
207205

208206
private BeanReference requestCache;
@@ -228,12 +226,11 @@ class HttpConfigurationBuilder {
228226
private boolean addAllAuth;
229227

230228
HttpConfigurationBuilder(Element element, boolean addAllAuth, ParserContext pc, BeanReference portMapper,
231-
BeanReference portResolver, BeanReference authenticationManager, BeanMetadataElement observationRegistry) {
229+
BeanReference authenticationManager, BeanMetadataElement observationRegistry) {
232230
this.httpElt = element;
233231
this.addAllAuth = addAllAuth;
234232
this.pc = pc;
235233
this.portMapper = portMapper;
236-
this.portResolver = portResolver;
237234
this.matcherType = MatcherType.fromElementOrMvc(element);
238235
this.interceptUrls = DomUtils.getChildElementsByTagName(element, Elements.INTERCEPT_URL);
239236
validateInterceptUrls(pc);
@@ -693,9 +690,7 @@ private void createChannelProcessingFilter() {
693690
RootBeanDefinition retryWithHttp = new RootBeanDefinition(RetryWithHttpEntryPoint.class);
694691
RootBeanDefinition retryWithHttps = new RootBeanDefinition(RetryWithHttpsEntryPoint.class);
695692
retryWithHttp.getPropertyValues().addPropertyValue("portMapper", this.portMapper);
696-
retryWithHttp.getPropertyValues().addPropertyValue("portResolver", this.portResolver);
697693
retryWithHttps.getPropertyValues().addPropertyValue("portMapper", this.portMapper);
698-
retryWithHttps.getPropertyValues().addPropertyValue("portResolver", this.portResolver);
699694
secureChannelProcessor.getPropertyValues().addPropertyValue("entryPoint", retryWithHttps);
700695
RootBeanDefinition inSecureChannelProcessor = new RootBeanDefinition(InsecureChannelProcessor.class);
701696
inSecureChannelProcessor.getPropertyValues().addPropertyValue("entryPoint", retryWithHttp);
@@ -751,7 +746,6 @@ private void createRequestCacheFilter() {
751746
requestCacheBldr = BeanDefinitionBuilder.rootBeanDefinition(HttpSessionRequestCache.class);
752747
requestCacheBldr.addPropertyValue("createSessionAllowed",
753748
this.sessionPolicy == SessionCreationPolicy.IF_REQUIRED);
754-
requestCacheBldr.addPropertyValue("portResolver", this.portResolver);
755749
if (this.csrfFilter != null) {
756750
BeanDefinitionBuilder requestCacheMatcherBldr = BeanDefinitionBuilder
757751
.rootBeanDefinition(RequestMatcherFactoryBean.class);

config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import org.springframework.security.web.DefaultSecurityFilterChain;
5858
import org.springframework.security.web.FilterChainProxy;
5959
import org.springframework.security.web.ObservationFilterChainDecorator;
60-
import org.springframework.security.web.PortResolverImpl;
6160
import org.springframework.security.web.firewall.ObservationMarkingRequestRejectedHandler;
6261
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
6362
import org.springframework.util.StringUtils;
@@ -151,19 +150,18 @@ private BeanReference createFilterChain(Element element, ParserContext pc) {
151150
return createSecurityFilterChainBean(element, pc, Collections.emptyList());
152151
}
153152
BeanReference portMapper = createPortMapper(element, pc);
154-
BeanReference portResolver = createPortResolver(portMapper, pc);
155153
ManagedList<BeanReference> authenticationProviders = new ManagedList<>();
156154
BeanReference authenticationManager = createAuthenticationManager(element, pc, authenticationProviders);
157155
boolean forceAutoConfig = isDefaultHttpConfig(element);
158156
BeanMetadataElement observationRegistry = getObservationRegistry(element);
159157
HttpConfigurationBuilder httpBldr = new HttpConfigurationBuilder(element, forceAutoConfig, pc, portMapper,
160-
portResolver, authenticationManager, observationRegistry);
158+
authenticationManager, observationRegistry);
161159
httpBldr.getSecurityContextRepositoryForAuthenticationFilters();
162160
AuthenticationConfigBuilder authBldr = new AuthenticationConfigBuilder(element, forceAutoConfig, pc,
163161
httpBldr.getSessionCreationPolicy(), httpBldr.getRequestCache(), authenticationManager,
164162
httpBldr.getSecurityContextHolderStrategyForAuthenticationFilters(),
165163
httpBldr.getSecurityContextRepositoryForAuthenticationFilters(), httpBldr.getSessionStrategy(),
166-
portMapper, portResolver, httpBldr.getCsrfLogoutHandler());
164+
portMapper, httpBldr.getCsrfLogoutHandler());
167165
httpBldr.setLogoutHandlers(authBldr.getLogoutHandlers());
168166
httpBldr.setEntryPoint(authBldr.getEntryPointBean());
169167
httpBldr.setAccessDeniedHandler(authBldr.getAccessDeniedHandlerBean());
@@ -241,18 +239,6 @@ private BeanReference createPortMapper(Element elt, ParserContext pc) {
241239
return new RuntimeBeanReference(portMapperName);
242240
}
243241

244-
private RuntimeBeanReference createPortResolver(BeanReference portMapper, ParserContext pc) {
245-
String beanName = "portResolver";
246-
if (pc.getRegistry().containsBeanDefinition(beanName)) {
247-
return new RuntimeBeanReference(beanName);
248-
}
249-
RootBeanDefinition portResolver = new RootBeanDefinition(PortResolverImpl.class);
250-
portResolver.getPropertyValues().addPropertyValue("portMapper", portMapper);
251-
String portResolverName = pc.getReaderContext().generateBeanName(portResolver);
252-
pc.registerBeanComponent(new BeanComponentDefinition(portResolver, portResolverName));
253-
return new RuntimeBeanReference(portResolverName);
254-
}
255-
256242
/**
257243
* Creates the internal AuthenticationManager bean which uses either the externally
258244
* registered (global) one as a parent or the bean specified by

config/src/main/java/org/springframework/security/config/http/OAuth2LoginBeanDefinitionParser.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser {
111111

112112
private final BeanReference portMapper;
113113

114-
private final BeanReference portResolver;
115-
116114
private final BeanReference sessionStrategy;
117115

118116
private final boolean allowSessionCreation;
@@ -131,12 +129,10 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser {
131129

132130
private BeanDefinition oauth2LoginLinks;
133131

134-
OAuth2LoginBeanDefinitionParser(BeanReference requestCache, BeanReference portMapper, BeanReference portResolver,
135-
BeanReference sessionStrategy, boolean allowSessionCreation,
136-
BeanMetadataElement authenticationFilterSecurityContextHolderStrategy) {
132+
OAuth2LoginBeanDefinitionParser(BeanReference requestCache, BeanReference portMapper, BeanReference sessionStrategy,
133+
boolean allowSessionCreation, BeanMetadataElement authenticationFilterSecurityContextHolderStrategy) {
137134
this.requestCache = requestCache;
138135
this.portMapper = portMapper;
139-
this.portResolver = portResolver;
140136
this.sessionStrategy = sessionStrategy;
141137
this.allowSessionCreation = allowSessionCreation;
142138
this.authenticationFilterSecurityContextHolderStrategy = authenticationFilterSecurityContextHolderStrategy;
@@ -231,7 +227,6 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
231227
.rootBeanDefinition(LoginUrlAuthenticationEntryPoint.class)
232228
.addConstructorArgValue(loginPage)
233229
.addPropertyValue("portMapper", this.portMapper)
234-
.addPropertyValue("portResolver", this.portResolver)
235230
.getBeanDefinition();
236231
}
237232
else {

config/src/main/java/org/springframework/security/config/http/Saml2LoginBeanDefinitionParser.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ final class Saml2LoginBeanDefinitionParser implements BeanDefinitionParser {
7676

7777
private final BeanReference portMapper;
7878

79-
private final BeanReference portResolver;
80-
8179
private final BeanReference requestCache;
8280

8381
private final boolean allowSessionCreation;
@@ -97,12 +95,11 @@ final class Saml2LoginBeanDefinitionParser implements BeanDefinitionParser {
9795
private BeanDefinition saml2AuthenticationUrlToProviderName;
9896

9997
Saml2LoginBeanDefinitionParser(List<BeanDefinition> csrfIgnoreRequestMatchers, BeanReference portMapper,
100-
BeanReference portResolver, BeanReference requestCache, boolean allowSessionCreation,
101-
BeanReference authenticationManager, BeanReference authenticationFilterSecurityContextRepositoryRef,
102-
List<BeanReference> authenticationProviders, Map<BeanDefinition, BeanMetadataElement> entryPoints) {
98+
BeanReference requestCache, boolean allowSessionCreation, BeanReference authenticationManager,
99+
BeanReference authenticationFilterSecurityContextRepositoryRef, List<BeanReference> authenticationProviders,
100+
Map<BeanDefinition, BeanMetadataElement> entryPoints) {
103101
this.csrfIgnoreRequestMatchers = csrfIgnoreRequestMatchers;
104102
this.portMapper = portMapper;
105-
this.portResolver = portResolver;
106103
this.requestCache = requestCache;
107104
this.allowSessionCreation = allowSessionCreation;
108105
this.authenticationManager = authenticationManager;
@@ -198,7 +195,6 @@ private void resolveLoginPage(Element element, ParserContext parserContext) {
198195
.rootBeanDefinition(LoginUrlAuthenticationEntryPoint.class)
199196
.addConstructorArgValue(loginPage)
200197
.addPropertyValue("portMapper", this.portMapper)
201-
.addPropertyValue("portResolver", this.portResolver)
202198
.getBeanDefinition();
203199
}
204200
else {
@@ -209,7 +205,6 @@ private void resolveLoginPage(Element element, ParserContext parserContext) {
209205
.rootBeanDefinition(LoginUrlAuthenticationEntryPoint.class)
210206
.addConstructorArgValue(loginUrl)
211207
.addPropertyValue("portMapper", this.portMapper)
212-
.addPropertyValue("portResolver", this.portResolver)
213208
.getBeanDefinition();
214209
}
215210
}

config/src/test/java/org/springframework/security/SerializationSamples.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@
186186
import org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutRequest;
187187
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
188188
import org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations;
189-
import org.springframework.security.web.PortResolverImpl;
190189
import org.springframework.security.web.authentication.WebAuthenticationDetails;
191190
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
192191
import org.springframework.security.web.authentication.preauth.PreAuthenticatedCredentialsNotFoundException;
@@ -594,7 +593,7 @@ final class SerializationSamples {
594593
request.addParameter("parameter", "value");
595594
request.setPathInfo("/path");
596595
request.addPreferredLocale(Locale.ENGLISH);
597-
return new SimpleSavedRequest(new DefaultSavedRequest(request, new PortResolverImpl(), "continue"));
596+
return new SimpleSavedRequest(new DefaultSavedRequest(request, "continue"));
598597
});
599598

600599
generatorByClassName.put(HttpSessionIdChangedEvent.class,

0 commit comments

Comments
 (0)