Example usage for javax.security.auth.callback NameCallback NameCallback

List of usage examples for javax.security.auth.callback NameCallback NameCallback

Introduction

In this page you can find the example usage for javax.security.auth.callback NameCallback NameCallback.

Prototype

public NameCallback(String prompt) 

Source Link

Document

Construct a NameCallback with a prompt.

Usage

From source file:org.apache.jackrabbit.core.security.authentication.AbstractLoginModule.java

/**
 * Method supports tries to acquire a UserID in the follwing order:
 * <ol>/*w w  w.ja v a2 s .c o m*/
 * <li>If passed credentials are {@link GuestCredentials} the anonymous user id
 * is returned.</li>
 * <li>Try to access it from the {@link Credentials} via {@link
 * SimpleCredentials#getUserID()}</li>
 * <li>Ask CallbackHandler for User-ID with use of {@link NameCallback}.</li>
 * <li>Test if the 'sharedState' contains a login name.</li>
 * <li>Fallback: return the anonymous UserID.</li>
 * </ol>
 *
 * @param credentials which, may contain a User-ID
 * @return The userId retrieved from the credentials or by any other means
 * described above.
 * @see #login()
 */
protected String getUserID(Credentials credentials) {
    String userId = null;
    if (credentials != null) {
        if (credentials instanceof GuestCredentials) {
            userId = anonymousId;
        } else if (credentials instanceof SimpleCredentials) {
            userId = ((SimpleCredentials) credentials).getUserID();
        } else {
            try {
                NameCallback callback = new NameCallback("User-ID: ");
                callbackHandler.handle(new Callback[] { callback });
                userId = callback.getName();
            } catch (UnsupportedCallbackException e) {
                log.warn("Credentials- or NameCallback must be supported");
            } catch (IOException e) {
                log.error("Name-Callback failed: " + e.getMessage());
            }
        }
    }
    if (userId == null && sharedState.containsKey(KEY_LOGIN_NAME)) {
        userId = (String) sharedState.get(KEY_LOGIN_NAME);
    }

    // still no userId -> anonymousID if its has been defined.
    // TODO: check again if correct when used with 'extendedAuth'
    if (userId == null) {
        userId = anonymousId;
    }
    return userId;
}

From source file:org.forgerock.openam.authentication.modules.impersonation.ImpersonationModule.java

private void substituteUIStrings() throws AuthLoginException {
    // Get service specific attribute configured in OpenAM
    System.out.println("question from config: " + question);

    Callback[] crquestion = getCallback(2);

    replaceCallback(2, 0, new NameCallback(question));
}