UaaUrlUtils { public static String getBaseURL(HttpServletRequest request) { String requestURL = request.getRequestURL().toString(); return hasText(request.getServletPath()) ? requestURL.substring(0, requestURL.lastIndexOf(request.getServletPath())) : requestURL; }  static String getUaaUrl(String path, IdentityZone currentIdentityZone); static String getUaaUrl(String path, boolean zoneSwitchPossible, IdentityZone currentIdentityZone); static String getUaaHost(IdentityZone currentIdentityZone); static boolean isValidRegisteredRedirectUrl(String url); static boolean isValidSubdomain(String subdomain); static String findMatchingRedirectUri(Collection<String> redirectUris, String requestedRedirectUri, String fallbackRedirectUri); static String getHostForURI(String uri); static String getBaseURL(HttpServletRequest request); static Map<String, String[]> getParameterMap(String uri); static boolean isUrl(String url); static String addQueryParameter(String url, String name, String value); static String addFragmentComponent(String urlString, String component); static String addSubdomainToUrl(String url, String subdomain); static String getSubdomain(String subdomain); static String extractPathVariableFromUrl(int pathParameterIndex, String path); static String getRequestPath(HttpServletRequest request); static boolean uriHasMatchingHost(String uri, String hostname); static String normalizeUri(String uri);  }
@Test void getBaseURL() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("login.domain"); request.setRequestURI("/something"); request.setServletPath("/something"); ServletRequestAttributes attrs = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(attrs); assertEquals("http: }
@Test void getBaseURLWhenPathMatchesHostname() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("login.domain"); request.setRequestURI("/login"); request.setServletPath("/login"); ServletRequestAttributes attrs = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(attrs); assertEquals("http: }
@Test void getBaseURLOnLocalhost() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(8080); request.setRequestURI("/uaa/something"); request.setServletPath("/something"); ServletRequestAttributes attrs = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(attrs); assertEquals("http: }