@Test public void testGetBearerTokenCustomCookieHeader() { when(authContextInfo.getTokenHeader()).thenReturn(COOKIE); when(authContextInfo.getTokenCookie()).thenReturn("CustomCookie"); AbstractBearerTokenExtractor target = newTarget(h -> null, c -> { if ("CustomCookie".equals(c)) { return "THE_TOKEN"; } return null; }); String bearerToken = target.getBearerToken(); assertEquals("THE_TOKEN", bearerToken); }
public String getBearerToken() { final String tokenHeaderName = authContextInfo.getTokenHeader(); final boolean fallbackToHeader = authContextInfo.isAlwaysCheckAuthorization(); AuthLogging.log.tokenHeaderName(tokenHeaderName); final String bearerValue; if (COOKIE_HEADER.equals(tokenHeaderName)) { String intermediateBearerValue = getBearerTokenCookie(); if (intermediateBearerValue == null && fallbackToHeader) { bearerValue = getBearerTokenAuthHeader(); } else { bearerValue = intermediateBearerValue; } } else if (AUTHORIZATION_HEADER.equals(tokenHeaderName)) { bearerValue = getBearerTokenAuthHeader(); } else { String customHeaderValue = getHeaderValue(tokenHeaderName); if (customHeaderValue == null) { AuthLogging.log.headerIsNull(tokenHeaderName); } else { String customHeaderSchemeValue = getTokenWithConfiguredScheme(customHeaderValue); if (customHeaderSchemeValue != null) { customHeaderValue = customHeaderSchemeValue; } } bearerValue = customHeaderValue; } return bearerValue; }
AbstractBearerTokenExtractor { public String getBearerToken() { final String tokenHeaderName = authContextInfo.getTokenHeader(); final boolean fallbackToHeader = authContextInfo.isAlwaysCheckAuthorization(); AuthLogging.log.tokenHeaderName(tokenHeaderName); final String bearerValue; if (COOKIE_HEADER.equals(tokenHeaderName)) { String intermediateBearerValue = getBearerTokenCookie(); if (intermediateBearerValue == null && fallbackToHeader) { bearerValue = getBearerTokenAuthHeader(); } else { bearerValue = intermediateBearerValue; } } else if (AUTHORIZATION_HEADER.equals(tokenHeaderName)) { bearerValue = getBearerTokenAuthHeader(); } else { String customHeaderValue = getHeaderValue(tokenHeaderName); if (customHeaderValue == null) { AuthLogging.log.headerIsNull(tokenHeaderName); } else { String customHeaderSchemeValue = getTokenWithConfiguredScheme(customHeaderValue); if (customHeaderSchemeValue != null) { customHeaderValue = customHeaderSchemeValue; } } bearerValue = customHeaderValue; } return bearerValue; } }
AbstractBearerTokenExtractor { public String getBearerToken() { final String tokenHeaderName = authContextInfo.getTokenHeader(); final boolean fallbackToHeader = authContextInfo.isAlwaysCheckAuthorization(); AuthLogging.log.tokenHeaderName(tokenHeaderName); final String bearerValue; if (COOKIE_HEADER.equals(tokenHeaderName)) { String intermediateBearerValue = getBearerTokenCookie(); if (intermediateBearerValue == null && fallbackToHeader) { bearerValue = getBearerTokenAuthHeader(); } else { bearerValue = intermediateBearerValue; } } else if (AUTHORIZATION_HEADER.equals(tokenHeaderName)) { bearerValue = getBearerTokenAuthHeader(); } else { String customHeaderValue = getHeaderValue(tokenHeaderName); if (customHeaderValue == null) { AuthLogging.log.headerIsNull(tokenHeaderName); } else { String customHeaderSchemeValue = getTokenWithConfiguredScheme(customHeaderValue); if (customHeaderSchemeValue != null) { customHeaderValue = customHeaderSchemeValue; } } bearerValue = customHeaderValue; } return bearerValue; } protected  AbstractBearerTokenExtractor(JWTAuthContextInfo authContextInfo); }
AbstractBearerTokenExtractor { public String getBearerToken() { final String tokenHeaderName = authContextInfo.getTokenHeader(); final boolean fallbackToHeader = authContextInfo.isAlwaysCheckAuthorization(); AuthLogging.log.tokenHeaderName(tokenHeaderName); final String bearerValue; if (COOKIE_HEADER.equals(tokenHeaderName)) { String intermediateBearerValue = getBearerTokenCookie(); if (intermediateBearerValue == null && fallbackToHeader) { bearerValue = getBearerTokenAuthHeader(); } else { bearerValue = intermediateBearerValue; } } else if (AUTHORIZATION_HEADER.equals(tokenHeaderName)) { bearerValue = getBearerTokenAuthHeader(); } else { String customHeaderValue = getHeaderValue(tokenHeaderName); if (customHeaderValue == null) { AuthLogging.log.headerIsNull(tokenHeaderName); } else { String customHeaderSchemeValue = getTokenWithConfiguredScheme(customHeaderValue); if (customHeaderSchemeValue != null) { customHeaderValue = customHeaderSchemeValue; } } bearerValue = customHeaderValue; } return bearerValue; } protected  AbstractBearerTokenExtractor(JWTAuthContextInfo authContextInfo); String getBearerToken(); }
AbstractBearerTokenExtractor { public String getBearerToken() { final String tokenHeaderName = authContextInfo.getTokenHeader(); final boolean fallbackToHeader = authContextInfo.isAlwaysCheckAuthorization(); AuthLogging.log.tokenHeaderName(tokenHeaderName); final String bearerValue; if (COOKIE_HEADER.equals(tokenHeaderName)) { String intermediateBearerValue = getBearerTokenCookie(); if (intermediateBearerValue == null && fallbackToHeader) { bearerValue = getBearerTokenAuthHeader(); } else { bearerValue = intermediateBearerValue; } } else if (AUTHORIZATION_HEADER.equals(tokenHeaderName)) { bearerValue = getBearerTokenAuthHeader(); } else { String customHeaderValue = getHeaderValue(tokenHeaderName); if (customHeaderValue == null) { AuthLogging.log.headerIsNull(tokenHeaderName); } else { String customHeaderSchemeValue = getTokenWithConfiguredScheme(customHeaderValue); if (customHeaderSchemeValue != null) { customHeaderValue = customHeaderSchemeValue; } } bearerValue = customHeaderValue; } return bearerValue; } protected  AbstractBearerTokenExtractor(JWTAuthContextInfo authContextInfo); String getBearerToken();  }