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.josso.liferay5.agent.jaas.SSOGatewayLoginModule.java

/**
 * Retreives the list of roles associated to current principal
 */// w  ww .jav a 2  s  .co  m
protected SSORole[] getRoleSets() throws LoginException {
    try {
        // obtain user roles principals and add it to the subject
        SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager();

        return im.findRolesBySSOSessionId(_requester, _currentSSOSessionId);
    } catch (Exception e) {
        logger.error("Session login failed for Principal : " + _ssoUserPrincipal, e);
        throw new LoginException("Session login failed for Principal : " + _ssoUserPrincipal);
    }

}

From source file:org.josso.jaspi.agent.SSOGatewayLoginModule.java

/**
 * Retreives the list of roles associated to current principal
 *//*from   w w w  . j a  va 2s  . c  o  m*/
protected SSORole[] getRoleSets() throws LoginException {
    try {
        // obtain user roles principals and add it to the subject
        SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager();
        return im.findRolesBySSOSessionId(_requester, _currentSSOSessionId);
    } catch (Exception e) {
        logger.error("Session login failed for Principal : " + _ssoUserPrincipal, e);
        throw new LoginException("Session login failed for Principal : " + _ssoUserPrincipal);
    }
}

From source file:org.ow2.proactive.scheduler.smartproxy.SmartProxyImpl.java

@Override
public void init(ConnectionInfo connectionInfo) throws SchedulerException, LoginException {
    this.connectionInfo = connectionInfo;
    if (connectionInfo.getCredentialFile() != null) {
        try {//from   www  .j av  a 2  s .  c  o m
            Credentials credentials = Credentials
                    .getCredentials(connectionInfo.getCredentialFile().getAbsolutePath());
            init(connectionInfo.getUrl(), credentials);
        } catch (KeyException e) {
            throw new LoginException(e.getMessage());
        }
    } else {
        CredData cred = new CredData(CredData.parseLogin(connectionInfo.getLogin()),
                CredData.parseDomain(connectionInfo.getLogin()), connectionInfo.getPassword());
        init(connectionInfo.getUrl(), cred);
    }
}

From source file:org.nuxeo.ecm.platform.login.test.DummyNuxeoLoginModule.java

@Override
public Principal createIdentity(String username) throws LoginException {
    log.debug("createIdentity: " + username);
    try {/* w w w  . j ava 2  s. c  o m*/
        NuxeoPrincipal principal;

        boolean isAdmin = false;
        if (ADMINISTRATOR_USERNAME.equalsIgnoreCase(username)) {
            isAdmin = true;
        }

        // don't retrieve from usernamanger, create a dummy principal
        principal = new NuxeoPrincipalImpl(username, false, isAdmin);

        String principalId = String.valueOf(random.nextLong());
        principal.setPrincipalId(principalId);
        return principal;
    } catch (Exception e) {
        log.error("createIdentity failed", e);
        LoginException le = new LoginException("createIdentity failed for user " + username);
        le.initCause(e);
        throw le;
    }
}

From source file:org.jasig.cas.client.jaas.CasLoginModule.java

public boolean login() throws LoginException {
    log.debug("Performing login.");
    final NameCallback serviceCallback = new NameCallback("service");
    final PasswordCallback ticketCallback = new PasswordCallback("ticket", false);
    try {/*  w  w  w  . j  ava2  s.co  m*/
        this.callbackHandler.handle(new Callback[] { ticketCallback, serviceCallback });
    } catch (final IOException e) {
        log.info("Login failed due to IO exception in callback handler: " + e);
        throw (LoginException) new LoginException("IO exception in callback handler: " + e).initCause(e);
    } catch (final UnsupportedCallbackException e) {
        log.info("Login failed due to unsupported callback: " + e);
        throw (LoginException) new LoginException(
                "Callback handler does not support PasswordCallback and TextInputCallback.").initCause(e);
    }

    if (ticketCallback.getPassword() != null) {
        this.ticket = new TicketCredential(new String(ticketCallback.getPassword()));
        final String service = CommonUtils.isNotBlank(serviceCallback.getName()) ? serviceCallback.getName()
                : this.service;

        if (this.cacheAssertions) {
            synchronized (ASSERTION_CACHE) {
                if (ASSERTION_CACHE.get(ticket) != null) {
                    log.debug("Assertion found in cache.");
                    this.assertion = (Assertion) ASSERTION_CACHE.get(ticket);
                }
            }
        }

        if (this.assertion == null) {
            log.debug("CAS assertion is null; ticket validation required.");
            if (CommonUtils.isBlank(service)) {
                log.info("Login failed because required CAS service parameter not provided.");
                throw new LoginException(
                        "Neither login module nor callback handler provided required service parameter.");
            }
            try {
                if (log.isDebugEnabled()) {
                    log.debug("Attempting ticket validation with service=" + service + " and ticket=" + ticket);
                }
                this.assertion = this.ticketValidator.validate(this.ticket.getTicket(), service);

            } catch (final Exception e) {
                log.info("Login failed due to CAS ticket validation failure: " + e);
                throw (LoginException) new LoginException("CAS ticket validation failed: " + e).initCause(e);
            }
        }
        log.info("Login succeeded.");
    } else {
        log.info("Login failed because callback handler did not provide CAS ticket.");
        throw new LoginException("Callback handler did not provide CAS ticket.");
    }
    return true;
}

From source file:org.nuxeo.ecm.platform.login.NuxeoLoginModule.java

protected NuxeoPrincipal validateUserIdentity(UserIdentificationInfo userIdent) throws LoginException {
    String loginPluginName = userIdent.getLoginPluginName();
    if (loginPluginName == null) {
        // we don't use a specific plugin
        boolean authenticated;
        try {//w  w w .  j  a v a2  s. c  o m
            authenticated = manager.checkUsernamePassword(userIdent.getUserName(), userIdent.getPassword());
        } catch (DirectoryException e) {
            throw (LoginException) new LoginException("Unable to validate identity").initCause(e);
        }
        if (authenticated) {
            return (NuxeoPrincipal) createIdentity(userIdent.getUserName());
        } else {
            return null;
        }
    } else {
        LoginPlugin lp = loginPluginManager.getPlugin(loginPluginName);
        if (lp == null) {
            log.error("Can't authenticate against a null loginModul plugin");
            return null;
        }
        // set the parameters and reinit if needed
        LoginPluginDescriptor lpd = loginPluginManager.getPluginDescriptor(loginPluginName);
        if (!lpd.getInitialized()) {
            Map<String, String> existingParams = lp.getParameters();
            if (existingParams == null) {
                existingParams = new HashMap<String, String>();
            }
            Map<String, String> loginParams = userIdent.getLoginParameters();
            if (loginParams != null) {
                existingParams.putAll(loginParams);
            }
            boolean init = lp.initLoginModule();
            if (init) {
                lpd.setInitialized(true);
            } else {
                log.error("Unable to initialize LoginModulePlugin " + lp.getName());
                return null;
            }
        }

        String username = lp.validatedUserIdentity(userIdent);
        if (username == null) {
            return null;
        } else {
            return (NuxeoPrincipal) createIdentity(username);
        }
    }
}

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

/**
 * Retreives the list of roles associated to current principal
 *///from   ww w . j a  va  2 s. com
protected SSORole[] getRoleSets() throws LoginException {
    try {
        // obtain user roles principals and add it to the subject
        SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager();

        return im.findRolesBySSOSessionId(_requester, _currentSSOSessionId);
    } catch (Exception e) {
        // logger.error("Session login failed for Principal : " + _ssoUserPrincipal, e);
        throw new LoginException("Session login failed for Principal : " + _ssoUserPrincipal);
    }

}

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

/**
 * Retreives the list of roles associated to current principal
 *///from ww w . java  2s  . c om
protected SSORole[] getRoleSets(String requester) throws LoginException {
    try {
        // obtain user roles principals and add it to the subject
        SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager();

        return im.findRolesBySSOSessionId(requester, _currentSSOSessionId);
    } catch (Exception e) {
        logger.error("Session login failed for Principal : " + _ssoUserPrincipal, e);
        throw new LoginException("Session login failed for Principal : " + _ssoUserPrincipal);
    }

}

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

/**
 * Mark a user as no longer active in the database.
 *
 * @param ticket the ticket of the user/*from   w w  w  .j  a  v a  2  s. com*/
 * @throws javax.security.auth.login.LoginException
 *          if the function failed
 */
public static void logout(UserTicket ticket) throws LoginException {
    PreparedStatement ps = null;
    String curSql;
    Connection con = null;
    FxContext inf = FxContext.get();
    try {

        // Obtain a database connection
        con = Database.getDbConnection();

        // EJBLookup user in the database, combined with a update statement to make sure
        // nothing changes between the lookup/set ISLOGGEDIN flag.
        curSql = "UPDATE " + TBL_ACCOUNT_DETAILS + " SET ISLOGGEDIN=? WHERE ID=? AND APPLICATION=?";
        ps = con.prepareStatement(curSql);
        ps.setBoolean(1, false);
        ps.setLong(2, ticket.getUserId());
        ps.setString(3, inf.getApplicationId());

        // Not more than one row should be affected, or the logout failed
        final int rowCount = ps.executeUpdate();
        if (rowCount > 1) {
            // Logout failed.
            LoginException le = new LoginException("Logout for user [" + ticket.getUserId() + "] failed");
            LOG.error(le);
            throw le;
        }

    } catch (SQLException exc) {
        LoginException le = new LoginException("Database error: " + exc.getMessage());
        LOG.error(le);
        throw le;
    } finally {
        Database.closeObjects(FxDBAuthentication.class, con, ps);
    }
}

From source file:org.josso.wls81.agent.mbeans.SSOGatewayLoginModuleImpl.java

/**
 * Retreives the list of roles associated to current principal
 *///from w  w w .j av  a2s .  c o  m
protected WLSJOSSORole[] getRoleSets() throws LoginException {
    try {
        // obtain user roles principals and add it to the subject
        SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager();

        SSORole[] roles = im.findRolesBySSOSessionId(_currentSSOSessionId);
        WLSJOSSORole[] wlsRoles = new WLSJOSSORole[roles.length];

        for (int i = 0; i < roles.length; i++) {
            SSORole role = roles[i];
            WLSJOSSORole wlsRole = new WLSJOSSORole(role);
            wlsRoles[i] = wlsRole;
        }

        return wlsRoles;

    } catch (Exception e) {
        logger.error("Session login failed for Principal : " + _ssoUserPrincipal, e);
        throw new LoginException("Session login failed for Principal : " + _ssoUserPrincipal);
    }

}