private static SecretKey encoded(final Password password) throws InvalidKeyException { if (password instanceof ClearPassword) { return new SecretKeySpec(new String(((ClearPassword)password).getPassword()).getBytes(StandardCharsets.UTF_8), "password"); } else { throw ElytronMessages.log.invalidKeyUnknownUnknownPasswordTypeOrAlgorithm(); } }
ClearPasswordImpl(ClearPassword clearPassword) { password = clearPassword.getPassword().clone(); }
@Override public String apply(CredentialSource sharedSecretSource) { try { PasswordCredential credential = sharedSecretSource.getCredential(PasswordCredential.class); ClearPassword password = credential.getPassword(ClearPassword.class); return String.valueOf(password.getPassword()); } catch (IOException e) { throw new IllegalArgumentException(e); } } };
public final String getPassword() { if (credentialSourceSupplier != null) { try { return new String( credentialSourceSupplier.get().getCredential(PasswordCredential.class).getPassword(ClearPassword.class).getPassword()); } catch (Exception e) { throw ConnectorLogger.DEPLOYMENT_CONNECTOR_LOGGER.invalidCredentialSourceSupplier(e); } } return this.password; }
public Credentials getCredentials() { ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier = credentialSourceSupplierInjector.getOptionalValue(); if (credentialSourceSupplier != null) { try { CredentialSource credentialSource = credentialSourceSupplier.get(); if (credentialSource == null) { return credentials; } char[] password = credentialSource.getCredential(PasswordCredential.class).getPassword(ClearPassword.class).getPassword(); return new Credentials(credentials.getUsername(), new String(password)); } catch (Exception e) { throw new RuntimeException(e); } } else { return credentials; } }
@Override public SingleSignOnSessionFactory get() { KeyStore store = this.keyStore.get(); String alias = this.keyAlias; CredentialSource source = this.credentialSource.get(); try { if (!store.containsAlias(alias)) { throw UndertowLogger.ROOT_LOGGER.missingKeyStoreEntry(alias); } if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) { throw UndertowLogger.ROOT_LOGGER.keyStoreEntryNotPrivate(alias); } PasswordCredential credential = source.getCredential(PasswordCredential.class); if (credential == null) { throw UndertowLogger.ROOT_LOGGER.missingCredential(source.toString()); } ClearPassword password = credential.getPassword(ClearPassword.class); if (password == null) { throw UndertowLogger.ROOT_LOGGER.credentialNotClearPassword(credential.toString()); } KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword())); KeyPair keyPair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey()); Optional<SSLContext> context = Optional.ofNullable(this.sslContext).map(dependency -> dependency.get()); return new DefaultSingleSignOnSessionFactory(this.manager.get(), keyPair, connection -> context.ifPresent(ctx -> connection.setSSLSocketFactory(ctx.getSocketFactory()))); } catch (GeneralSecurityException | IOException e) { throw new IllegalArgumentException(e); } } }
composeCryptBasedPassword(out, (UnixDESCryptPassword) password); } else if (ALGORITHM_CLEAR.equals(algorithm)) { return CodePointIterator.ofChars(((ClearPassword)password).getPassword()).asUtf8().drain(); } else { return null;
@Override public CipherAuthToken apply(String authValue) { KeyStore store = this.keyStore.get(); String alias = this.keyAlias; try { if (!store.containsAlias(alias)) { throw JGroupsLogger.ROOT_LOGGER.keyEntryNotFound(alias); } if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) { throw JGroupsLogger.ROOT_LOGGER.unexpectedKeyStoreEntryType(alias, KeyStore.PrivateKeyEntry.class.getSimpleName()); } PasswordCredential credential = this.keyCredentialSource.get().getCredential(PasswordCredential.class); if (credential == null) { throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource(); } ClearPassword password = credential.getPassword(ClearPassword.class); if (password == null) { throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource(); } KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword())); KeyPair pair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey()); Cipher cipher = Cipher.getInstance(this.transformation); return new CipherAuthToken(cipher, pair, authValue.getBytes(StandardCharsets.UTF_8)); } catch (GeneralSecurityException | IOException e) { throw new IllegalArgumentException(e); } } }
private KeyStore.ProtectionParameter convertParameter(final CredentialStore.ProtectionParameter protectionParameter) throws CredentialStoreException { // only one conversion is really possible. if (protectionParameter == null) { return convertParameter(this.protectionParameter); } else if (protectionParameter instanceof CredentialStore.CredentialSourceProtectionParameter) { final CredentialSource credentialSource = ((CredentialStore.CredentialSourceProtectionParameter) protectionParameter).getCredentialSource(); try { return credentialSource.applyToCredential(PasswordCredential.class, c -> c.getPassword().castAndApply(ClearPassword.class, p -> new KeyStore.PasswordProtection(p.getPassword()))); } catch (IOException e) { throw log.cannotAcquireCredentialFromStore(e); } } else { throw log.invalidProtectionParameter(protectionParameter); } }
@Override public void accept(P protocol) { KeyStore store = this.keyStore.get(); String alias = this.keyAlias; try { if (!store.containsAlias(alias)) { throw JGroupsLogger.ROOT_LOGGER.keyEntryNotFound(alias); } PasswordCredential credential = this.credentialSource.get().getCredential(PasswordCredential.class); if (credential == null) { throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource(); } ClearPassword password = credential.getPassword(ClearPassword.class); if (password == null) { throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource(); } if (!store.entryInstanceOf(alias, this.entryClass)) { throw JGroupsLogger.ROOT_LOGGER.unexpectedKeyStoreEntryType(alias, this.entryClass.getSimpleName()); } KeyStore.Entry entry = store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword())); protocol.setKeyStoreEntry(this.entryClass.cast(entry)); } catch (KeyStoreException | IOException | NoSuchAlgorithmException | UnrecoverableEntryException e) { throw new IllegalArgumentException(e); } } }
password = credential.getPassword(ClearPassword.class); if (password == null) throw log.couldNotObtainCredential(); charPassword = password.getPassword(); } catch (Exception e) { throw log.couldNotObtainCredentialWithCause(e); password = credential.getPassword(ClearPassword.class); if (password == null) throw log.couldNotObtainCredential(); charPassword = password.getPassword(); } catch (Exception e) { throw log.obtainingDirContextCredentialFromAuthenticationContextFailed(e);
if (password instanceof ClearPassword) { passwordCallback.setPassword(((ClearPassword) password).getPassword()); continue; } else if (password != null) try {
String password = new String(credentialSourceExceptionExceptionSupplier.get().getCredential(PasswordCredential.class).getPassword(ClearPassword.class).getPassword()); dataSourceConfiguration.connectionPoolConfiguration().connectionFactoryConfiguration().credential(new SimplePassword(password)); } catch (Exception e) {
PasswordCredential passwordCredential = privateCredentials.getCredential(PasswordCredential.class, ClearPassword.ALGORITHM_CLEAR); if (passwordCredential != null) { credential = new String(passwordCredential.getPassword(ClearPassword.class).getPassword()); } else { credential = new RemotingConnectionCredential(connection, localIdentity);
passwordFactory = () -> ((ClearPassword)clearPassword.get()).getPassword(); break;
private static SecretKey encoded(final Password password) throws InvalidKeyException { if (password instanceof ClearPassword) { return new SecretKeySpec(new String(((ClearPassword)password).getPassword()).getBytes(StandardCharsets.UTF_8), "password"); } else { throw ElytronMessages.log.invalidKeyUnknownUnknownPasswordTypeOrAlgorithm(); } }
private static SecretKey encoded(final Password password) throws InvalidKeyException { if (password instanceof ClearPassword) { return new SecretKeySpec(new String(((ClearPassword)password).getPassword()).getBytes(StandardCharsets.UTF_8), "password"); } else { throw ElytronMessages.log.invalidKeyUnknownUnknownPasswordTypeOrAlgorithm(); } }
private static SecretKey encoded(final Password password) throws InvalidKeyException { if (password instanceof ClearPassword) { return new SecretKeySpec(new String(((ClearPassword)password).getPassword()).getBytes(StandardCharsets.UTF_8), "password"); } else { throw ElytronMessages.log.invalidKeyUnknownUnknownPasswordTypeOrAlgorithm(); } }
public final String getPassword() { if (credentialSourceSupplier != null) { try { return new String( credentialSourceSupplier.get().getCredential(PasswordCredential.class).getPassword(ClearPassword.class).getPassword()); } catch (Exception e) { throw ConnectorLogger.DEPLOYMENT_CONNECTOR_LOGGER.invalidCredentialSourceSupplier(e); } } return this.password; }
private char[] resolvePassword() throws Exception { ExceptionSupplier<CredentialSource, Exception> sourceSupplier = credentialSourceSupplier.getValue(); CredentialSource cs = sourceSupplier != null ? sourceSupplier.get() : null; String path = resolvedPath != null ? resolvedPath.getPath() : "null"; if (cs == null) throw ROOT_LOGGER.keyStorePasswordCannotBeResolved(path); PasswordCredential credential = cs.getCredential(PasswordCredential.class); if (credential == null) throw ROOT_LOGGER.keyStorePasswordCannotBeResolved(path); ClearPassword password = credential.getPassword(ClearPassword.class); if (password == null) throw ROOT_LOGGER.keyStorePasswordCannotBeResolved(path); return password.getPassword(); }