Java Code Examples for javax.security.auth.login.LoginException#initCause()

The following examples show how to use javax.security.auth.login.LoginException#initCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecureIdentityLoginModule.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean commit() throws LoginException
{
   Principal principal = new SimplePrincipal(username);
   SubjectActions.addPrincipals(subject, principal);
   sharedState.put("javax.security.auth.login.name", username);
   // Decode the encrypted password
   try
   {
      char[] decodedPassword = decode(password);
      PasswordCredential cred = new PasswordCredential(username, decodedPassword);
      SubjectActions.addCredentials(subject, cred);
   }
   catch(Exception e)
   {
      LoginException le = new LoginException(e.getLocalizedMessage());
      le.initCause(e);
      throw le;
   }
   return true;
}
 
Example 2
Source File: JWTLoginModule.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public boolean login() throws LoginException {
    SecurityAssociationCallback sac = new SecurityAssociationCallback();
    try {
        callbackHandler.handle(new Callback[]{sac});
        JWTCredential jwtCredential = (JWTCredential) sac.getCredential();
        // Validate the credential by
        jwtPrincipal = validate(jwtCredential);
    } catch (Exception e) {
        if (logExceptions) {
            log.infof(e, "Failed to validate token");
        }
        LoginException ex = new LoginException("Failed to validate token");
        ex.initCause(e);
        throw ex;
    }

    loginOk = true;
    return true;
}
 
Example 3
Source File: PBEIdentityLoginModule.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean commit() throws LoginException
{
   Principal principal = new SimplePrincipal(username);
   SubjectActions.addPrincipals(subject, principal);
   sharedState.put("javax.security.auth.login.name", username);
   // Decode the encrypted password
   try
   {
      char[] decodedPassword = decode(password);
      PasswordCredential cred = new PasswordCredential(username, decodedPassword);
      SubjectActions.addCredentials(subject, cred);
   }
   catch(Exception e)
   {
      LoginException le = new LoginException(e.getLocalizedMessage());
      le.initCause(e);
      throw le;
   }
   return true;
}
 
Example 4
Source File: LoginModule.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean login () throws LoginException
{
    this.userInformation = null;

    final AuthenticationImplementation auth = Activator.getInstance ().getAuthentication ();

    try
    {
        this.userInformation = auth.authenticate ( new JavaCallbackHandler ( this.callbackHandler ) ).get ();
    }
    catch ( final Exception e )
    {
        final LoginException loginException = new LoginException ();
        loginException.initCause ( e );
        throw loginException;
    }

    this.loggedIn = this.userInformation != null;

    return this.loggedIn;
}
 
Example 5
Source File: PamLoginModule.java    From atlas with Apache License 2.0 6 votes vote down vote up
private boolean performLogin() throws LoginException
{
    try
    {
        UnixUser user = pam.authenticate(username, password);
        principal = new PamPrincipal(user);
        authSucceeded = true;

        if (LOG.isDebugEnabled())
            LOG.debug("user " + username );
        return true;
    }
    catch (PAMException ex)
    {
        LoginException le = new FailedLoginException("Invalid username or password");
        le.initCause(ex);
        throw le;
    }
}
 
Example 6
Source File: PamLoginModule.java    From ranger with Apache License 2.0 6 votes vote down vote up
private boolean performLogin() throws LoginException
  {
      try
      {
if (_passwordchar != null) {
                              UnixUser user = _pam.authenticate(_username, String.valueOf(_passwordchar));
                              _principal = new PamPrincipal(user);
                              _authSucceeded = true;
                              return true;
                      } else {
                              throw new PAMException("Password is Null or Empty!!!");
                      }
      }
      catch (PAMException ex)
      {
          LoginException le = new FailedLoginException("Invalid username or password");
          le.initCause(ex);
          throw le;
      }
  }
 
Example 7
Source File: PamLoginModule.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void obtainUserAndPassword() throws LoginException
{
    if (callbackHandler == null)
    {
        throw new LoginException("Error: no CallbackHandler available  to gather authentication information from the user");
    }

    try
    {
        NameCallback nameCallback = new NameCallback("username");
        PasswordCallback passwordCallback = new PasswordCallback("password", false);

        invokeCallbackHandler(nameCallback, passwordCallback);

        initUserName(nameCallback);
        initPassword(passwordCallback);
    }
    catch (IOException | UnsupportedCallbackException ex)
    {
        LoginException le = new LoginException("Error in callbacks");
        le.initCause(ex);
        throw le;
    }
}
 
Example 8
Source File: PamLoginModule.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void createPam(String service) throws LoginException
{
    try
    {
        pam = new PAM(service);
    }
    catch (PAMException ex)
    {
        LoginException le = new LoginException("Error initializing PAM");
        le.initCause(ex);
        throw le;
    }
}
 
Example 9
Source File: DefaultPicketLinkLogger.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public LoginException authLoginError(Throwable t) {
    LoginException loginException = new LoginException("Error during login/authentication");

    loginException.initCause(t);

    return loginException;
}
 
Example 10
Source File: SaltedDatabaseServerLoginModule.java    From PBKDF2 with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Generic helper: Use JBoss SecurityActions to load a class, then create a new instance.
 *
 * @param <T> generic return type
 * @param name FQCN of the class to instantiate.
 * @param clazz Expected type, used for PicketBox logging.
 * @return Insance. On error/exception, this method registers the
 *         exception via {{@link #setValidateError(Throwable)} and returns
 *         <code>null</code>.
 */
@SuppressWarnings("unchecked")
protected <T> T newInstance(final String name, final Class<T> clazz) {
	T r = null;
	try {
	   Class<?> loadedClass = getClass().getClassLoader().loadClass(name);
	   r = (T) loadedClass.newInstance();
	} catch(Exception e) {
	    LoginException le = new LoginException(PicketBoxMessages.MESSAGES.failedToInstantiateClassMessage(clazz));
	    le.initCause(e);
	    setValidateError(le);
	}
	return r;
}
 
Example 11
Source File: SunPKCS11.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Log out from this provider
 *
 * @exception LoginException if the logout operation fails
 * @exception SecurityException if the does not pass a security check for
 *  <code>SecurityPermission("authProvider.<i>name</i>")</code>,
 *  where <i>name</i> is the value returned by
 *  this provider's <code>getName</code> method
 */
public void logout() throws LoginException {

    // security check

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission
            (new SecurityPermission("authProvider." + this.getName()));
    }

    if (hasValidToken() == false) {
        // app may call logout for cleanup, allow
        return;
    }

    if ((token.tokenInfo.flags & CKF_LOGIN_REQUIRED) == 0) {
        if (debug != null) {
            debug.println("logout operation not required for token - " +
                            "ignoring logout request");
        }
        return;
    }

    try {
        if (token.isLoggedInNow(null) == false) {
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
    } catch (PKCS11Exception e) {
        // ignore
    }

    // perform token logout

    Session session = null;
    try {
        session = token.getOpSession();
        p11.C_Logout(session.id());
        if (debug != null) {
            debug.println("logout succeeded");
        }
    } catch (PKCS11Exception pe) {
        if (pe.getErrorCode() == CKR_USER_NOT_LOGGED_IN) {
            // let this one go
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
        LoginException le = new LoginException();
        le.initCause(pe);
        throw le;
    } finally {
        token.releaseSession(session);
    }
}
 
Example 12
Source File: SunPKCS11.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Log out from this provider
 *
 * @exception LoginException if the logout operation fails
 * @exception SecurityException if the does not pass a security check for
 *  <code>SecurityPermission("authProvider.<i>name</i>")</code>,
 *  where <i>name</i> is the value returned by
 *  this provider's <code>getName</code> method
 */
public void logout() throws LoginException {

    // security check

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission
            (new SecurityPermission("authProvider." + this.getName()));
    }

    if (hasValidToken() == false) {
        // app may call logout for cleanup, allow
        return;
    }

    if ((token.tokenInfo.flags & CKF_LOGIN_REQUIRED) == 0) {
        if (debug != null) {
            debug.println("logout operation not required for token - " +
                            "ignoring logout request");
        }
        return;
    }

    try {
        if (token.isLoggedInNow(null) == false) {
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
    } catch (PKCS11Exception e) {
        // ignore
    }

    // perform token logout

    Session session = null;
    try {
        session = token.getOpSession();
        p11.C_Logout(session.id());
        if (debug != null) {
            debug.println("logout succeeded");
        }
    } catch (PKCS11Exception pe) {
        if (pe.getErrorCode() == CKR_USER_NOT_LOGGED_IN) {
            // let this one go
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
        LoginException le = new LoginException();
        le.initCause(pe);
        throw le;
    } finally {
        token.releaseSession(session);
    }
}
 
Example 13
Source File: SunPKCS11.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Log out from this provider
 *
 * @exception LoginException if the logout operation fails
 * @exception SecurityException if the does not pass a security check for
 *  <code>SecurityPermission("authProvider.<i>name</i>")</code>,
 *  where <i>name</i> is the value returned by
 *  this provider's <code>getName</code> method
 */
public void logout() throws LoginException {

    // security check

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission
            (new SecurityPermission("authProvider." + this.getName()));
    }

    if (hasValidToken() == false) {
        // app may call logout for cleanup, allow
        return;
    }

    if ((token.tokenInfo.flags & CKF_LOGIN_REQUIRED) == 0) {
        if (debug != null) {
            debug.println("logout operation not required for token - " +
                            "ignoring logout request");
        }
        return;
    }

    try {
        if (token.isLoggedInNow(null) == false) {
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
    } catch (PKCS11Exception e) {
        // ignore
    }

    // perform token logout

    Session session = null;
    try {
        session = token.getOpSession();
        p11.C_Logout(session.id());
        if (debug != null) {
            debug.println("logout succeeded");
        }
    } catch (PKCS11Exception pe) {
        if (pe.getErrorCode() == CKR_USER_NOT_LOGGED_IN) {
            // let this one go
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
        LoginException le = new LoginException();
        le.initCause(pe);
        throw le;
    } finally {
        token.releaseSession(session);
    }
}
 
Example 14
Source File: SunPKCS11.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Log out from this provider
 *
 * @exception LoginException if the logout operation fails
 * @exception SecurityException if the does not pass a security check for
 *  <code>SecurityPermission("authProvider.<i>name</i>")</code>,
 *  where <i>name</i> is the value returned by
 *  this provider's <code>getName</code> method
 */
public void logout() throws LoginException {

    // security check

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission
            (new SecurityPermission("authProvider." + this.getName()));
    }

    if (hasValidToken() == false) {
        // app may call logout for cleanup, allow
        return;
    }

    if ((token.tokenInfo.flags & CKF_LOGIN_REQUIRED) == 0) {
        if (debug != null) {
            debug.println("logout operation not required for token - " +
                            "ignoring logout request");
        }
        return;
    }

    try {
        if (token.isLoggedInNow(null) == false) {
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
    } catch (PKCS11Exception e) {
        // ignore
    }

    // perform token logout

    Session session = null;
    try {
        session = token.getOpSession();
        p11.C_Logout(session.id());
        if (debug != null) {
            debug.println("logout succeeded");
        }
    } catch (PKCS11Exception pe) {
        if (pe.getErrorCode() == CKR_USER_NOT_LOGGED_IN) {
            // let this one go
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
        LoginException le = new LoginException();
        le.initCause(pe);
        throw le;
    } finally {
        token.releaseSession(session);
    }
}
 
Example 15
Source File: SunPKCS11.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Log out from this provider
 *
 * @exception LoginException if the logout operation fails
 * @exception SecurityException if the does not pass a security check for
 *  <code>SecurityPermission("authProvider.<i>name</i>")</code>,
 *  where <i>name</i> is the value returned by
 *  this provider's <code>getName</code> method
 */
public void logout() throws LoginException {

    // security check

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission
            (new SecurityPermission("authProvider." + this.getName()));
    }

    if (hasValidToken() == false) {
        // app may call logout for cleanup, allow
        return;
    }

    if ((token.tokenInfo.flags & CKF_LOGIN_REQUIRED) == 0) {
        if (debug != null) {
            debug.println("logout operation not required for token - " +
                            "ignoring logout request");
        }
        return;
    }

    try {
        if (token.isLoggedInNow(null) == false) {
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
    } catch (PKCS11Exception e) {
        // ignore
    }

    // perform token logout

    Session session = null;
    try {
        session = token.getOpSession();
        p11.C_Logout(session.id());
        if (debug != null) {
            debug.println("logout succeeded");
        }
    } catch (PKCS11Exception pe) {
        if (pe.getErrorCode() == CKR_USER_NOT_LOGGED_IN) {
            // let this one go
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
        LoginException le = new LoginException();
        le.initCause(pe);
        throw le;
    } finally {
        token.releaseSession(session);
    }
}
 
Example 16
Source File: SunPKCS11.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Log out from this provider
 *
 * @exception LoginException if the logout operation fails
 * @exception SecurityException if the does not pass a security check for
 *  <code>SecurityPermission("authProvider.<i>name</i>")</code>,
 *  where <i>name</i> is the value returned by
 *  this provider's <code>getName</code> method
 */
public void logout() throws LoginException {

    // security check

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission
            (new SecurityPermission("authProvider." + this.getName()));
    }

    if (hasValidToken() == false) {
        // app may call logout for cleanup, allow
        return;
    }

    if ((token.tokenInfo.flags & CKF_LOGIN_REQUIRED) == 0) {
        if (debug != null) {
            debug.println("logout operation not required for token - " +
                            "ignoring logout request");
        }
        return;
    }

    try {
        if (token.isLoggedInNow(null) == false) {
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
    } catch (PKCS11Exception e) {
        // ignore
    }

    // perform token logout

    Session session = null;
    try {
        session = token.getOpSession();
        p11.C_Logout(session.id());
        if (debug != null) {
            debug.println("logout succeeded");
        }
    } catch (PKCS11Exception pe) {
        if (pe.getErrorCode() == CKR_USER_NOT_LOGGED_IN) {
            // let this one go
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
        LoginException le = new LoginException();
        le.initCause(pe);
        throw le;
    } finally {
        token.releaseSession(session);
    }
}
 
Example 17
Source File: SunPKCS11.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Log out from this provider
 *
 * @exception LoginException if the logout operation fails
 * @exception SecurityException if the does not pass a security check for
 *  <code>SecurityPermission("authProvider.<i>name</i>")</code>,
 *  where <i>name</i> is the value returned by
 *  this provider's <code>getName</code> method
 */
public void logout() throws LoginException {

    // security check

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission
            (new SecurityPermission("authProvider." + this.getName()));
    }

    if (hasValidToken() == false) {
        // app may call logout for cleanup, allow
        return;
    }

    if ((token.tokenInfo.flags & CKF_LOGIN_REQUIRED) == 0) {
        if (debug != null) {
            debug.println("logout operation not required for token - " +
                            "ignoring logout request");
        }
        return;
    }

    try {
        if (token.isLoggedInNow(null) == false) {
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
    } catch (PKCS11Exception e) {
        // ignore
    }

    // perform token logout

    Session session = null;
    try {
        session = token.getOpSession();
        p11.C_Logout(session.id());
        if (debug != null) {
            debug.println("logout succeeded");
        }
    } catch (PKCS11Exception pe) {
        if (pe.getErrorCode() == CKR_USER_NOT_LOGGED_IN) {
            // let this one go
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
        LoginException le = new LoginException();
        le.initCause(pe);
        throw le;
    } finally {
        token.releaseSession(session);
    }
}
 
Example 18
Source File: SunPKCS11.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Log out from this provider
 *
 * @exception LoginException if the logout operation fails
 * @exception SecurityException if the does not pass a security check for
 *  <code>SecurityPermission("authProvider.<i>name</i>")</code>,
 *  where <i>name</i> is the value returned by
 *  this provider's <code>getName</code> method
 */
public void logout() throws LoginException {

    // security check

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission
            (new SecurityPermission("authProvider." + this.getName()));
    }

    if (hasValidToken() == false) {
        // app may call logout for cleanup, allow
        return;
    }

    if ((token.tokenInfo.flags & CKF_LOGIN_REQUIRED) == 0) {
        if (debug != null) {
            debug.println("logout operation not required for token - " +
                            "ignoring logout request");
        }
        return;
    }

    try {
        if (token.isLoggedInNow(null) == false) {
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
    } catch (PKCS11Exception e) {
        // ignore
    }

    // perform token logout

    Session session = null;
    try {
        session = token.getOpSession();
        p11.C_Logout(session.id());
        if (debug != null) {
            debug.println("logout succeeded");
        }
    } catch (PKCS11Exception pe) {
        if (pe.getErrorCode() == CKR_USER_NOT_LOGGED_IN) {
            // let this one go
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
        LoginException le = new LoginException();
        le.initCause(pe);
        throw le;
    } finally {
        token.releaseSession(session);
    }
}
 
Example 19
Source File: SunPKCS11.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Log out from this provider
 *
 * @exception LoginException if the logout operation fails
 * @exception SecurityException if the does not pass a security check for
 *  <code>SecurityPermission("authProvider.<i>name</i>")</code>,
 *  where <i>name</i> is the value returned by
 *  this provider's <code>getName</code> method
 */
public void logout() throws LoginException {

    // security check

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission
            (new SecurityPermission("authProvider." + this.getName()));
    }

    if (hasValidToken() == false) {
        // app may call logout for cleanup, allow
        return;
    }

    if ((token.tokenInfo.flags & CKF_LOGIN_REQUIRED) == 0) {
        if (debug != null) {
            debug.println("logout operation not required for token - " +
                            "ignoring logout request");
        }
        return;
    }

    try {
        if (token.isLoggedInNow(null) == false) {
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
    } catch (PKCS11Exception e) {
        // ignore
    }

    // perform token logout

    Session session = null;
    try {
        session = token.getOpSession();
        p11.C_Logout(session.id());
        if (debug != null) {
            debug.println("logout succeeded");
        }
    } catch (PKCS11Exception pe) {
        if (pe.getErrorCode() == CKR_USER_NOT_LOGGED_IN) {
            // let this one go
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
        LoginException le = new LoginException();
        le.initCause(pe);
        throw le;
    } finally {
        token.releaseSession(session);
    }
}
 
Example 20
Source File: SunPKCS11.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Log out from this provider
 *
 * @exception LoginException if the logout operation fails
 * @exception SecurityException if the does not pass a security check for
 *  <code>SecurityPermission("authProvider.<i>name</i>")</code>,
 *  where <i>name</i> is the value returned by
 *  this provider's <code>getName</code> method
 */
public void logout() throws LoginException {

    // security check

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission
            (new SecurityPermission("authProvider." + this.getName()));
    }

    if (hasValidToken() == false) {
        // app may call logout for cleanup, allow
        return;
    }

    if ((token.tokenInfo.flags & CKF_LOGIN_REQUIRED) == 0) {
        if (debug != null) {
            debug.println("logout operation not required for token - " +
                            "ignoring logout request");
        }
        return;
    }

    try {
        if (token.isLoggedInNow(null) == false) {
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
    } catch (PKCS11Exception e) {
        // ignore
    }

    // perform token logout

    Session session = null;
    try {
        session = token.getOpSession();
        p11.C_Logout(session.id());
        if (debug != null) {
            debug.println("logout succeeded");
        }
    } catch (PKCS11Exception pe) {
        if (pe.getErrorCode() == CKR_USER_NOT_LOGGED_IN) {
            // let this one go
            if (debug != null) {
                debug.println("user not logged in");
            }
            return;
        }
        LoginException le = new LoginException();
        le.initCause(pe);
        throw le;
    } finally {
        token.releaseSession(session);
    }
}