Commit 1f1cc84a92c46eb140114b277091ebb31ae540bf

Authored by vzikratyi
1 parent 6b41fb9c

Changed getting redirectUri

... ... @@ -190,17 +190,33 @@ public class CustomOAuth2AuthorizationRequestResolver implements OAuth2Authoriza
190 190
191 191 uriVariables.put("action", action == null ? "" : action);
192 192
193   - return UriComponentsBuilder.fromUriString(getRedirectUri(request))
  193 + String redirectUri = getRedirectUri(request);
  194 + log.trace("Redirect URI - {}.", redirectUri);
  195 +
  196 + return UriComponentsBuilder.fromUriString(redirectUri)
194 197 .buildAndExpand(uriVariables)
195 198 .toUriString();
196 199 }
197 200
198 201 private String getRedirectUri(HttpServletRequest request) {
199 202 String loginProcessingUri = oauth2Configuration != null ? oauth2Configuration.getLoginProcessingUrl() : DEFAULT_LOGIN_PROCESSING_URI;
200   - String baseUrl= MiscUtils.constructBaseUrl(request);
  203 +
  204 + String scheme = MiscUtils.getScheme(request);
  205 + String domainName = MiscUtils.getDomainName(request);
  206 + int port = MiscUtils.getPort(request);
  207 + String baseUrl = scheme + "://" + domainName;
  208 + if (needsPort(scheme, port)){
  209 + baseUrl += ":" + port;
  210 + }
201 211 return baseUrl + loginProcessingUri;
202 212 }
203 213
  214 + private boolean needsPort(String scheme, int port) {
  215 + boolean isHttpDefault = "http".equals(scheme.toLowerCase()) && port == 80;
  216 + boolean isHttpsDefault = "https".equals(scheme.toLowerCase()) && port == 443;
  217 + return !isHttpDefault && !isHttpsDefault;
  218 + }
  219 +
204 220 /**
205 221 * Creates nonce and its hash for use in OpenID Connect 1.0 Authentication Requests.
206 222 *
... ...