|
29 | 29 | import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
|
30 | 30 | import org.springframework.security.web.savedrequest.RequestCache;
|
31 | 31 | import org.springframework.security.web.util.ThrowableAnalyzer;
|
| 32 | +import org.springframework.security.web.util.UrlUtils; |
32 | 33 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
33 | 34 | import org.springframework.util.Assert;
|
34 | 35 | import org.springframework.web.filter.OncePerRequestFilter;
|
@@ -254,23 +255,15 @@ private void unsuccessfulRedirectForAuthorization(HttpServletRequest request, Ht
|
254 | 255 | }
|
255 | 256 |
|
256 | 257 | private String expandRedirectUri(HttpServletRequest request, ClientRegistration clientRegistration) {
|
257 |
| - int port = request.getServerPort(); |
258 |
| - if (("http".equals(request.getScheme()) && port == 80) || ("https".equals(request.getScheme()) && port == 443)) { |
259 |
| - port = -1; // Removes the port in UriComponentsBuilder |
260 |
| - } |
261 |
| - |
262 | 258 | // Supported URI variables -> baseUrl, action, registrationId
|
263 | 259 | // Used in -> CommonOAuth2Provider.DEFAULT_REDIRECT_URL = "{baseUrl}/{action}/oauth2/code/{registrationId}"
|
264 | 260 | Map<String, String> uriVariables = new HashMap<>();
|
265 | 261 | uriVariables.put("registrationId", clientRegistration.getRegistrationId());
|
266 | 262 |
|
267 |
| - String baseUrl = UriComponentsBuilder.newInstance() |
268 |
| - .scheme(request.getScheme()) |
269 |
| - .host(request.getServerName()) |
270 |
| - .port(port) |
271 |
| - .path(request.getContextPath()) |
272 |
| - .build() |
273 |
| - .toUriString(); |
| 263 | + String baseUrl = UriComponentsBuilder.fromHttpUrl(UrlUtils.buildFullRequestUrl(request)) |
| 264 | + .replacePath(request.getContextPath()) |
| 265 | + .build() |
| 266 | + .toUriString(); |
274 | 267 | uriVariables.put("baseUrl", baseUrl);
|
275 | 268 |
|
276 | 269 | if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(clientRegistration.getAuthorizationGrantType())) {
|
|
0 commit comments