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

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

Introduction

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

Prototype

public String getName() 

Source Link

Document

Get the retrieved name.

Usage

From source file:org.forgerock.openam.forgerockrest.authn.callbackhandlers.RestAuthNameCallbackHandler.java

/**
 * {@inheritDoc}//from w  ww .ja  v a 2  s. c  om
 */
public JsonValue convertToJson(NameCallback callback, int index) {

    String prompt = callback.getPrompt();
    String name = callback.getName();

    JsonValue jsonValue = JsonValueBuilder.jsonValue().put("type", CALLBACK_NAME).array("output")
            .addLast(createOutputField("prompt", prompt)).array("input").addLast(createInputField(index, name))
            .build();

    return jsonValue;
}

From source file:org.apache.ranger.authentication.unix.jaas.PamLoginModule.java

private void initUserName(NameCallback nameCallback) {
    _username = nameCallback.getName();
}

From source file:de.ingrid.admin.security.AbstractLoginModule.java

@Override
public boolean login() throws LoginException {
    NameCallback nameCallback = new NameCallback("user name:");
    PasswordCallback passwordCallback = new PasswordCallback("password:", false);
    try {//from ww w .  ja  v a2s .c  o m
        _callbackHandler.handle(new Callback[] { nameCallback, passwordCallback });
        String name = nameCallback.getName();
        char[] password = passwordCallback.getPassword();
        if (name != null) {
            if (password != null) {
                IngridPrincipal ingridPrincipal = authenticate(name, new String(password));
                if (ingridPrincipal.isAuthenticated()) {
                    setAuthenticated(true);
                    _currentPrincipal = ingridPrincipal;
                }
            }
        }
    } catch (Exception e) {
        LOG.error("login failed.", e);
        throw new LoginException(e.getMessage());
    }
    return isAuthenticated();
}

From source file:be.fedict.eid.applet.beta.service.AuthorizationLoginModule.java

public boolean login() throws LoginException {
    NameCallback nameCallback = new NameCallback("Username");
    Callback[] callbacks = new Callback[] { nameCallback };
    try {//from  ww w .j  ava  2s  .  c om
        this.callbackHandler.handle(callbacks);
    } catch (Exception e) {
        throw new LoginException("JAAS callback error: " + e.getMessage());
    }
    String name = nameCallback.getName();
    this.principal = new NamePrincipal(name);
    LOG.debug("login: " + name);
    return true;
}

From source file:cz.ceskaexpedice.k5.k5jaas.basic.K5LoginModule.java

@Override
public boolean login() throws LoginException {
    try {/*from  ww  w.j a  v a 2 s  . c  om*/
        NameCallback nmCallback = new NameCallback("Name");
        PasswordCallback pswdCallback = new PasswordCallback("Password", false);
        this.callbackhandler.handle(new Callback[] { nmCallback, pswdCallback });

        String loginName = nmCallback.getName();
        this.remoteLoginName = loginName;
        char[] pswd = pswdCallback.getPassword();
        this.remotePassword = new String(pswd);
        URLConnection connection = openConnection(this.loginAddress, loginName, new String(pswd));
        InputStream is = connection.getInputStream();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        copyStreams(is, bos);
        String str = new String(bos.toByteArray(), "UTF-8");
        JSONObject obj = new JSONObject(str);
        this.logged = testLogged(obj);

    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (UnsupportedCallbackException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (JSONException e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    }

    return this.logged;
}

From source file:org.sakaiproject.nakamura.lite.jackrabbit.SparseLoginModule.java

protected String getUserID(Credentials credentials) {
    String userId = null;/* w w w.  j  a  v a  2 s.  co  m*/
    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) {
                LOGGER.warn("Credentials- or NameCallback must be supported");
            } catch (IOException e) {
                LOGGER.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:be.fedict.hsm.model.security.AdministratorLoginModule.java

@Override
public boolean login() throws LoginException {
    LOG.debug("login");
    NameCallback nameCallback = new NameCallback("username");
    PasswordCallback passwordCallback = new PasswordCallback("password", false);
    Callback[] callbacks = new Callback[] { nameCallback, passwordCallback };
    try {/*from w  ww  .  j av a 2  s .c o  m*/
        this.callbackHandler.handle(callbacks);
    } catch (Exception e) {
        throw new LoginException(e.getMessage());
    }
    String username = nameCallback.getName();
    String cardNumber = new String(passwordCallback.getPassword());
    String authenticatedAdministrator = this.administratorSecurityBean.getAuthenticatedAdministrator(username,
            cardNumber);
    if (null == authenticatedAdministrator) {
        throw new LoginException("invalid administrator: " + username);
    }
    this.authenticatedAdministrator = authenticatedAdministrator;
    return true;
}

From source file:be.fedict.hsm.model.security.ApplicationLoginModule.java

@Override
public boolean login() throws LoginException {
    LOG.debug("login");
    NameCallback nameCallback = new NameCallback("username");
    PasswordCallback passwordCallback = new PasswordCallback("password", false);
    Callback[] callbacks = new Callback[] { nameCallback, passwordCallback };
    try {/*from w  w w . j  av a 2  s .c  o  m*/
        this.callbackHandler.handle(callbacks);
    } catch (Exception e) {
        throw new LoginException(e.getMessage());
    }
    String username = nameCallback.getName();
    char[] credential = passwordCallback.getPassword();
    String authenticatedApplication = this.applicationSecurityBean.getAuthenticatedApplication(username,
            credential);
    if (null == authenticatedApplication) {
        throw new LoginException("invalid application: " + username);
    }
    this.authenticatedApplication = authenticatedApplication;
    return true;
}

From source file:de.tbosch.tools.googleapps.oauth2.OAuth2SaslClient.java

@Override
public byte[] evaluateChallenge(byte[] challenge) throws SaslException {
    if (isComplete) {
        // Empty final response from server, just ignore it.
        return new byte[] {};
    }/*from   w  w  w. ja va  2s  .c  o m*/

    NameCallback nameCallback = new NameCallback("Enter name");
    Callback[] callbacks = new Callback[] { nameCallback };
    try {
        callbackHandler.handle(callbacks);
    } catch (UnsupportedCallbackException e) {
        throw new SaslException("Unsupported callback: " + e);
    } catch (IOException e) {
        throw new SaslException("Failed to execute callback: " + e);
    }
    String email = nameCallback.getName();

    byte[] response = String.format("user=%s\1auth=Bearer %s\1\1", email, oauthToken).getBytes();
    isComplete = true;
    return response;
}

From source file:gov.nih.nci.ncicb.cadsr.common.security.jboss.DBLoginModule.java

protected String[] getUsernameAndPassword() throws LoginException {
    String[] info = { null, null };
    if (callbackHandler == null) {
        throw new LoginException("Error: no CallbackHandler available to collect authentication information");
    }//  ww w  . ja  v  a2  s  . c  o m
    NameCallback nc = new NameCallback("User name: ", "guest");
    PasswordCallback pc = new PasswordCallback("Password: ", false);
    Callback[] callbacks = { nc, pc };
    String username = null;
    String password = null;
    try {
        callbackHandler.handle(callbacks);
        username = nc.getName();
        char[] tmpPassword = pc.getPassword();
        if (tmpPassword != null) {
            credential = new char[tmpPassword.length];
            System.arraycopy(tmpPassword, 0, credential, 0, tmpPassword.length);
            pc.clearPassword();
            password = new String(credential);
        }
    } catch (IOException ioe) {
        throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException("CallbackHandler does not support: " + uce.getCallback());
    }
    info[0] = username;
    info[1] = password;
    logger.debug("Username=" + username);
    return info;
}