@Test public void testOAuthFederatedBuilderBadPassphrase() { final String keystorePath = OAuthUtilsTest.class.getResource("/keystore.jks").getPath(); final List<String> ids = asList("trellis,trellis-ec".split(",")); assertNull(OAuthUtils.buildAuthenticatorWithTruststore(keystorePath, "foo".toCharArray(), ids)); }
@Test public void testBuildFederatedNull() { assertNull(OAuthUtils.buildAuthenticatorWithTruststore(null, "test".toCharArray(), asList("one,two".split(",")))); }
@Test public void testOAuthFederatedBuilder() { final String keystorePath = OAuthUtilsTest.class.getResource("/keystore.jks").getPath(); final List<String> ids = asList("trellis,foo".split(",")); final Authenticator authenticator = OAuthUtils.buildAuthenticatorWithTruststore(keystorePath, passphrase, ids); assertTrue(authenticator instanceof JwtAuthenticator); }
@Test public void testOAuthBuilderNoIds() { final String keystorePath = OAuthUtilsTest.class.getResource("/keystore.jks").getPath(); final List<String> ids = asList("foo,bar".split(",")); assertNull(OAuthUtils.buildAuthenticatorWithTruststore(keystorePath, passphrase, ids)); }
@Test public void testOAuthBuilderNoKeystore() { final String keystorePath = OAuthUtilsTest.class.getResource("/keystore.jks").getPath(); final List<String> ids = asList("trellis,foo".split(",")); assertNull(OAuthUtils.buildAuthenticatorWithTruststore(keystorePath + "foo", passphrase, ids)); }
@Test public void testOAuthFederatedBuilderMultipleIds() { final String keystorePath = OAuthUtilsTest.class.getResource("/keystore.jks").getPath(); final List<String> ids = asList("trellis,trellis-ec".split(",")); final Authenticator authenticator = OAuthUtils.buildAuthenticatorWithTruststore(keystorePath, passphrase, ids); assertTrue(authenticator instanceof FederatedJwtAuthenticator); }
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(); }