Search in sources :

Example 56 with Callback

use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.

the class AMLoginModule method clearInfoText.

/**
     * Clears the info text for a given callback state
     * 
     * @param state The state to clear all infotexts
     * @throws AuthLoginException Invalid state
     * @supported.api
     */
public void clearInfoText(int state) throws AuthLoginException {
    if (debug.messageEnabled()) {
        debug.message("clearInfoText : state=" + state);
    }
    // check state length
    if (state > stateLength) {
        throw new AuthLoginException(bundleName, "invalidState", new Object[] { new Integer(state) });
    }
    // check callback length for the state
    Callback[] ext = getCallback(state);
    if (ext.length <= 0) {
        throw new AuthLoginException(bundleName, "invalidCallbackIndex", null);
    }
    // in internal, first Callback is always PagePropertiesCallback
    PagePropertiesCallback pc = (PagePropertiesCallback) ((Callback[]) internal.get(state - 1))[0];
    // clear info text
    List<String> infoTexts = pc.getInfoText();
    for (int i = 0; i < infoTexts.size(); i++) {
        infoTexts.set(i, EMPTY_STRING);
    }
    pc.setInfoText(infoTexts);
}
Also used : HiddenValueCallback(com.sun.identity.authentication.callbacks.HiddenValueCallback) ScriptTextOutputCallback(com.sun.identity.authentication.callbacks.ScriptTextOutputCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) TextInputCallback(javax.security.auth.callback.TextInputCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) LoginStateCallback(com.sun.identity.authentication.service.LoginStateCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) SessionConstraint(com.iplanet.dpro.session.service.SessionConstraint)

Example 57 with Callback

use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.

the class AMLoginModule method getInfoText.

/**
     * Returns the info text associated with a specific callback
     * 
     * @param state The state to fetch the info text
     * @param index The callback to fetch the info text
     * @return The info text
     * @supported.api
     */
public String getInfoText(int state, int index) {
    // check state
    if (state > stateLength) {
        // invalid state, return empty string now
        return EMPTY_STRING;
    }
    // get internal callbacks for the state
    Callback[] callbacks = (Callback[]) internal.get(state - 1);
    if (callbacks == null || callbacks.length == 0) {
        // no callbacks defined for this state, return empty string
        return EMPTY_STRING;
    }
    // check first Callback
    Callback callback = callbacks[0];
    if (callback instanceof PagePropertiesCallback) {
        List<String> infoText = ((PagePropertiesCallback) callback).getAttribute();
        if (infoText == null || infoText.isEmpty() || index >= infoText.size()) {
            return EMPTY_STRING;
        } else {
            return infoText.get(index);
        }
    } else {
        return EMPTY_STRING;
    }
}
Also used : HiddenValueCallback(com.sun.identity.authentication.callbacks.HiddenValueCallback) ScriptTextOutputCallback(com.sun.identity.authentication.callbacks.ScriptTextOutputCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) TextInputCallback(javax.security.auth.callback.TextInputCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) LoginStateCallback(com.sun.identity.authentication.service.LoginStateCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback)

Example 58 with Callback

use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.

the class AMLoginModule method getLoginState.

/*
     * Returns the Login State object
     * @return com.sun.identity.authentication.service.LoginState
     */
private com.sun.identity.authentication.service.LoginState getLoginState() {
    Callback[] callbacks = new Callback[1];
    try {
        callbacks[0] = new LoginStateCallback();
        if (handler == null) {
            return null;
        }
        handler.handle(callbacks);
        return ((LoginStateCallback) callbacks[0]).getLoginState();
    } catch (Exception e) {
        debug.message("Error..", e);
        return null;
    }
}
Also used : HiddenValueCallback(com.sun.identity.authentication.callbacks.HiddenValueCallback) ScriptTextOutputCallback(com.sun.identity.authentication.callbacks.ScriptTextOutputCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) TextInputCallback(javax.security.auth.callback.TextInputCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) LoginStateCallback(com.sun.identity.authentication.service.LoginStateCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) LoginStateCallback(com.sun.identity.authentication.service.LoginStateCallback) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) SSOException(com.iplanet.sso.SSOException) IdRepoException(com.sun.identity.idm.IdRepoException) IOException(java.io.IOException) AMException(com.iplanet.am.sdk.AMException) AuthException(com.sun.identity.authentication.service.AuthException)

Example 59 with Callback

use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.

the class AMLoginModule method getAttribute.

/**
     * Returns the attribute name for the specified callback in the
     * specified login state.
     *
     * @param state Order of state
     * @param index Order of the Callback in the Callback[], the index
     *        starts with 0.
     * @return Name of the attribute, empty string will be returned
     *         if the attribute is not defined.
     * @supported.api
     */
public String getAttribute(int state, int index) {
    // check state
    if (state > stateLength) {
        // invalid state, return empty string now
        return EMPTY_STRING;
    }
    // get internal callbacks for the state
    Callback[] callbacks = (Callback[]) internal.get(state - 1);
    if (callbacks == null || callbacks.length == 0) {
        // no callbacks defined for this state, return empty string
        return EMPTY_STRING;
    }
    // check first Callback
    Callback callback = callbacks[0];
    if (callback instanceof PagePropertiesCallback) {
        List req = ((PagePropertiesCallback) callback).getAttribute();
        if (req == null || req.isEmpty() || index >= req.size()) {
            return EMPTY_STRING;
        } else {
            return (String) req.get(index);
        }
    } else {
        return EMPTY_STRING;
    }
}
Also used : HiddenValueCallback(com.sun.identity.authentication.callbacks.HiddenValueCallback) ScriptTextOutputCallback(com.sun.identity.authentication.callbacks.ScriptTextOutputCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) TextInputCallback(javax.security.auth.callback.TextInputCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) LoginStateCallback(com.sun.identity.authentication.service.LoginStateCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) List(java.util.List) ArrayList(java.util.ArrayList)

Example 60 with Callback

use of javax.security.auth.callback.Callback in project alluxio by Alluxio.

the class PlainSaslServer method evaluateResponse.

@Override
public byte[] evaluateResponse(byte[] response) throws SaslException {
    Preconditions.checkState(!mCompleted, "PLAIN authentication has completed");
    Preconditions.checkArgument(response != null, "Received null response");
    try {
        // parse the response
        // message = [authorizationId] UTF8NUL authenticationId UTF8NUL passwd'
        // authorizationId may be empty,then the authorizationId = authenticationId
        String payload;
        try {
            payload = new String(response, "UTF-8");
        } catch (Exception e) {
            throw new IllegalArgumentException("Received corrupt response", e);
        }
        String[] parts = payload.split("", 3);
        // validate response
        if (parts.length != 3) {
            throw new IllegalArgumentException("Invalid message format, parts must contain 3 items");
        }
        String authorizationId = parts[0];
        String authenticationId = parts[1];
        String passwd = parts[2];
        Preconditions.checkState(authenticationId != null && !authenticationId.isEmpty(), "No authentication identity provided");
        Preconditions.checkState(passwd != null && !passwd.isEmpty(), "No password provided");
        if (authorizationId == null || authorizationId.isEmpty()) {
            authorizationId = authenticationId;
        } else if (!authorizationId.equals(authenticationId)) {
            // TODO(dong): support impersonation
            throw new UnsupportedOperationException("Impersonation is not supported now.");
        }
        NameCallback nameCallback = new NameCallback("User");
        nameCallback.setName(authenticationId);
        PasswordCallback passwordCallback = new PasswordCallback("Password", false);
        passwordCallback.setPassword(passwd.toCharArray());
        AuthorizeCallback authCallback = new AuthorizeCallback(authenticationId, authorizationId);
        Callback[] cbList = { nameCallback, passwordCallback, authCallback };
        mHandler.handle(cbList);
        if (!authCallback.isAuthorized()) {
            throw new SaslException("AuthorizeCallback authorized failure");
        }
        mAuthorizationId = authCallback.getAuthorizedID();
    } catch (Exception e) {
        throw new SaslException("Plain authentication failed: " + e.getMessage(), e);
    }
    mCompleted = true;
    return null;
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) AuthorizeCallback(javax.security.sasl.AuthorizeCallback) Callback(javax.security.auth.callback.Callback) PasswordCallback(javax.security.auth.callback.PasswordCallback) SaslException(javax.security.sasl.SaslException) SaslException(javax.security.sasl.SaslException) AuthorizeCallback(javax.security.sasl.AuthorizeCallback)

Aggregations

Callback (javax.security.auth.callback.Callback)274 NameCallback (javax.security.auth.callback.NameCallback)181 PasswordCallback (javax.security.auth.callback.PasswordCallback)173 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)127 IOException (java.io.IOException)84 LoginException (javax.security.auth.login.LoginException)54 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)49 CallbackHandler (javax.security.auth.callback.CallbackHandler)43 Test (org.testng.annotations.Test)42 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)38 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)31 Subject (javax.security.auth.Subject)31 HashMap (java.util.HashMap)28 HttpServletRequest (javax.servlet.http.HttpServletRequest)24 Principal (java.security.Principal)23 AuthContext (com.sun.identity.authentication.AuthContext)22 FailedLoginException (javax.security.auth.login.FailedLoginException)22 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)19 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)19 LoginContext (javax.security.auth.login.LoginContext)18