Search in sources :

Example 1 with DigestPassword

use of org.wildfly.security.password.interfaces.DigestPassword in project wildfly by wildfly.

the class RealmDirectLoginModule method getUsersPassword.

/**
     * @see org.jboss.security.auth.spi.UsernamePasswordLoginModule#getUsersPassword()
     */
@Override
protected String getUsersPassword() throws LoginException {
    if (validationMode == ValidationMode.VALIDATION) {
        return null;
    }
    RealmCallback rcb = new RealmCallback("Realm", securityRealm.getName());
    NameCallback ncb = new NameCallback("User Name", getUsername());
    String password = null;
    switch(validationMode) {
        case DIGEST:
            CredentialCallback cc = new CredentialCallback(PasswordCredential.class, ALGORITHM_DIGEST_MD5);
            handle(new Callback[] { rcb, ncb, cc });
            PasswordCredential passwordCredential = (PasswordCredential) cc.getCredential();
            DigestPassword digestPassword = passwordCredential.getPassword(DigestPassword.class);
            password = ByteIterator.ofBytes(digestPassword.getDigest()).hexEncode().drainToString();
            break;
        case PASSWORD:
            PasswordCallback pcb = new PasswordCallback("Password", false);
            handle(new Callback[] { rcb, ncb, pcb });
            password = String.valueOf(pcb.getPassword());
            break;
    }
    return password;
}
Also used : DigestPassword(org.wildfly.security.password.interfaces.DigestPassword) NameCallback(javax.security.auth.callback.NameCallback) PasswordCredential(org.wildfly.security.credential.PasswordCredential) PasswordCallback(javax.security.auth.callback.PasswordCallback) CredentialCallback(org.wildfly.security.auth.callback.CredentialCallback) RealmCallback(javax.security.sasl.RealmCallback)

Aggregations

NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1 RealmCallback (javax.security.sasl.RealmCallback)1 CredentialCallback (org.wildfly.security.auth.callback.CredentialCallback)1 PasswordCredential (org.wildfly.security.credential.PasswordCredential)1 DigestPassword (org.wildfly.security.password.interfaces.DigestPassword)1