Skip authentication for the `OIDCKeycloak.js` file (Fix regression) (#9505)

Skip authentication for the `OIDCKeycloak.js` file

Signed-off-by: David Festal <dfestal@redhat.com>
6.19.x
David Festal 2018-04-23 10:23:17 +02:00 committed by GitHub
parent 654980a4e0
commit c66d349728
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -38,14 +38,16 @@ public abstract class AbstractKeycloakFilter implements Filter {
/** when a request came from a machine with valid token then auth is not required */
protected boolean shouldSkipAuthentication(HttpServletRequest request, String token) {
if (token == null) {
if (request.getRequestURI() != null
&& request.getRequestURI().endsWith("api/keycloak/OIDCKeycloak.js")) {
return true;
}
return false;
}
try {
final PublicKey publicKey = signatureKeyManager.getKeyPair().getPublic();
final Jwt jwt = Jwts.parser().setSigningKey(publicKey).parse(token);
return MACHINE_TOKEN_KIND.equals(jwt.getHeader().get("kind"))
|| (request.getRequestURI() != null
&& request.getRequestURI().endsWith("api/keycloak/OIDCKeycloak.js"));
return MACHINE_TOKEN_KIND.equals(jwt.getHeader().get("kind"));
} catch (ExpiredJwtException | MalformedJwtException | SignatureException ex) {
// given token is not signed by particular signature key so it must be checked in another way
return false;

View File

@ -65,6 +65,13 @@ public class AbstractKeycloakFilterTest {
.compact();
when(signatureKeyManager.getKeyPair()).thenReturn(keyPair);
when(request.getRequestURI()).thenReturn(null);
}
@Test
public void testShouldSkipAuthWhenRetrievingOIDCKeycloakJsFile() {
when(request.getRequestURI()).thenReturn("https://localhost:8080/api/keycloak/OIDCKeycloak.js");
assertTrue(abstractKeycloakFilter.shouldSkipAuthentication(request, null));
}
@Test