Example usage for javax.security.auth.callback TextOutputCallback INFORMATION

List of usage examples for javax.security.auth.callback TextOutputCallback INFORMATION

Introduction

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

Prototype

int INFORMATION

To view the source code for javax.security.auth.callback TextOutputCallback INFORMATION.

Click Source Link

Document

Information message.

Usage

From source file:com.ideabase.repository.core.auth.RepositoryLoginModule.java

/**
 * Perform Lucene index search by user name and user password. <br>
 * if indexer returns some value. it means the requset is from valid user.<br>
 * send another callback request, this callback request pack the user id.<br>
 * the callback handler can retrieve user object from storage.<br>
 * create new {@see RepositoryUserPrincipal}. <br>
 *///www. j  a  v  a2 s. c o  m
private void authenticateUser(final String pUserName, final String pUserPassword)
        throws LoginException, IOException, UnsupportedCallbackException {

    final String userHashKey = DigestUtils.shaHex(pUserName + pUserPassword);
    final User user = API.giveMe().repositoryService().getItemByTitle(userHashKey, User.class);
    if (user != null) {
        final Integer userId = user.getId();
        // send other callback request with user id.
        Callback[] callbacks = new Callback[1];
        callbacks[0] = new TextOutputCallback(TextOutputCallback.INFORMATION, String.valueOf(userId));
        mCallbackHandler.handle(callbacks);

        if (DEBUG) {
            LOG.debug("Search result id - " + userId);
        }

        // create repository user principal
        if (!user.isAdmin()) {
            mUser = new RepositoryUserPrincipal(PRINCIPAL_USER, userId);
        } else {
            mUser = new RepositoryUserPrincipal(PRINCIPAL_ADMIN, userId);
        }
    } else {
        throw new LoginException("Login failed. Invalid user or password.");
    }
}

From source file:org.hyperic.hq.plugin.weblogic.WeblogicAuth.java

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof TextOutputCallback) {

            TextOutputCallback toc = (TextOutputCallback) callbacks[i];

            switch (toc.getMessageType()) {
            case TextOutputCallback.INFORMATION:
                log.info(toc.getMessage());
                break;

            case TextOutputCallback.ERROR:
                log.error(toc.getMessage());
                break;

            case TextOutputCallback.WARNING:
                log.warn(toc.getMessage());
                break;

            default:
                throw new IOException("Unsupported message type: " + toc.getMessageType());
            }/* www.jav  a 2 s.c o m*/
        } else if (callbacks[i] instanceof NameCallback) {
            NameCallback nc = (NameCallback) callbacks[i];
            nc.setName(this.username);
        } else if (callbacks[i] instanceof URLCallback) {
            URLCallback uc = (URLCallback) callbacks[i];
            uc.setURL(this.url);
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callbacks[i];
            pc.setPassword(this.passwordArray);
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}

From source file:org.polymap.core.security.DummyLoginModule.java

public boolean login() throws LoginException {
    // check if there is a user with "login" password
    for (DummyUserPrincipal candidate : users.values()) {
        if (candidate.getPassword().equals("login")) {
            principal = candidate;//  ww  w.  j av a 2  s  .com
            return loggedIn = true;
        }
    }

    try {
        Callback label = new TextOutputCallback(TextOutputCallback.INFORMATION,
                // empty if service login
                StringUtils.defaultIfEmpty(dialogTitle, "POLYMAP3 Workbench"));
        NameCallback nameCallback = new NameCallback(
                StringUtils.defaultIfEmpty(i18n.get("username"), "Username"), "default");
        PasswordCallback passwordCallback = new PasswordCallback(
                StringUtils.defaultIfEmpty(i18n.get("password"), "Password"), false);

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

        String username = nameCallback.getName();

        String password = "";
        if (passwordCallback.getPassword() != null) {
            password = String.valueOf(passwordCallback.getPassword());
        }

        DummyUserPrincipal candidate = userForName(username);
        if (candidate.getPassword().equals(password)) {
            principal = candidate;
            loggedIn = true;
            return true;
        }
        return false;
    } catch (Exception e) {
        log.warn("", e);
        throw new LoginException(e.getLocalizedMessage());
    }
}

From source file:org.polymap.rhei.um.auth.UmLoginModule.java

@Override
public boolean login() throws LoginException {
    Callback label = new TextOutputCallback(TextOutputCallback.INFORMATION, dialogTitle);
    NameCallback nameCallback = new NameCallback(i18n.get("username"), "default");
    PasswordCallback passwordCallback = new PasswordCallback(i18n.get("password"), false);
    try {/*from   w w  w .  jav  a  2 s .co  m*/
        callbackHandler.handle(new Callback[] { label, nameCallback, passwordCallback });
    } catch (Exception e) {
        log.warn("", e);
        throw new LoginException(e.getLocalizedMessage());
    }

    String username = nameCallback.getName();
    //        if (username == null) {
    //            return false;
    //        }

    // admin
    if (username == null || username.equals("admin")) {
        // FIXME read password hash from persistent storage and check
        log.warn("!!! NO PASSWORD check for admin user yet !!!!!!");
        principal = new UserPrincipal("admin");
        return loggedIn = true;
    }

    // ordinary user
    User user = repo.findUser(username);
    log.info("username: " + user.email().get());

    if (user != null && passwordCallback.getPassword() != null) {
        String password = String.valueOf(passwordCallback.getPassword());
        if (PasswordEncryptor.instance().checkPassword(password, user.passwordHash().get())) {
            log.info("username: " + user.username().get());
            principal = new UmUserPrincipal(user);
            return loggedIn = true;
        }
    }
    return false;
}