Search in sources :

Example 1 with DigestPasswordAlgorithmSpec

use of org.wildfly.security.password.spec.DigestPasswordAlgorithmSpec in project wildfly-swarm by wildfly-swarm.

the class AuthCallbackHandler method handle.

@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (Callback current : callbacks) {
        if (current instanceof NameCallback) {
            NameCallback ncb = (NameCallback) current;
            ncb.setName(this.userName);
        } else if (current instanceof RealmCallback) {
            RealmCallback rcb = (RealmCallback) current;
            rcb.setText(rcb.getDefaultText());
        } else if (current instanceof CredentialCallback) {
            CredentialCallback ccb = (CredentialCallback) current;
            try {
                DigestPasswordAlgorithmSpec algoSpec = new DigestPasswordAlgorithmSpec(this.userName, this.realm);
                EncryptablePasswordSpec passwordSpec = new EncryptablePasswordSpec(this.password.toCharArray(), algoSpec);
                Password passwd = PasswordFactory.getInstance(ALGORITHM_DIGEST_MD5).generatePassword(passwordSpec);
                Credential creds = new PasswordCredential(passwd);
                ccb.setCredential(creds);
            } catch (InvalidKeySpecException e) {
                e.printStackTrace();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
        } else if (current instanceof PasswordCallback) {
            PasswordCallback pcb = (PasswordCallback) current;
            pcb.setPassword(this.password.toCharArray());
        } else {
            throw new UnsupportedCallbackException(current);
        }
    }
}
Also used : PasswordCredential(org.wildfly.security.credential.PasswordCredential) Credential(org.wildfly.security.credential.Credential) PasswordCredential(org.wildfly.security.credential.PasswordCredential) CredentialCallback(org.wildfly.security.auth.callback.CredentialCallback) EncryptablePasswordSpec(org.wildfly.security.password.spec.EncryptablePasswordSpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) RealmCallback(javax.security.sasl.RealmCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) CredentialCallback(org.wildfly.security.auth.callback.CredentialCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) DigestPasswordAlgorithmSpec(org.wildfly.security.password.spec.DigestPasswordAlgorithmSpec) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) RealmCallback(javax.security.sasl.RealmCallback) Password(org.wildfly.security.password.Password)

Aggregations

NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 Callback (javax.security.auth.callback.Callback)1 NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 RealmCallback (javax.security.sasl.RealmCallback)1 CredentialCallback (org.wildfly.security.auth.callback.CredentialCallback)1 Credential (org.wildfly.security.credential.Credential)1 PasswordCredential (org.wildfly.security.credential.PasswordCredential)1 Password (org.wildfly.security.password.Password)1 DigestPasswordAlgorithmSpec (org.wildfly.security.password.spec.DigestPasswordAlgorithmSpec)1 EncryptablePasswordSpec (org.wildfly.security.password.spec.EncryptablePasswordSpec)1