/** * Cast this password type if the type matches. * * @param passwordType the password type class to check * @param <P> the password type * @return the password cast as the target type, or {@code null} if the password does not match the criteria */ default <P extends Password> P castAs(Class<P> passwordType) { return castAndApply(passwordType, Function.identity()); }
/** * Cast this password type if the type and algorithm matches. * * @param passwordType the password type class to check * @param algorithmName the name of the algorithm or {@code null} if any algorithm is acceptable * @param <P> the password type * @return the password cast as the target type, or {@code null} if the password does not match the criteria */ default <P extends Password> P castAs(Class<P> passwordType, String algorithmName) { return castAndApply(passwordType, algorithmName, Function.identity()); }
private static char[] getStorePassword(final CredentialStore.ProtectionParameter protectionParameter) throws IOException, CredentialStoreException { final char[] password; if (protectionParameter instanceof CredentialStore.CredentialSourceProtectionParameter) { password = ((CredentialStore.CredentialSourceProtectionParameter) protectionParameter).getCredentialSource().applyToCredential(PasswordCredential.class, c -> c.getPassword().castAndApply(ClearPassword.class, ClearPassword::getPassword)); } else if (protectionParameter != null) { throw log.invalidProtectionParameter(protectionParameter); } else { password = null; } return password; }
public void store(final String credentialAlias, final Credential credential, final CredentialStore.ProtectionParameter protectionParameter) throws CredentialStoreException, UnsupportedCredentialTypeException { if (! modifiable) { throw log.nonModifiableCredentialStore("store"); } if (protectionParameter != null) { throw log.invalidProtectionParameter(protectionParameter); } // Vault can only store clear passwords; let's check out the type first. final char[] chars = credential.castAndApply(PasswordCredential.class, c -> c.getPassword().castAndApply(ClearPassword.class, ClearPassword::getPassword)); if (chars == null) { throw log.unsupportedCredentialType(credential.getClass()); } byte[] encoded; try { final Cipher cipher = Cipher.getInstance(adminKey.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE, adminKey); encoded = cipher.doFinal(CodePointIterator.ofChars(chars).asUtf8().drain()); } catch (NoSuchAlgorithmException | IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException | InvalidKeyException e) { throw log.cannotWriteCredentialToStore(e); } synchronized (data) { data.put(credentialAlias, encoded); } }
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); } }
c -> c.getPassword().castAndApply(DigestPassword.class, DigestPassword::getDigest) ); } catch (UnsupportedCallbackException e) {
throw new ConfigXMLParseException(xmlLog.couldNotObtainCredential(), reader); char[] pass = passwordCredential.getPassword().castAndApply(ClearPassword.class, ClearPassword::getPassword); if (pass == null) { throw new ConfigXMLParseException(xmlLog.couldNotObtainCredential(), reader);
throw new ConfigXMLParseException(xmlLog.couldNotObtainCredential(), reader); char[] pass = passwordCredential.getPassword().castAndApply(ClearPassword.class, ClearPassword::getPassword); if (pass == null) { throw new ConfigXMLParseException(xmlLog.couldNotObtainCredential(), reader);
try { return credentialSourceSupplier.get().applyToCredential(PasswordCredential.class, c -> c.getPassword().castAndApply(ClearPassword.class, ClearPassword::getPassword)); } catch (IOException e) { throw xmlLog.xmlFailedToCreateCredential(nestedLocation, e);
/** * Cast this password type if the type and algorithm matches. * * @param passwordType the password type class to check * @param algorithmName the name of the algorithm or {@code null} if any algorithm is acceptable * @param <P> the password type * @return the password cast as the target type, or {@code null} if the password does not match the criteria */ default <P extends Password> P castAs(Class<P> passwordType, String algorithmName) { return castAndApply(passwordType, algorithmName, Function.identity()); }
/** * Cast this password type if the type matches. * * @param passwordType the password type class to check * @param <P> the password type * @return the password cast as the target type, or {@code null} if the password does not match the criteria */ default <P extends Password> P castAs(Class<P> passwordType) { return castAndApply(passwordType, Function.identity()); }
/** * Cast this password type if the type matches. * * @param passwordType the password type class to check * @param <P> the password type * @return the password cast as the target type, or {@code null} if the password does not match the criteria */ default <P extends Password> P castAs(Class<P> passwordType) { return castAndApply(passwordType, Function.identity()); }
/** * Cast this password type if the type and algorithm matches. * * @param passwordType the password type class to check * @param algorithmName the name of the algorithm or {@code null} if any algorithm is acceptable * @param <P> the password type * @return the password cast as the target type, or {@code null} if the password does not match the criteria */ default <P extends Password> P castAs(Class<P> passwordType, String algorithmName) { return castAndApply(passwordType, algorithmName, Function.identity()); }
/** * Cast this password type if the type and algorithm matches. * * @param passwordType the password type class to check * @param algorithmName the name of the algorithm or {@code null} if any algorithm is acceptable * @param <P> the password type * @return the password cast as the target type, or {@code null} if the password does not match the criteria */ default <P extends Password> P castAs(Class<P> passwordType, String algorithmName) { return castAndApply(passwordType, algorithmName, Function.identity()); }
/** * Cast this password type if the type matches. * * @param passwordType the password type class to check * @param <P> the password type * @return the password cast as the target type, or {@code null} if the password does not match the criteria */ default <P extends Password> P castAs(Class<P> passwordType) { return castAndApply(passwordType, Function.identity()); }
private static char[] getStorePassword(final CredentialStore.ProtectionParameter protectionParameter) throws IOException, CredentialStoreException { final char[] password; if (protectionParameter instanceof CredentialStore.CredentialSourceProtectionParameter) { password = ((CredentialStore.CredentialSourceProtectionParameter) protectionParameter).getCredentialSource().applyToCredential(PasswordCredential.class, c -> c.getPassword().castAndApply(ClearPassword.class, ClearPassword::getPassword)); } else if (protectionParameter != null) { throw log.invalidProtectionParameter(protectionParameter); } else { password = null; } return password; }
private static char[] getStorePassword(final CredentialStore.ProtectionParameter protectionParameter) throws IOException, CredentialStoreException { final char[] password; if (protectionParameter instanceof CredentialStore.CredentialSourceProtectionParameter) { password = ((CredentialStore.CredentialSourceProtectionParameter) protectionParameter).getCredentialSource().applyToCredential(PasswordCredential.class, c -> c.getPassword().castAndApply(ClearPassword.class, ClearPassword::getPassword)); } else if (protectionParameter != null) { throw log.invalidProtectionParameter(protectionParameter); } else { password = null; } return password; }
private static char[] getStorePassword(final CredentialStore.ProtectionParameter protectionParameter) throws IOException, CredentialStoreException { final char[] password; if (protectionParameter instanceof CredentialStore.CredentialSourceProtectionParameter) { password = ((CredentialStore.CredentialSourceProtectionParameter) protectionParameter).getCredentialSource().applyToCredential(PasswordCredential.class, c -> c.getPassword().castAndApply(ClearPassword.class, ClearPassword::getPassword)); } else if (protectionParameter != null) { throw log.invalidProtectionParameter(protectionParameter); } else { password = null; } return password; }
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); } }
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); } }