@Test void givenJwtInCookieAndHeader_whenGetJwtTokenFromRequest_thenPreferCookie() { String cookieName = authConfigurationProperties.getCookieProperties().getCookieName(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setCookies(new Cookie(cookieName, "jwt1")); request.addHeader(HttpHeaders.AUTHORIZATION, ApimlConstants.BEARER_AUTHENTICATION_PREFIX + " jwt2"); Optional<String> token = authService.getJwtTokenFromRequest(request); assertTrue(token.isPresent()); assertEquals("jwt1", token.get()); }
public Optional<String> getJwtTokenFromRequest(HttpServletRequest request) { Optional<String> fromCookie = getJwtTokenFromCookie(request); if (!fromCookie.isPresent()) { return extractJwtTokenFromAuthorizationHeader(request.getHeader(HttpHeaders.AUTHORIZATION)); } return fromCookie; }
AuthenticationService { public Optional<String> getJwtTokenFromRequest(HttpServletRequest request) { Optional<String> fromCookie = getJwtTokenFromCookie(request); if (!fromCookie.isPresent()) { return extractJwtTokenFromAuthorizationHeader(request.getHeader(HttpHeaders.AUTHORIZATION)); } return fromCookie; } }
AuthenticationService { public Optional<String> getJwtTokenFromRequest(HttpServletRequest request) { Optional<String> fromCookie = getJwtTokenFromCookie(request); if (!fromCookie.isPresent()) { return extractJwtTokenFromAuthorizationHeader(request.getHeader(HttpHeaders.AUTHORIZATION)); } return fromCookie; }  }
AuthenticationService { public Optional<String> getJwtTokenFromRequest(HttpServletRequest request) { Optional<String> fromCookie = getJwtTokenFromCookie(request); if (!fromCookie.isPresent()) { return extractJwtTokenFromAuthorizationHeader(request.getHeader(HttpHeaders.AUTHORIZATION)); } return fromCookie; }  @PostConstruct void afterPropertiesSet(); String createJwtToken(String username, String domain, String ltpaToken); @CacheEvict(value = CACHE_VALIDATION_JWT_TOKEN, key = "#jwtToken") @Cacheable(value = CACHE_INVALIDATED_JWT_TOKENS, key = "#jwtToken", condition = "#jwtToken != null") Boolean invalidateJwtToken(String jwtToken, boolean distribute); @Cacheable(value = CACHE_INVALIDATED_JWT_TOKENS, unless = "true", key = "#jwtToken", condition = "#jwtToken != null") Boolean isInvalidated(String jwtToken); @Cacheable(value = CACHE_VALIDATION_JWT_TOKEN, key = "#jwtToken", condition = "#jwtToken != null") TokenAuthentication validateJwtToken(String jwtToken); @CachePut(value = "validationJwtToken", key = "#jwtToken", condition = "#jwtToken != null") TokenAuthentication createTokenAuthentication(String user, String jwtToken); boolean distributeInvalidate(String toInstanceId); TokenAuthentication validateJwtToken(TokenAuthentication token); QueryResponse parseJwtToken(String jwtToken); Optional<String> getJwtTokenFromRequest(HttpServletRequest request); String getLtpaTokenWithValidation(String jwtToken); String getLtpaToken(String jwtToken); }
AuthenticationService { public Optional<String> getJwtTokenFromRequest(HttpServletRequest request) { Optional<String> fromCookie = getJwtTokenFromCookie(request); if (!fromCookie.isPresent()) { return extractJwtTokenFromAuthorizationHeader(request.getHeader(HttpHeaders.AUTHORIZATION)); } return fromCookie; }  @PostConstruct void afterPropertiesSet(); String createJwtToken(String username, String domain, String ltpaToken); @CacheEvict(value = CACHE_VALIDATION_JWT_TOKEN, key = "#jwtToken") @Cacheable(value = CACHE_INVALIDATED_JWT_TOKENS, key = "#jwtToken", condition = "#jwtToken != null") Boolean invalidateJwtToken(String jwtToken, boolean distribute); @Cacheable(value = CACHE_INVALIDATED_JWT_TOKENS, unless = "true", key = "#jwtToken", condition = "#jwtToken != null") Boolean isInvalidated(String jwtToken); @Cacheable(value = CACHE_VALIDATION_JWT_TOKEN, key = "#jwtToken", condition = "#jwtToken != null") TokenAuthentication validateJwtToken(String jwtToken); @CachePut(value = "validationJwtToken", key = "#jwtToken", condition = "#jwtToken != null") TokenAuthentication createTokenAuthentication(String user, String jwtToken); boolean distributeInvalidate(String toInstanceId); TokenAuthentication validateJwtToken(TokenAuthentication token); QueryResponse parseJwtToken(String jwtToken); Optional<String> getJwtTokenFromRequest(HttpServletRequest request); String getLtpaTokenWithValidation(String jwtToken); String getLtpaToken(String jwtToken);  }