LookoutTokenResolveUtils { public static String getLookoutToken(ServerRequest.Headers headers) { String token = WebfluxUtils.getHeaderValue(headers, Constants.TOKEN_HEADER_NAME); if (token == null) { String authorization = WebfluxUtils.getHeaderValue(headers, "Authorization"); if (StringUtils.startsWith(authorization, "Basic ")) { String base64 = authorization.substring(6); String usernameAndPassword = new String(Base64.getUrlDecoder().decode(base64), StandardCharsets.UTF_8); String username = StringUtils.substringBefore(usernameAndPassword, ":"); if ("lookout".equals(username)) { String password = StringUtils.substringAfter(usernameAndPassword, ":"); token = password; } else { token = username; } } } return token; } private  LookoutTokenResolveUtils(); static String getLookoutToken(ServerRequest.Headers headers);  }
@Test public void testGetLookoutTokenFromHeader() { HttpHeaders headers = new HttpHeaders(); headers.add(Constants.TOKEN_HEADER_NAME, "demo"); ServerRequest req = MockServerRequest.builder().headers(headers).build(); String x = LookoutTokenResolveUtils.getLookoutToken(req.headers()); Assert.assertEquals("demo", x); }
@Test public void testGetLookoutTokenFromBasicAuth() { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + Base64.getEncoder().encodeToString("hello".getBytes())); ServerRequest req = MockServerRequest.builder().headers(headers).build(); String x = LookoutTokenResolveUtils.getLookoutToken(req.headers()); Assert.assertEquals("hello", x); }