Example usage for javax.security.auth.callback UnsupportedCallbackException printStackTrace

List of usage examples for javax.security.auth.callback UnsupportedCallbackException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.dtolabs.rundeck.jetty.jaas.JettyCachingLdapLoginModule.java

/**
 * Gets credentials by calling {@link #getCallBackAuth()}, then performs {@link #authenticate(String, Object)}
 *
 * @return true if authenticated//from w w w  .ja va 2s .c o m
 * @throws LoginException
 */
@Override
public boolean login() throws LoginException {
    try {
        Object[] userPass = getCallBackAuth();
        if (null == userPass || userPass.length < 2) {
            setAuthenticated(false);
            throw new FailedLoginException();
        }
        String name = (String) userPass[0];
        Object pass = userPass[1];
        boolean authenticated = authenticate(name, pass);
        setAuthenticated(authenticated);

        if (!isAuthenticated()) {
            throw new FailedLoginException();
        }
        return isAuthenticated();
    } catch (UnsupportedCallbackException e) {
        throw new LoginException("Error obtaining callback information.");
    } catch (IOException e) {
        if (_debug) {
            e.printStackTrace();
        }
        throw new LoginException("IO Error performing login.");
    }
}

From source file:com.dtolabs.rundeck.jetty.jaas.JettyCachingLdapLoginModule.java

/**
 * since ldap uses a context bind for valid authentication checking, we
 * override login()//from  w ww  . j  a  va 2 s .c  om
 * <br>
 * if credentials are not available from the users context or if we are
 * forcing the binding check then we try a binding authentication check,
 * otherwise if we have the users encoded password then we can try
 * authentication via that mechanic
 * @param webUserName user
 * @param webCredential password
 *
 *
 * @return true if authenticated
 * @throws LoginException
 */
protected boolean authenticate(final String webUserName, final Object webCredential) throws LoginException {
    try {
        if (isEmptyOrNull(webUserName) || isEmptyOrNull(webCredential)
                || (webCredential instanceof char[] && ((char[]) webCredential).length == 0)) {
            LOG.info("empty username or password not allowed");
            setAuthenticated(false);
            return isAuthenticated();
        }

        loginAttempts++;

        if (_reportStatistics) {
            DecimalFormat percentHit = new DecimalFormat("#.##");
            LOG.info("Login attempts: " + loginAttempts + ", Hits: " + userInfoCacheHits + ", Ratio: "
                    + percentHit.format((double) userInfoCacheHits / loginAttempts * 100f) + "%.");
        }

        if (_forceBindingLogin) {
            return bindingLogin(webUserName, webCredential);
        }

        // This sets read and the credential
        UserInfo userInfo = getUserInfo(webUserName);

        if (userInfo == null) {
            setAuthenticated(false);
            return false;
        }

        JAASUserInfo jaasUserInfo = new JAASUserInfo(userInfo);
        jaasUserInfo.fetchRoles(); //must run this otherwise will throw NPE later
        setCurrentUser(jaasUserInfo);

        if (webCredential instanceof String) {
            return credentialLogin(Credential.getCredential((String) webCredential));
        }

        return credentialLogin(webCredential);
    } catch (UnsupportedCallbackException e) {
        throw new LoginException("Error obtaining callback information.");
    } catch (IOException e) {
        if (_debug) {
            e.printStackTrace();
        }
        throw new LoginException("IO Error performing login.");
    } catch (LoginException e) {
        throw e;
    } catch (Exception e) {
        if (_debug) {
            e.printStackTrace();
        }
        throw new LoginException("Error obtaining user info.");
    }
}