Search in sources :

Example 11 with AccountLockedException

use of javax.security.auth.login.AccountLockedException in project cas by apereo.

the class ShiroAuthenticationHandler method authenticateUsernamePasswordInternal.

@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential transformedCredential, final String originalPassword) throws GeneralSecurityException {
    try {
        val token = new UsernamePasswordToken(transformedCredential.getUsername(), transformedCredential.getPassword());
        if (transformedCredential instanceof RememberMeUsernamePasswordCredential) {
            token.setRememberMe(RememberMeUsernamePasswordCredential.class.cast(transformedCredential).isRememberMe());
        }
        val currentUser = getCurrentExecutingSubject();
        currentUser.login(token);
        checkSubjectRolesAndPermissions(currentUser);
        val strategy = getPasswordPolicyHandlingStrategy();
        val messageList = new ArrayList<MessageDescriptor>();
        if (strategy != null) {
            LOGGER.debug("Attempting to examine and handle password policy via [{}]", strategy.getClass().getSimpleName());
            val principal = this.principalFactory.createPrincipal(token.getUsername());
            messageList.addAll(strategy.handle(principal, getPasswordPolicyConfiguration()));
        }
        return createAuthenticatedSubjectResult(transformedCredential, currentUser, messageList);
    } catch (final UnknownAccountException uae) {
        throw new AccountNotFoundException(uae.getMessage());
    } catch (final LockedAccountException | ExcessiveAttemptsException lae) {
        throw new AccountLockedException(lae.getMessage());
    } catch (final ExpiredCredentialsException eae) {
        throw new CredentialExpiredException(eae.getMessage());
    } catch (final DisabledAccountException eae) {
        throw new AccountDisabledException(eae.getMessage());
    } catch (final AuthenticationException ice) {
        throw new FailedLoginException(ice.getMessage());
    }
}
Also used : lombok.val(lombok.val) DisabledAccountException(org.apache.shiro.authc.DisabledAccountException) AccountLockedException(javax.security.auth.login.AccountLockedException) AuthenticationException(org.apache.shiro.authc.AuthenticationException) UnknownAccountException(org.apache.shiro.authc.UnknownAccountException) ArrayList(java.util.ArrayList) ExcessiveAttemptsException(org.apache.shiro.authc.ExcessiveAttemptsException) ExpiredCredentialsException(org.apache.shiro.authc.ExpiredCredentialsException) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) FailedLoginException(javax.security.auth.login.FailedLoginException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) CredentialExpiredException(javax.security.auth.login.CredentialExpiredException) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential) LockedAccountException(org.apache.shiro.authc.LockedAccountException) AccountDisabledException(org.apereo.cas.authentication.exceptions.AccountDisabledException)

Aggregations

AccountLockedException (javax.security.auth.login.AccountLockedException)11 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)10 FailedLoginException (javax.security.auth.login.FailedLoginException)9 lombok.val (lombok.val)6 AccountExpiredException (javax.security.auth.login.AccountExpiredException)5 AccountDisabledException (org.apereo.cas.authentication.exceptions.AccountDisabledException)5 AccountPasswordMustChangeException (org.apereo.cas.authentication.exceptions.AccountPasswordMustChangeException)4 SimpleCredentials (javax.jcr.SimpleCredentials)3 CredentialExpiredException (javax.security.auth.login.CredentialExpiredException)3 ArrayList (java.util.ArrayList)2 CredentialException (javax.security.auth.login.CredentialException)2 LoginException (javax.security.auth.login.LoginException)2 HttpResponse (org.apache.http.HttpResponse)2 User (org.apache.jackrabbit.api.security.user.User)2 User (com.thinkbiganalytics.metadata.api.user.User)1 User (com.thinkbiganalytics.security.rest.model.User)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 GeneralSecurityException (java.security.GeneralSecurityException)1 LinkedHashMap (java.util.LinkedHashMap)1