private static Password createClearPassword(int skip, byte[] userPassword) { if (skip != 0) userPassword = Arrays.copyOfRange(userPassword, skip, userPassword.length); return ClearPassword.createRaw(ALGORITHM_CLEAR, new String(userPassword, StandardCharsets.UTF_8).toCharArray()); }
private static Password decoded(final SecretKey key) { return ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, new String(key.getEncoded(), StandardCharsets.UTF_8).toCharArray()); }
/** * Create a new configuration which is the same as this configuration, but which uses the given password to authenticate. * * @param password the password to use * @return the new configuration */ public AuthenticationConfiguration usePassword(char[] password) { return usePassword(password == null ? null : ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password)); }
/** * Create a new configuration which is the same as this configuration, but which uses the given password to authenticate. * * @param password the password to use * @return the new configuration */ public AuthenticationConfiguration usePassword(String password) { return usePassword(password == null ? null : ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password.toCharArray())); }
Object writeReplace() { return ClearPassword.createRaw(getAlgorithm(), password); }
public <C extends Credential> C getCredential(final Class<C> credentialType, final String algorithmName, final AlgorithmParameterSpec parameterSpec) throws IOException { if (PasswordCredential.class.isAssignableFrom(credentialType) && (algorithmName == null || algorithmName.equals(ClearPassword.ALGORITHM_CLEAR)) && parameterSpec == null) { try { final PasswordCallback passwordCallback = new PasswordCallback("Password", false); callbackHandler.handle(new Callback[] { passwordCallback }); final char[] chars = passwordCallback.getPassword(); return chars == null ? null : credentialType.cast(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, chars))); } catch (UnsupportedCallbackException e) { // fall out and try CredentialCallback } } try { final CredentialCallback credentialCallback = new CredentialCallback(credentialType, algorithmName, parameterSpec); callbackHandler.handle(new Callback[] { credentialCallback }); return credentialCallback.getCredential(credentialType, algorithmName, parameterSpec); } catch (UnsupportedCallbackException e) { // no credentials can be acquired; fall out } return null; } }
public <C extends Credential> C retrieve(final String credentialAlias, final Class<C> credentialType, final String credentialAlgorithm, final AlgorithmParameterSpec parameterSpec, final CredentialStore.ProtectionParameter protectionParameter) throws CredentialStoreException { if (protectionParameter != null) { throw log.invalidProtectionParameter(protectionParameter); } if (! credentialType.isAssignableFrom(PasswordCredential.class)) { return null; } if (credentialAlgorithm != null && ! credentialAlgorithm.equals(ClearPassword.ALGORITHM_CLEAR)) { return null; } if (parameterSpec != null) { return null; } final byte[] bytes; synchronized (data) { bytes = data.get(credentialAlias); } // decode final byte[] decoded; try { final Cipher cipher = Cipher.getInstance(adminKey.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, adminKey); decoded = cipher.doFinal(bytes); } catch (NoSuchAlgorithmException | IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException | InvalidKeyException e) { throw log.cannotAcquireCredentialFromStore(e); } return credentialType.cast(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, new String(decoded, StandardCharsets.UTF_8).toCharArray()))); }
return credentialType.cast(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, line.toCharArray()))); } finally {
private static IdentityCredentials getSingleCredential(Object rawCredential) { if (rawCredential == null) { return IdentityCredentials.NONE; } else if (rawCredential instanceof Credential) { return IdentityCredentials.NONE.withCredential((Credential) rawCredential); } else if (rawCredential instanceof GSSCredential) { return IdentityCredentials.NONE.withCredential(new GSSKerberosCredential((GSSCredential) rawCredential)); } else if (rawCredential instanceof Password) { return IdentityCredentials.NONE.withCredential(new PasswordCredential((Password) rawCredential)); } else if (rawCredential instanceof X509Certificate) { return IdentityCredentials.NONE.withCredential(new X509CertificateChainPublicCredential((X509Certificate) rawCredential)); } else if (rawCredential instanceof X509Certificate[]) { return IdentityCredentials.NONE.withCredential(new X509CertificateChainPublicCredential((X509Certificate[]) rawCredential)); } else if (rawCredential instanceof X500PrivateCredential) { final X500PrivateCredential credential = (X500PrivateCredential) rawCredential; return IdentityCredentials.NONE.withCredential(new X509CertificateChainPrivateCredential(credential.getPrivateKey(), credential.getCertificate())); } else if (rawCredential instanceof String) { return IdentityCredentials.NONE.withCredential(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, ((String) rawCredential).toCharArray()))); } else if (rawCredential instanceof char[]) { // todo: automatically decode to other credential types return IdentityCredentials.NONE.withCredential(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, (char[]) rawCredential))); } else if (rawCredential instanceof byte[]) { // todo: automatically decode to other credential types return IdentityCredentials.NONE.withCredential(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, new String((byte[]) rawCredential, StandardCharsets.UTF_8).toCharArray()))); } else { return IdentityCredentials.NONE; } }
IdentityCredentialCallback credentialUpdateCallback = new IdentityCredentialCallback(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password)), true); callbackHandler.handle(new Callback[]{credentialUpdateCallback}); return true;
if (evidence instanceof PasswordGuessEvidence) { PasswordGuessEvidence passwordGuessEvidence = PasswordGuessEvidence.class.cast(evidence); serverAuthenticationContext.addPrivateCredential(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, passwordGuessEvidence.getGuess()))); } else if (evidence instanceof BearerTokenEvidence) { BearerTokenEvidence tokenEvidence = BearerTokenEvidence.class.cast(evidence);
callbackHandler.handle(new Callback[] { new IdentityCredentialCallback(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password.toCharArray())), true) } ); } catch (UnsupportedCallbackException e) {
@Override public boolean verifyEvidence(Evidence evidence) throws RealmUnavailableException { if (evidence instanceof PasswordGuessEvidence) { if (credentials.canVerify(evidence)) { log.tracef("verifyEvidence For principal='%s' using cached credential", principal); return credentials.verify(evidence); } Credential credential = identity.getCredential(PasswordCredential.class); if (credential != null) { log.tracef("verifyEvidence Credential obtained from identity and cached for principal='%s'", principal); credentials = credentials.withCredential(credential); if (credential.canVerify(evidence)) { return credential.verify(evidence); } } char[] guess = ((PasswordGuessEvidence) evidence).getGuess(); Password password = ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, guess); log.tracef("verifyEvidence Falling back to direct support of identity for principal='%s'", principal); if (identity.verifyEvidence(evidence)) { credentials = credentials.withCredential(new PasswordCredential(password)); return true; } return false; } return identity.verifyEvidence(evidence); }
return new CredentialStoreCredentialSource(credentialStore, finalAlias); } else { final PasswordCredential passwordCredential = new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, finalClearText.toCharArray())); return IdentityCredentials.NONE.withCredential(passwordCredential);
/** * Create a new configuration which is the same as this configuration, but which uses the given password to authenticate. * * @param password the password to use * @return the new configuration */ public AuthenticationConfiguration usePassword(String password) { return usePassword(password == null ? null : ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password.toCharArray())); }
/** * Create a new configuration which is the same as this configuration, but which uses the given password to authenticate. * * @param password the password to use * @return the new configuration */ public AuthenticationConfiguration usePassword(char[] password) { return usePassword(password == null ? null : ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password)); }
/** * Create a new configuration which is the same as this configuration, but which uses the given password to authenticate. * * @param password the password to use * @return the new configuration */ public AuthenticationConfiguration usePassword(char[] password) { return usePassword(password == null ? null : ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password)); }
/** * Create a new configuration which is the same as this configuration, but which uses the given password to authenticate. * * @param password the password to use * @return the new configuration */ public AuthenticationConfiguration usePassword(char[] password) { return usePassword(password == null ? null : ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password)); }
/** * Create a new configuration which is the same as this configuration, but which uses the given password to authenticate. * * @param password the password to use * @return the new configuration */ public AuthenticationConfiguration usePassword(String password) { return usePassword(password == null ? null : ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password.toCharArray())); }
/** * Create a new configuration which is the same as this configuration, but which uses the given password to authenticate. * * @param password the password to use * @return the new configuration */ public AuthenticationConfiguration usePassword(String password) { return usePassword(password == null ? null : ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, password.toCharArray())); }