private static Authenticator buildAuthenticator() { final Configuration config = getConfiguration(); final Authenticator jwksAuthenticator = OAuthUtils.buildAuthenticatorWithJwk( config.get(CONFIG_AUTH_OAUTH_JWK_URL)); if (nonNull(jwksAuthenticator)) { return jwksAuthenticator; } final Authenticator keystoreAuthenticator = OAuthUtils.buildAuthenticatorWithTruststore( config.get(CONFIG_AUTH_OAUTH_KEYSTORE_PATH), config.getOrDefault(CONFIG_AUTH_OAUTH_KEYSTORE_CREDENTIALS, "").toCharArray(), asList(config.getOrDefault(CONFIG_AUTH_OAUTH_KEYSTORE_IDS, "").split(","))); if (nonNull(keystoreAuthenticator)) { return keystoreAuthenticator; } final Authenticator sharedKeyAuthenticator = OAuthUtils.buildAuthenticatorWithSharedSecret( config.get(CONFIG_AUTH_OAUTH_SHARED_SECRET)); if (nonNull(sharedKeyAuthenticator)) { return sharedKeyAuthenticator; } return new NullAuthenticator(); }
public static Authenticator getJwtAuthenticator(final JwtAuthConfiguration config) { final Authenticator jwksAuthenticator = OAuthUtils.buildAuthenticatorWithJwk( config.getJwks()); if (nonNull(jwksAuthenticator)) { return jwksAuthenticator; } final Authenticator keystoreAuthenticator = OAuthUtils.buildAuthenticatorWithTruststore( config.getKeyStore(), config.getKeyStorePassword().toCharArray(), config.getKeyIds()); if (nonNull(keystoreAuthenticator)) { return keystoreAuthenticator; } final Authenticator sharedKeyAuthenticator = OAuthUtils.buildAuthenticatorWithSharedSecret(config.getKey()); if (nonNull(sharedKeyAuthenticator)) { return sharedKeyAuthenticator; } return new NullAuthenticator(); }
@Test public void testNullAuthenticator() { final Authenticator authenticator = new NullAuthenticator(); assertFalse(authenticator.authenticate("blah").isPresent(), "Unexpected principal found!"); assertNull(authenticator.parse("credentials"), "Credentials were not null!"); }