Example usage for javax.security.auth.login LoginException LoginException

List of usage examples for javax.security.auth.login LoginException LoginException

Introduction

In this page you can find the example usage for javax.security.auth.login LoginException LoginException.

Prototype

public LoginException(String msg) 

Source Link

Document

Constructs a LoginException with the specified detail message.

Usage

From source file:org.rhq.enterprise.server.core.jaas.JDBCLoginModule.java

/**
 * @see org.jboss.security.auth.spi.UsernamePasswordLoginModule#getUsersPassword()
 *///  w ww. ja  v a  2s  .  com
@Override
protected String getUsersPassword() throws LoginException {
    String username = getUsername();
    if ("admin".equals(username)) {
        throw new FailedLoginException("Cannot log in as overlord");
    }
    String password = null;
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        Properties props = getProperties();
        InitialContext ctx = new InitialContext(props);
        DataSource ds = (DataSource) ctx.lookup(dsJndiName);
        conn = ds.getConnection();

        ps = conn.prepareStatement(principalsQuery);
        ps.setString(1, username);
        rs = ps.executeQuery();
        if (rs.next() == false) {
            throw new FailedLoginException("No matching username found in principals");
        }

        password = rs.getString(1);
    } catch (NamingException ex) {
        throw new LoginException(ex.toString(true));
    } catch (SQLException ex) {
        throw new LoginException(ex.toString());
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (Exception e) {
            }
        }

        if (ps != null) {
            try {
                ps.close();
            } catch (Exception e) {
            }
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (Exception ex) {
            }
        }
    }

    return password;
}

From source file:org.getobjects.jaas.EODatabaseLoginModule.java

@Override
public boolean login() throws LoginException {
    if (this.database == null)
        throw new LoginException("missing valid JAAS EODatabase config!");
    return super.login();
}

From source file:org.josso.tc55.agent.jaas.SSOGatewayLoginModule.java

/**
 * Authenticate the user by prompting for the SSO Session Identifier assigned by the SSO Gateway on logon.
 *
 * This method obtains from the gateway, using the provided session identifier, the user associated with
 * such session identifier.//from w  w w . j  a va2 s  . c  o  m
 * Only the NameCallBack is used, since its not a user/password pair but only one value containing the session
 * identifier. Any other callback type is ignored.
 *
 * @return true in all cases since this LoginModule
 *        should not be ignored.
 *
 * @exception javax.security.auth.login.FailedLoginException if the authentication fails.
 *
 * @exception javax.security.auth.login.LoginException if this LoginModule
 *        is unable to perform the authentication.
 */
public boolean login() throws LoginException {

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

    Callback[] callbacks = new Callback[2];

    // Just ask for the session identifier
    callbacks[0] = new NameCallback("ssoSessionId");
    callbacks[1] = new PasswordCallback("password", false);

    String ssoSessionId;
    String ssoSessionId2 = null;
    try {
        _callbackHandler.handle(callbacks);
        ssoSessionId = ((NameCallback) callbacks[0]).getName();
        if (((PasswordCallback) callbacks[1]).getPassword() != null)
            ssoSessionId2 = String.valueOf(((PasswordCallback) callbacks[1]).getPassword());

        _requester = "";
        // Check for nulls ?
        SSOAgentRequest request = AbstractSSOAgent._currentRequest.get();
        if (request != null)
            _requester = request.getRequester();
        else
            logger.warn("No SSO Agent request found in thread local variable, can't identify requester");

    } catch (java.io.IOException ioe) {
        throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException("Error: " + uce.getCallback().toString()
                + " not available to garner authentication information " + "from the user");
    }

    logger.debug("Requested authentication to gateway by " + _requester + " using sso session " + ssoSessionId
            + "/" + ssoSessionId2);

    try {

        if (ssoSessionId2 != null && !ssoSessionId2.equals(ssoSessionId))
            ssoSessionId = ssoSessionId2;

        // If no session is found, ignore this module.
        if (ssoSessionId == null) {
            logger.debug("Session authentication failed : " + ssoSessionId);
            _succeeded = false;
            return false;
        }

        _currentSSOSessionId = ssoSessionId;

        SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager();
        SSOUser ssoUser = im.findUserInSession(_requester, ssoSessionId);

        logger.debug("Session authentication succeeded : " + ssoSessionId);
        _ssoUserPrincipal = ssoUser;
        _succeeded = true;

    } catch (SSOIdentityException e) {
        // Ignore this ... (user does not exist for this session)
        if (logger.isDebugEnabled())
            logger.debug(e.getMessage());
        _succeeded = false;
        return false;

    } catch (Exception e) {
        logger.error("Session authentication failed : " + ssoSessionId, e);
        _succeeded = false;
        clearCredentials();
        throw new FailedLoginException("Fatal error authenticating session : " + e);
    }

    return true;
}

From source file:org.josso.tc50.agent.jaas.SSOGatewayLoginModule.java

/**
 * Authenticate the user by prompting for the SSO Session Identifier assigned by the SSO Gateway on logon.
 *
 * This method obtains from the gateway, using the provided session identifier, the user associated with
 * such session identifier./*from ww  w .  j a  va 2  s.  c  o  m*/
 * Only the NameCallBack is used, since its not a user/password pair but only one value containing the session
 * identifier. Any other callback type is ignored.
 *
 * @return true in all cases since this LoginModule
 *        should not be ignored.
 *
 * @exception javax.security.auth.login.FailedLoginException if the authentication fails.
 *
 * @exception javax.security.auth.login.LoginException if this LoginModule
 *        is unable to perform the authentication.
 */
public boolean login() throws LoginException {

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

    Callback[] callbacks = new Callback[2];

    // Just ask for the session identifier
    callbacks[0] = new NameCallback("ssoSessionId");
    callbacks[1] = new PasswordCallback("password", false);

    String ssoSessionId;
    String ssoSessionId2 = null;
    try {
        _callbackHandler.handle(callbacks);

        ssoSessionId = ((NameCallback) callbacks[0]).getName();
        if (((PasswordCallback) callbacks[1]).getPassword() != null)
            ssoSessionId2 = String.valueOf(((PasswordCallback) callbacks[1]).getPassword());

        _requester = "";
        // Check for nulls ?
        SSOAgentRequest request = AbstractSSOAgent._currentRequest.get();
        if (request != null)
            _requester = request.getRequester();
        else
            logger.warn("No SSO Agent request found in thread local variable, can't identify requester");

    } catch (java.io.IOException ioe) {
        throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException("Error: " + uce.getCallback().toString()
                + " not available to garner authentication information " + "from the user");
    }

    logger.debug("Requested authentication to gateway by " + _requester + " using sso session " + ssoSessionId
            + "/" + ssoSessionId2);

    try {

        if (ssoSessionId2 != null && !ssoSessionId2.equals(ssoSessionId))
            ssoSessionId = ssoSessionId2;

        // If no session is found, ignore this module.
        if (ssoSessionId == null) {
            logger.debug("Session authentication failed : " + ssoSessionId);
            _succeeded = false;
            return false;
        }

        _currentSSOSessionId = ssoSessionId;

        SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager();
        SSOUser ssoUser = im.findUserInSession(_requester, ssoSessionId);

        logger.debug("Session authentication succeeded : " + ssoSessionId);
        _ssoUserPrincipal = ssoUser;
        _succeeded = true;

    } catch (SSOIdentityException e) {
        // Ignore this ... (user does not exist for this session)
        //if ( logger.isDebugEnabled())
        logger.debug(e.getMessage());
        _succeeded = false;
        return false;

    } catch (Exception e) {
        // logger.error("Session authentication failed : " + ssoSessionId, e);
        _succeeded = false;
        clearCredentials();
        throw new FailedLoginException("Fatal error authenticating session : " + e);
    }

    return true;
}

From source file:org.josso.tc60.agent.jaas.SSOGatewayLoginModule.java

/**
 * Authenticate the user by prompting for the SSO Session Identifier assigned by the SSO Gateway on logon.
 *
 * This method obtains from the gateway, using the provided session identifier, the user associated with
 * such session identifier./*www  .j ava  2 s . c  o  m*/
 * Only the NameCallBack is used, since its not a user/password pair but only one value containing the session
 * identifier. Any other callback type is ignored.
 *
 * @return true in all cases since this LoginModule
 *        should not be ignored.
 *
 * @exception javax.security.auth.login.FailedLoginException if the authentication fails.
 *
 * @exception javax.security.auth.login.LoginException if this LoginModule
 *        is unable to perform the authentication.
 */
public boolean login() throws LoginException {

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

    Callback[] callbacks = new Callback[2];

    // Just ask for the session identifier
    callbacks[0] = new NameCallback("ssoSessionId");
    callbacks[1] = new PasswordCallback("password", false);

    String ssoSessionId;
    String ssoSessionId2 = null;

    try {
        _callbackHandler.handle(callbacks);
        ssoSessionId = ((NameCallback) callbacks[0]).getName();
        if (((PasswordCallback) callbacks[1]).getPassword() != null)
            ssoSessionId2 = String.valueOf(((PasswordCallback) callbacks[1]).getPassword());

        _requester = "";
        // Check for nulls ?
        SSOAgentRequest request = AbstractSSOAgent._currentRequest.get();
        if (request != null)
            _requester = request.getRequester();
        else
            logger.warn("No SSO Agent request found in thread local variable, can't identify requester");

    } catch (java.io.IOException ioe) {
        throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException("Error: " + uce.getCallback().toString()
                + " not available to garner authentication information " + "from the user");
    }

    logger.debug("Requested authentication to gateway by " + _requester + " using sso session " + ssoSessionId
            + "/" + ssoSessionId2);

    try {

        if (ssoSessionId2 != null && !ssoSessionId2.equals(ssoSessionId))
            ssoSessionId = ssoSessionId2;

        // If no session is found, ignore this module.
        if (ssoSessionId == null) {
            logger.debug("Session authentication failed : " + ssoSessionId);
            _succeeded = false;
            return false;
        }

        _currentSSOSessionId = ssoSessionId;

        SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager();
        SSOUser ssoUser = im.findUserInSession(_requester, ssoSessionId);

        logger.debug("Session authentication succeeded : " + ssoSessionId);
        _ssoUserPrincipal = ssoUser;
        _succeeded = true;

    } catch (SSOIdentityException e) {
        // Ignore this ... (user does not exist for this session)
        if (logger.isDebugEnabled())
            logger.debug(e.getMessage(), e);
        _succeeded = false;
        return false;

    } catch (Exception e) {
        logger.error("Session authentication failed : " + ssoSessionId, e);
        _succeeded = false;
        clearCredentials();
        throw new FailedLoginException("Fatal error authenticating session : " + e);
    }

    return true;
}

From source file:com.hs.mail.security.login.PropertiesLoginModule.java

private String getLine(File file, String start) throws LoginException {
    LineReader reader = null;/*from www.  ja va  2 s  . c om*/
    BufferedInputStream is = null;
    try {
        is = new BufferedInputStream(new FileInputStream(file));
        reader = new LineReader(is);
        int len = start.length();
        String line = null;
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            if (!line.startsWith("#") && line.regionMatches(false, 0, start, 0, len)) {
                return line;
            }
        }
        return null;
    } catch (IOException e) {
        throw new LoginException("Error while reading file: " + file);
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(reader);
    }
}

From source file:org.josso.wls10.agent.jaas.SSOGatewayLoginModuleNoCustomPrincipalsImpl.java

/**
 * Authenticate the user by prompting for the SSO Session Identifier assigned by the SSO Gateway on logon.
 *
 * This method obtains from the gateway, using the provided session identifier, the user associated with
 * such session identifier.//from w w w. ja  v a 2 s.  c om
 * Only the NameCallBack is used, since its not a user/password pair but only one value containing the session
 * identifier. Any other callback type is ignored.
 *
 * @return true in all cases since this LoginModule
 *        should not be ignored.
 *
 * @exception javax.security.auth.login.FailedLoginException if the authentication fails.
 *
 * @exception javax.security.auth.login.LoginException if this LoginModule
 *        is unable to perform the authentication.
 */
public boolean login() throws LoginException {

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

    Callback[] callbacks = new Callback[2];

    // Just ask for the session identifier
    callbacks[0] = new NameCallback("ssoSessionId");
    callbacks[1] = new PasswordCallback("password", false);

    String ssoSessionId;
    String ssoSessionId2 = null;
    try {
        _callbackHandler.handle(callbacks);
        ssoSessionId = ((NameCallback) callbacks[0]).getName();
        if (((PasswordCallback) callbacks[1]).getPassword() != null)
            ssoSessionId2 = String.valueOf(((PasswordCallback) callbacks[1]).getPassword());

        _requester = "";
        // Check for nulls ?
        SSOAgentRequest request = AbstractSSOAgent._currentRequest.get();
        if (request != null)
            _requester = request.getRequester();
        else
            logger.warn("No SSO Agent request found in thread local variable, can't identify requester");

    } catch (java.io.IOException ioe) {
        throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException("Error: " + uce.getCallback().toString()
                + " not available to garner authentication information " + "from the user");
    }

    logger.debug("Requested authentication to gateway by " + _requester + " using sso session " + ssoSessionId
            + "/" + ssoSessionId2);

    try {

        if (ssoSessionId2 != null && !ssoSessionId2.equals(ssoSessionId))
            ssoSessionId = ssoSessionId2;

        // If no session is found, ignore this module.
        if (ssoSessionId == null) {
            if (logger.isDebugEnabled())
                logger.debug("Session authentication failed : " + ssoSessionId);
            _succeeded = false;
            return false;
        }

        _currentSSOSessionId = ssoSessionId;

        SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager();
        SSOUser jossoUser = im.findUserInSession(_requester, ssoSessionId);
        WLSUser wlsUser = new WLSUserImpl(jossoUser.getName());

        if (logger.isDebugEnabled())
            logger.debug("Session authentication succeeded : " + ssoSessionId);

        _ssoUserPrincipal = wlsUser;
        _succeeded = true;

    } catch (SSOIdentityException e) {
        // Ignore this ... (user does not exist for this session)
        logger.debug(e.getMessage());
        _succeeded = false;
        return false;

    } catch (Exception e) {

        logger.error("Session login failed for Principal : " + _ssoUserPrincipal + e.getMessage());

        // Only log if debug is enabled ...
        if (logger.isDebugEnabled())
            logger.debug(e.getMessage(), e);

        _succeeded = false;
        clearCredentials();
        throw new FailedLoginException(
                "Fatal error authenticating session : " + _ssoUserPrincipal + " : " + e.getMessage());
    }

    return true;
}

From source file:org.josso.wls81.agent.jaas.SSOGatewayLoginModuleNoCustomPrincipalsImpl.java

/**
 * Authenticate the user by prompting for the SSO Session Identifier assigned by the SSO Gateway on logon.
 *
 * This method obtains from the gateway, using the provided session identifier, the user associated with
 * such session identifier./*  w  w  w  .jav  a 2s  . c  o  m*/
 * Only the NameCallBack is used, since its not a user/password pair but only one value containing the session
 * identifier. Any other callback type is ignored.
 *
 * @return true in all cases since this LoginModule
 *        should not be ignored.
 *
 * @exception javax.security.auth.login.FailedLoginException if the authentication fails.
 *
 * @exception javax.security.auth.login.LoginException if this LoginModule
 *        is unable to perform the authentication.
 */
public boolean login() throws LoginException {

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

    Callback[] callbacks = new Callback[2];

    // Just ask for the session identifier
    callbacks[0] = new NameCallback("ssoSessionId");
    callbacks[1] = new PasswordCallback("password", false);

    String ssoSessionId;
    String ssoSessionId2 = null;
    try {
        _callbackHandler.handle(callbacks);
        ssoSessionId = ((NameCallback) callbacks[0]).getName();
        if (((PasswordCallback) callbacks[1]).getPassword() != null)
            ssoSessionId2 = String.valueOf(((PasswordCallback) callbacks[1]).getPassword());

        _requester = "";
        // Check for nulls ?
        SSOAgentRequest request = (SSOAgentRequest) AbstractSSOAgent._currentRequest.get();
        if (request != null)
            _requester = request.getRequester();
        else
            logger.warn("No SSO Agent request found in thread local variable, can't identify requester");

    } catch (java.io.IOException ioe) {
        throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException("Error: " + uce.getCallback().toString()
                + " not available to garner authentication information " + "from the user");
    }

    logger.debug("Requested authentication to gateway by " + _requester + " using sso session " + ssoSessionId
            + "/" + ssoSessionId2);

    try {

        if (ssoSessionId2 != null && !ssoSessionId2.equals(ssoSessionId))
            ssoSessionId = ssoSessionId2;

        // If no session is found, ignore this module.
        if (ssoSessionId == null) {

            if (logger.isDebugEnabled())
                logger.debug("Session authentication failed : " + ssoSessionId);

            _succeeded = false;
            return false;
        }

        _currentSSOSessionId = ssoSessionId;

        SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager();
        SSOUser jossoUser = im.findUserInSession(_requester, ssoSessionId);
        WLSUser wlsUser = new WLSUserImpl(jossoUser.getName());

        if (logger.isDebugEnabled())
            logger.debug("Session authentication succeeded : " + ssoSessionId);

        _ssoUserPrincipal = wlsUser;
        _succeeded = true;

    } catch (SSOIdentityException e) {
        // Ignore this ... (user does not exist for this session)
        if (logger.isDebugEnabled())
            logger.debug(e.getMessage());

        _succeeded = false;
        return false;

    } catch (Exception e) {

        logger.error("Session login failed for Principal : " + _ssoUserPrincipal + e.getMessage());

        // Only log if debug is enabled ...
        if (logger.isDebugEnabled())
            logger.debug(e.getMessage(), e);

        _succeeded = false;
        clearCredentials();
        throw new FailedLoginException(
                "Fatal error authenticating session : " + _ssoUserPrincipal + " : " + e.getMessage());
    }

    return true;
}

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

@Override
protected void doInit(CallbackHandler callbackHandler, Session session,
        @SuppressWarnings("rawtypes") Map options) throws LoginException {
    try {//ww  w. jav a 2 s .  c om
        SessionImpl sessionImpl = (SessionImpl) session;
        SparseMapUserManager userManager = (SparseMapUserManager) sessionImpl.getUserManager();
        org.sakaiproject.nakamura.api.lite.Session sparseSession = userManager.getSession();

        LoginModulePlugin[] modules = Activator.getLoginModules();
        for (int i = 0; i < modules.length; i++) {
            modules[i].doInit(callbackHandler, session, options);
        }

        CredentialsCallback cb = new CredentialsCallback();
        try {
            callbackHandler.handle(new Callback[] { cb });
        } catch (IOException e1) {
            LOGGER.warn(e1.getMessage(), e1);
        } catch (UnsupportedCallbackException e1) {
            LOGGER.warn(e1.getMessage(), e1);
        }
        authenticator = sparseSession.getAuthenticator();
    } catch (StorageClientException e) {
        throw new LoginException(e.getMessage());
    } catch (AccessDeniedException e) {
        throw new LoginException(e.getMessage());
    } catch (RepositoryException e) {
        throw new LoginException(e.getMessage());
    }

}

From source file:de.adorsys.oauth.loginmodule.DelegatingLoginModule.java

private void verifyClientID(ClientID clientID) throws LoginException {
    if (clientID == null || StringUtils.isEmpty(clientID.toString())) {
        log.warn("Received call with invalid client_id: " + clientID);
        throw new LoginException("Invalid client_id");
    }/*  w  ww . java2 s  . com*/

    String[] clientIDs = clientIdList.split(",");

    if (!Arrays.asList(clientIDs).contains(clientID.getValue())) {
        log.warn("Received call with unkown client_id: " + clientID);
        throw new LoginException("Unkown client_id");
    }
}