public String getAlgorithm() { return password.getAlgorithm(); }
/** * 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()); }
/** * Get the password if it is of the given type; otherwise return {@code null}. * * @param type the password type class * @param <P> the password type * @return the password, or {@code null} if the password is not of the given type */ public <P extends Password> P getPassword(Class<P> type) { return getPassword().castAs(type); }
if (entry instanceof PasswordEntry) try { final Password password = ((PasswordEntry) entry).getPassword(); final PasswordFactory passwordFactory1 = PasswordFactory.getInstance(password.getAlgorithm(), providersSupplier); final ClearPasswordSpec passwordSpec = passwordFactory1.getKeySpec(password, ClearPasswordSpec.class); return passwordSpec.getEncodedPassword(); try { return credentialSourceSupplier.get().applyToCredential(PasswordCredential.class, c -> c.getPassword().castAndApply(ClearPassword.class, ClearPassword::getPassword)); } catch (IOException e) { throw xmlLog.xmlFailedToCreateCredential(nestedLocation, e);
public boolean supportsParameters(final Class<? extends AlgorithmParameterSpec> paramSpecClass) { return paramSpecClass.isInstance(password.getParameterSpec()); }
public PasswordCredential clone() { final Password password = this.password; final Password clone = password.clone(); return clone == password ? this : new PasswordCredential(clone); }
public boolean impliesParameters(final AlgorithmParameterSpec parameterSpec) { Assert.checkNotNullParam("parameterSpec", parameterSpec); return password.impliesParameters(parameterSpec); }
public <P extends AlgorithmParameterSpec> P getParameters(final Class<P> paramSpecClass) { final AlgorithmParameterSpec parameterSpec = password.getParameterSpec(); return paramSpecClass.isInstance(parameterSpec) ? paramSpecClass.cast(parameterSpec) : null; }
public PasswordCredential clone() { final Password password = this.password; final Password clone = password.clone(); return clone == password ? this : new PasswordCredential(clone); }
public boolean impliesParameters(final AlgorithmParameterSpec parameterSpec) { Assert.checkNotNullParam("parameterSpec", parameterSpec); return password.impliesParameters(parameterSpec); }
/** * Cast this password type and apply a function if the type 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 function the function to apply * @param <P> the password type * @param <R> the return type * @return the result of the function, or {@code null} if the password is not of the given type */ default <P extends Password, R> R castAndApply(Class<P> passwordType, String algorithmName, Function<P, R> function) { return passwordType.isInstance(this) && (algorithmName == null || algorithmName.equals(getAlgorithm())) ? function.apply(passwordType.cast(this)) : null; }
/** * 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()); }
try { callbackHandler.handle(new Callback[] { nameCallback, credentialCallback }); final TwoWayPassword twoWayPassword = credentialCallback.applyToCredential(PasswordCredential.class, c -> c.getPassword().castAs(TwoWayPassword.class)); if (twoWayPassword == null) { return null;
public boolean impliesSameParameters(final AlgorithmCredential other) { Assert.checkNotNullParam("other", other); return Objects.equals(password.getParameterSpec(), other.getParameters()); }
public PasswordCredential clone() { final Password password = this.password; final Password clone = password.clone(); return clone == password ? this : new PasswordCredential(clone); }
public boolean impliesParameters(final AlgorithmParameterSpec parameterSpec) { Assert.checkNotNullParam("parameterSpec", parameterSpec); return password.impliesParameters(parameterSpec); }
return (password instanceof SunUnixMD5CryptPassword && algorithm.equals(password.getAlgorithm())); return (password instanceof UnixSHACryptPassword && algorithm.equals(password.getAlgorithm())); case ALGORITHM_DIGEST_SHA_384: case ALGORITHM_DIGEST_SHA_512:{ return (password instanceof DigestPassword && algorithm.equals(password.getAlgorithm())); case ALGORITHM_SIMPLE_DIGEST_SHA_384: case ALGORITHM_SIMPLE_DIGEST_SHA_512: { return (password instanceof SimpleDigestPassword && algorithm.equals(password.getAlgorithm())); case ALGORITHM_SALT_PASSWORD_DIGEST_SHA_384: case ALGORITHM_SALT_PASSWORD_DIGEST_SHA_512: { return (password instanceof SaltedSimpleDigestPassword && algorithm.equals(password.getAlgorithm())); return (password instanceof ScramDigestPassword && algorithm.equals(password.getAlgorithm())); case ALGORITHM_OTP_SHA_384: case ALGORITHM_OTP_SHA_512: { return (password instanceof OneTimePassword && algorithm.equals(password.getAlgorithm())); return MaskedPassword.isMaskedAlgorithm(algorithm) && password instanceof MaskedPassword && algorithm.equals(password.getAlgorithm());
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; }
c -> c.getPassword().castAs(TwoWayPassword.class) ); if (password != null) {
/** * Attempt to acquire parameters of the given type from the given key. * * @param key the key (must not be {@code null}) * @param paramSpecClass the parameter specification class (must not be {@code null}) * @param <P> the parameter specification type * @return the parameters, or {@code null} if no known parameters of the given type are available */ public static <P extends AlgorithmParameterSpec> P getParameters(Key key, Class<P> paramSpecClass) { if (key instanceof Password) { final AlgorithmParameterSpec parameterSpec = ((Password) key).getParameterSpec(); return paramSpecClass.isInstance(parameterSpec) ? paramSpecClass.cast(parameterSpec) : null; } else if (key instanceof RSAKey && paramSpecClass.isAssignableFrom(RSAParameterSpec.class)) { return paramSpecClass.cast(new RSAParameterSpec((RSAKey) key)); } else if (key instanceof DSAKey && paramSpecClass.isAssignableFrom(DSAParams.class)) { return paramSpecClass.cast(((DSAKey) key).getParams()); } else if (key instanceof ECKey && paramSpecClass.isAssignableFrom(ECParameterSpec.class)) { return paramSpecClass.cast(((ECKey) key).getParams()); } else if (key instanceof DHKey && paramSpecClass.isAssignableFrom(DHParameterSpec.class)) { return paramSpecClass.cast(((DHKey) key).getParams()); } else if (key instanceof PBEKey && paramSpecClass.isAssignableFrom(PBEParameterSpec.class)) { final PBEKey pbeKey = (PBEKey) key; final byte[] salt = pbeKey.getSalt(); // TODO: we miss the IV here return salt == null ? null : paramSpecClass.cast(new PBEParameterSpec(salt, pbeKey.getIterationCount())); } else { return null; } }