|
21 | 21 |
|
22 | 22 | import jakarta.servlet.http.HttpServletRequest;
|
23 | 23 |
|
| 24 | +import org.springframework.context.ApplicationContext; |
24 | 25 | import org.springframework.http.MediaType;
|
25 | 26 | import org.springframework.security.authentication.AuthenticationDetailsSource;
|
26 | 27 | import org.springframework.security.authentication.AuthenticationManager;
|
27 | 28 | import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
|
28 | 29 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
29 | 30 | import org.springframework.security.web.AuthenticationEntryPoint;
|
30 | 31 | import org.springframework.security.web.PortMapper;
|
| 32 | +import org.springframework.security.web.PortResolver; |
31 | 33 | import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
|
32 | 34 | import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
33 | 35 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
@@ -272,6 +274,10 @@ public void configure(B http) throws Exception {
|
272 | 274 | if (portMapper != null) {
|
273 | 275 | this.authenticationEntryPoint.setPortMapper(portMapper);
|
274 | 276 | }
|
| 277 | + PortResolver portResolver = getBeanOrNull(http, PortResolver.class); |
| 278 | + if (portResolver != null) { |
| 279 | + this.authenticationEntryPoint.setPortResolver(portResolver); |
| 280 | + } |
275 | 281 | RequestCache requestCache = http.getSharedObject(RequestCache.class);
|
276 | 282 | if (requestCache != null) {
|
277 | 283 | this.defaultSuccessHandler.setRequestCache(requestCache);
|
@@ -412,6 +418,14 @@ private void setLoginPage(String loginPage) {
|
412 | 418 | this.authenticationEntryPoint = new LoginUrlAuthenticationEntryPoint(loginPage);
|
413 | 419 | }
|
414 | 420 |
|
| 421 | + private <C> C getBeanOrNull(B http, Class<C> clazz) { |
| 422 | + ApplicationContext context = http.getSharedObject(ApplicationContext.class); |
| 423 | + if (context == null) { |
| 424 | + return null; |
| 425 | + } |
| 426 | + return context.getBeanProvider(clazz).getIfUnique(); |
| 427 | + } |
| 428 | + |
415 | 429 | @SuppressWarnings("unchecked")
|
416 | 430 | private T getSelf() {
|
417 | 431 | return (T) this;
|
|
0 commit comments