Search in sources :

Example 1 with DigestRealm

use of com.sun.enterprise.security.ee.auth.realm.DigestRealm in project Payara by payara.

the class DigestLoginModule method login.

public final boolean login() throws LoginException {
    Set<Object> creds = this.subject.getPrivateCredentials();
    Iterator<Object> itr = creds.iterator();
    while (itr.hasNext()) {
        Object obj = itr.next();
        if (obj instanceof DigestCredentials) {
            digestCredentials = (DigestCredentials) obj;
            break;
        } else if (obj instanceof com.sun.enterprise.security.auth.login.DigestCredentials) {
            com.sun.enterprise.security.auth.login.DigestCredentials dc = (com.sun.enterprise.security.auth.login.DigestCredentials) obj;
            digestCredentials = new DigestCredentials(dc.getRealmName(), dc.getUserName(), dc.getParameters());
        }
    }
    if (digestCredentials == null) {
        throw new LoginException();
    }
    DigestAlgorithmParameter[] params = digestCredentials.getParameters();
    String username = digestCredentials.getUserName();
    try {
        _realm = Realm.getInstance(digestCredentials.getRealmName());
    } catch (NoSuchRealmException ex) {
        _logger.log(Level.FINE, "", ex);
        _logger.log(Level.SEVERE, "no.realm", digestCredentials.getRealmName());
        throw new LoginException(ex.getMessage());
    }
    if (_realm instanceof DigestRealm) {
        if (((DigestRealm) _realm).validate(username, params)) {
            // change to pass Password Validator
            _succeeded = true;
        }
    } else {
        _logger.log(Level.SEVERE, "digest.realm", digestCredentials.getRealmName());
        throw new LoginException("Realm" + digestCredentials.getRealmName() + " does not support Digest validation");
    }
    return _succeeded;
}
Also used : DigestRealm(com.sun.enterprise.security.ee.auth.realm.DigestRealm) DigestAlgorithmParameter(com.sun.enterprise.security.auth.digest.api.DigestAlgorithmParameter) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) LoginException(javax.security.auth.login.LoginException)

Aggregations

DigestAlgorithmParameter (com.sun.enterprise.security.auth.digest.api.DigestAlgorithmParameter)1 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)1 DigestRealm (com.sun.enterprise.security.ee.auth.realm.DigestRealm)1 LoginException (javax.security.auth.login.LoginException)1