Search in sources :

Example 1 with AuthSubject

use of com.sun.identity.authentication.internal.AuthSubject in project OpenAM by OpenRock.

the class SpecialRepo method authenticate.

public boolean authenticate(Callback[] credentials) throws IdRepoException, AuthLoginException {
    debug.message("SpecialRepo:authenticate called");
    // Obtain user name and password from credentials and authenticate
    String username = null;
    String password = null;
    for (int i = 0; i < credentials.length; i++) {
        if (credentials[i] instanceof NameCallback) {
            username = ((NameCallback) credentials[i]).getName();
            if (debug.messageEnabled()) {
                debug.message("SpecialRepo:authenticate username: " + username);
            }
        } else if (credentials[i] instanceof PasswordCallback) {
            char[] passwd = ((PasswordCallback) credentials[i]).getPassword();
            if (passwd != null) {
                password = new String(passwd);
                debug.message("SpecialRepo:authN passwd present");
            }
        }
    }
    if (username == null || password == null) {
        return (false);
    }
    Map sharedState = new HashMap();
    sharedState.put(ISAuthConstants.SHARED_STATE_USERNAME, username);
    sharedState.put(ISAuthConstants.SHARED_STATE_PASSWORD, password);
    debug.message("SpecialRepo:authenticate inst. SMSAuthModule");
    SMSAuthModule module = new SMSAuthModule();
    debug.message("SpecialRepo:authenticate SMSAuthModule:init");
    module.initialize(new AuthSubject(), null, sharedState, Collections.EMPTY_MAP);
    boolean answer = false;
    try {
        answer = module.login();
        if (debug.messageEnabled()) {
            debug.message("SpecialRepo:authenticate login: " + answer);
        }
    } catch (LoginException le) {
        if (debug.warningEnabled()) {
            debug.warning("authentication: login exception", le);
        }
        if (le instanceof AuthLoginException) {
            throw ((AuthLoginException) le);
        }
    }
    return (answer);
}
Also used : SMSAuthModule(com.sun.identity.authentication.internal.server.SMSAuthModule) NameCallback(javax.security.auth.callback.NameCallback) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) AuthSubject(com.sun.identity.authentication.internal.AuthSubject) PasswordCallback(javax.security.auth.callback.PasswordCallback) LoginException(javax.security.auth.login.LoginException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Aggregations

AuthSubject (com.sun.identity.authentication.internal.AuthSubject)1 SMSAuthModule (com.sun.identity.authentication.internal.server.SMSAuthModule)1 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1 LoginException (javax.security.auth.login.LoginException)1