Example usage for javax.security.auth.callback PasswordCallback clearPassword

List of usage examples for javax.security.auth.callback PasswordCallback clearPassword

Introduction

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

Prototype

public void clearPassword() 

Source Link

Document

Clear the retrieved password.

Usage

From source file:com.flexive.core.security.FxDefaultLogin.java

/**
 * Verify the name/password combination.
 *
 * @return true always, since this LoginModule should not be ignored.
 * @throws FailedLoginException if the authentication fails.
 * @throws LoginException       if this LoginModule is unable to perform the authentication.
 *//* ww  w. ja v a  2 s.  co m*/
@Override
public boolean login() throws LoginException {
    LoginException le = null;
    try {
        // Determine username and password using the callback handler
        final Callback[] callbacks = new Callback[] { new NameCallback("user: "),
                new PasswordCallback("password: ", true), new FxCallback() };
        callbackHandler.handle(callbacks);

        FxCallback ac = ((FxCallback) callbacks[2]);
        final String username = ((NameCallback) callbacks[0]).getName();
        final PasswordCallback pc = (PasswordCallback) callbacks[1];
        final String password = new String((pc.getPassword()));
        pc.clearPassword();
        UserTicket ticket = FxAuthenticationHandler.login(username, password, ac);
        // Set the credentials and principals
        this.tempPrincipals.add(new FxPrincipal(ticket));
        // The login was successfull
        success = true;
        if (LOG.isInfoEnabled())
            LOG.info("User [" + ticket.getUserName() + "] successfully logged in, ticket=" + ticket);
    } catch (IOException exc) {
        le = new FxLoginFailedException("IOException: " + exc.getMessage(),
                FxLoginFailedException.TYPE_UNKNOWN_ERROR);
        LOG.error(le);
    } catch (UnsupportedCallbackException exc) {
        le = new FxLoginFailedException("IOException: " + exc.getMessage(),
                FxLoginFailedException.TYPE_UNKNOWN_ERROR);
        LOG.error(le);
    }
    // Log and throw exceptions
    if (le != null) {
        success = false;
        throw le;
    }
    return true;
}

From source file:com.redhat.topicindex.security.FedoraAccountSystem.java

public boolean login() throws LoginException {
    if (callbackHandler == null)
        throw new LoginException("No CallbackHandler available");

    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  om*/
        callbackHandler.handle(callbacks);

        username = nameCallback.getName();
        password = passwordCallback.getPassword();
        passwordCallback.clearPassword();
    } catch (IOException e) {
        throw new LoginException(e.toString());
    } catch (UnsupportedCallbackException e) {
        throw new LoginException("Error: " + e.getCallback().toString() + "not available");
    }

    if (authenticate()) {
        loginSucceeded = true;
    } else {
        return false;
    }

    return true;
}

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");
    }//from   w w w.  j av a 2s.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;
}

From source file:net.ontopia.topicmaps.nav2.realm.TMLoginModule.java

/** 
 * Prompt the user for username and password, and verify those.
 *//*from   w w  w. j  a  v a 2s.  c o  m*/
@Override
public boolean login() throws LoginException {
    log.debug("TMLoginModule: login");

    if (callbackHandler == null)
        throw new LoginException(
                "Error: no CallbackHandler available " + "to garner authentication information from the user");

    // prompt for a user name and password
    NameCallback nameCallback = new NameCallback("user name: ");
    PasswordCallback passwordCallback = new PasswordCallback("password: ", false);

    try {
        callbackHandler.handle(new Callback[] { nameCallback, passwordCallback });

        this.username = nameCallback.getName();
        char[] charpassword = passwordCallback.getPassword();
        password = (charpassword == null ? "" : new String(charpassword));
        passwordCallback.clearPassword();

    } catch (java.io.IOException ioe) {
        throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException("Error: " + uce.getCallback()
                + " not available to garner authentication information " + "from the user");
    }
    // verify the username/password
    loginSucceeded = verifyUsernamePassword(username, password);
    return loginSucceeded;
}

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

private void initPassword(PasswordCallback passwordCallback) {
    char[] password = passwordCallback.getPassword();
    if (password != null) {
        _password = new String(password);
    }/*from  w  ww. ja v a2 s . com*/
    passwordCallback.clearPassword();
}

From source file:org.betaconceptframework.astroboa.engine.service.security.AstroboaLogin.java

/**
 * //from  w w  w . j  av  a  2 s.co  m
 * TAKEN FROM Jboss class
 *  
 * org.jboss.security.auth.spi.UsernamePasswordLoginModule
 * 
 * and adjust it to Astroboa requirements
 * 
 * @return
 * @throws LoginException
 */
private String[] getAuthenticationInformation() throws LoginException {
    String[] info = { null, null, null, null, null };
    // prompt for a username and password
    if (callbackHandler == null) {
        throw new LoginException(
                "Error: no CallbackHandler available " + "to collect authentication information");
    }

    NameCallback nc = new NameCallback("User name: ", "guest");
    PasswordCallback pc = new PasswordCallback("Password: ", false);
    AstroboaAuthenticationCallback authenticationCallback = new AstroboaAuthenticationCallback(
            "Astroboa authentication info");

    Callback[] callbacks = { nc, pc, authenticationCallback };
    String username = null;
    String password = null;
    String identityStoreLocation = null;
    String userSecretKey = null;
    String repositoryId = null;

    try {
        callbackHandler.handle(callbacks);
        username = nc.getName();
        char[] tmpPassword = pc.getPassword();
        if (tmpPassword != null) {
            char[] credential = new char[tmpPassword.length];
            System.arraycopy(tmpPassword, 0, credential, 0, tmpPassword.length);
            pc.clearPassword();
            password = new String(credential);
        }

        identityStoreLocation = authenticationCallback.getIdentityStoreLocation();

        useExternalIdentity = authenticationCallback.isExternalIdentityStore();

        userSecretKey = authenticationCallback.getSecretKey();

        repositoryId = authenticationCallback.getRepositoryId();
    } catch (IOException e) {
        LoginException le = new LoginException("Failed to get username/password");
        le.initCause(e);
        throw le;
    } catch (UnsupportedCallbackException e) {
        LoginException le = new LoginException("CallbackHandler does not support: " + e.getCallback());
        le.initCause(e);
        throw le;
    }
    info[0] = username;
    info[1] = password;
    info[2] = userSecretKey;
    info[3] = identityStoreLocation;
    info[4] = repositoryId;

    return info;
}