@Test 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)); }
public static Authenticator buildAuthenticatorWithTruststore(final String keystorePath, final char[] keystorePassword, final List<String> keyids) { if (keystorePath != null) { final File file = new File(keystorePath); if (file.exists()) { try (final InputStream is = Files.newInputStream(file.toPath())) { final KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(is, keystorePassword); final List<String> keyIds = filterKeyIds(ks, keyids); switch (keyIds.size()) { case 0: LOGGER.warn("No valid key ids provided! Skipping keystore: {}", keystorePath); return null; case 1: return new JwtAuthenticator(ks.getCertificate(keyIds.get(0)).getPublicKey()); default: return new FederatedJwtAuthenticator(ks, keyIds); } } catch (final IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException ex) { LOGGER.error("Error reading keystore: {}", ex.getMessage()); LOGGER.warn("Ignoring JWT authenticator with keystore: {}", keystorePath); } } } return null; }
OAuthUtils { public static Authenticator buildAuthenticatorWithTruststore(final String keystorePath, final char[] keystorePassword, final List<String> keyids) { if (keystorePath != null) { final File file = new File(keystorePath); if (file.exists()) { try (final InputStream is = Files.newInputStream(file.toPath())) { final KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(is, keystorePassword); final List<String> keyIds = filterKeyIds(ks, keyids); switch (keyIds.size()) { case 0: LOGGER.warn("No valid key ids provided! Skipping keystore: {}", keystorePath); return null; case 1: return new JwtAuthenticator(ks.getCertificate(keyIds.get(0)).getPublicKey()); default: return new FederatedJwtAuthenticator(ks, keyIds); } } catch (final IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException ex) { LOGGER.error("Error reading keystore: {}", ex.getMessage()); LOGGER.warn("Ignoring JWT authenticator with keystore: {}", keystorePath); } } } return null; } }
OAuthUtils { public static Authenticator buildAuthenticatorWithTruststore(final String keystorePath, final char[] keystorePassword, final List<String> keyids) { if (keystorePath != null) { final File file = new File(keystorePath); if (file.exists()) { try (final InputStream is = Files.newInputStream(file.toPath())) { final KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(is, keystorePassword); final List<String> keyIds = filterKeyIds(ks, keyids); switch (keyIds.size()) { case 0: LOGGER.warn("No valid key ids provided! Skipping keystore: {}", keystorePath); return null; case 1: return new JwtAuthenticator(ks.getCertificate(keyIds.get(0)).getPublicKey()); default: return new FederatedJwtAuthenticator(ks, keyIds); } } catch (final IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException ex) { LOGGER.error("Error reading keystore: {}", ex.getMessage()); LOGGER.warn("Ignoring JWT authenticator with keystore: {}", keystorePath); } } } return null; } private  OAuthUtils(); }
OAuthUtils { public static Authenticator buildAuthenticatorWithTruststore(final String keystorePath, final char[] keystorePassword, final List<String> keyids) { if (keystorePath != null) { final File file = new File(keystorePath); if (file.exists()) { try (final InputStream is = Files.newInputStream(file.toPath())) { final KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(is, keystorePassword); final List<String> keyIds = filterKeyIds(ks, keyids); switch (keyIds.size()) { case 0: LOGGER.warn("No valid key ids provided! Skipping keystore: {}", keystorePath); return null; case 1: return new JwtAuthenticator(ks.getCertificate(keyIds.get(0)).getPublicKey()); default: return new FederatedJwtAuthenticator(ks, keyIds); } } catch (final IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException ex) { LOGGER.error("Error reading keystore: {}", ex.getMessage()); LOGGER.warn("Ignoring JWT authenticator with keystore: {}", keystorePath); } } } return null; } private  OAuthUtils(); static Principal withWebIdClaim(final Claims claims); static Principal withSubjectClaim(final Claims claims); static Authenticator buildAuthenticatorWithJwk(final String location); static Key buildRSAPublicKey(final String keyType, final BigInteger modulus,
            final BigInteger exponent); static Authenticator buildAuthenticatorWithSharedSecret(final String key); static Authenticator buildAuthenticatorWithTruststore(final String keystorePath,
            final char[] keystorePassword, final List<String> keyids); }
OAuthUtils { public static Authenticator buildAuthenticatorWithTruststore(final String keystorePath, final char[] keystorePassword, final List<String> keyids) { if (keystorePath != null) { final File file = new File(keystorePath); if (file.exists()) { try (final InputStream is = Files.newInputStream(file.toPath())) { final KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(is, keystorePassword); final List<String> keyIds = filterKeyIds(ks, keyids); switch (keyIds.size()) { case 0: LOGGER.warn("No valid key ids provided! Skipping keystore: {}", keystorePath); return null; case 1: return new JwtAuthenticator(ks.getCertificate(keyIds.get(0)).getPublicKey()); default: return new FederatedJwtAuthenticator(ks, keyIds); } } catch (final IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException ex) { LOGGER.error("Error reading keystore: {}", ex.getMessage()); LOGGER.warn("Ignoring JWT authenticator with keystore: {}", keystorePath); } } } return null; } private  OAuthUtils(); static Principal withWebIdClaim(final Claims claims); static Principal withSubjectClaim(final Claims claims); static Authenticator buildAuthenticatorWithJwk(final String location); static Key buildRSAPublicKey(final String keyType, final BigInteger modulus,
            final BigInteger exponent); static Authenticator buildAuthenticatorWithSharedSecret(final String key); static Authenticator buildAuthenticatorWithTruststore(final String keystorePath,
            final char[] keystorePassword, final List<String> keyids); static final String WEBID; static final String WEBSITE; }