Example usage for org.springframework.security.authentication CredentialsExpiredException CredentialsExpiredException

List of usage examples for org.springframework.security.authentication CredentialsExpiredException CredentialsExpiredException

Introduction

In this page you can find the example usage for org.springframework.security.authentication CredentialsExpiredException CredentialsExpiredException.

Prototype

public CredentialsExpiredException(String msg, Throwable t) 

Source Link

Document

Constructs a CredentialsExpiredException with the specified message and root cause.

Usage

From source file:org.codehaus.groovy.grails.plugins.springsecurity.DefaultPostAuthenticationChecks.java

public void check(UserDetails user) {
    if (!user.isCredentialsNonExpired()) {
        log.debug("User account credentials have expired");

        throw new CredentialsExpiredException(
                messages.getMessage("AbstractUserDetailsAuthenticationProvider.credentialsExpired",
                        "User credentials have expired"),
                user);//from w  w w  .  ja  v  a 2s .  c o  m
    }
}

From source file:org.carewebframework.vista.security.base.BaseAuthenticationProvider.java

@SuppressWarnings("deprecation")
private void checkAuthResult(AuthResult result, IUser user) throws AuthenticationException {
    switch (result.status) {
    case SUCCESS:
        return;/*www  . j  ava 2 s  . co  m*/

    case CANCELED:
        throw new AuthenticationCancelledException(
                StringUtils.defaultIfEmpty(result.reason, "Authentication attempt was cancelled."));

    case EXPIRED:
        throw new CredentialsExpiredException(
                StringUtils.defaultIfEmpty(result.reason, "Your password has expired."), user);

    case FAILURE:
        throw new BadCredentialsException(
                StringUtils.defaultIfEmpty(result.reason, "Your username or password was not recognized."));

    case LOCKED:
        throw new LockedException(StringUtils.defaultIfEmpty(result.reason,
                "Your user account has been locked and cannot be accessed."));

    case NOLOGINS:
        throw new DisabledException(
                StringUtils.defaultIfEmpty(result.reason, "Logins are currently disabled."));
    }
}

From source file:de.theit.jenkins.crowd.CrowdAuthenticationManager.java

/**
 * {@inheritDoc}// w ww . j  a  v a2  s.c  o m
 * 
 * @see org.springframework.security.AuthenticationManager#authenticate(org.springframework.security.Authentication)
 */
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String username = authentication.getPrincipal().toString();

    // checking whether there's already a SSO token
    if (null == authentication.getCredentials() && authentication instanceof CrowdAuthenticationToken
            && null != ((CrowdAuthenticationToken) authentication).getSSOToken()) {
        // SSO token available => user already authenticated
        if (LOG.isLoggable(Level.FINER)) {
            LOG.finer("User '" + username + "' already authenticated");
        }
        return authentication;
    }

    String password = authentication.getCredentials().toString();

    // ensure that the group is available, active and that the user
    // is a member of it
    if (!this.configuration.isGroupMember(username)) {
        throw new InsufficientAuthenticationException(
                userNotValid(username, this.configuration.allowedGroupNames));
    }

    String displayName = null;
    try {
        // authenticate user
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Authenticating user: " + username);
        }
        User user = this.configuration.crowdClient.authenticateUser(username, password);
        displayName = user.getDisplayName();
    } catch (UserNotFoundException ex) {
        if (LOG.isLoggable(Level.INFO)) {
            LOG.info(userNotFound(username));
        }
        throw new BadCredentialsException(userNotFound(username), ex);
    } catch (ExpiredCredentialException ex) {
        LOG.warning(expiredCredentials(username));
        throw new CredentialsExpiredException(expiredCredentials(username), ex);
    } catch (InactiveAccountException ex) {
        LOG.warning(accountExpired(username));
        throw new AccountExpiredException(accountExpired(username), ex);
    } catch (ApplicationPermissionException ex) {
        LOG.warning(applicationPermission());
        throw new AuthenticationServiceException(applicationPermission(), ex);
    } catch (InvalidAuthenticationException ex) {
        LOG.warning(invalidAuthentication());
        throw new AuthenticationServiceException(invalidAuthentication(), ex);
    } catch (OperationFailedException ex) {
        LOG.log(Level.SEVERE, operationFailed(), ex);
        throw new AuthenticationServiceException(operationFailed(), ex);
    }

    // user successfully authenticated
    // => retrieve the list of groups the user is a member of
    List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();

    // add the "authenticated" authority to the list of granted
    // authorities...
    authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY);
    // ..and finally all authorities retrieved from the Crowd server
    authorities.addAll(this.configuration.getAuthoritiesForUser(username));

    // user successfully authenticated => create authentication token
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("User successfully authenticated; creating authentication token");
    }

    return new CrowdAuthenticationToken(username, password, authorities, null, displayName);
}

From source file:iplatform.admin.ui.server.auth.ad.ActiveDirectoryLdapAuthenticationProvider.java

void raiseExceptionForErrorCode(int code, NamingException exception) {
    //String hexString = Integer.toHexString(code);
    //Throwable cause = new ActiveDirectoryAuthenticationException(hexString, exception.getMessage(), exception);
    Throwable cause = new Exception(exception.getMessage());
    switch (code) {
    case PASSWORD_EXPIRED:
        throw new CredentialsExpiredException(messages.getMessage(
                "LdapAuthenticationProvider.credentialsExpired", "User credentials have expired"), cause);
    case ACCOUNT_DISABLED:
        throw new DisabledException(
                messages.getMessage("LdapAuthenticationProvider.disabled", "User is disabled"), cause);
    case ACCOUNT_EXPIRED:
        throw new AccountExpiredException(
                messages.getMessage("LdapAuthenticationProvider.expired", "User account has expired"), cause);
    case ACCOUNT_LOCKED:
        throw new LockedException(
                messages.getMessage("LdapAuthenticationProvider.locked", "User account is locked"), cause);
    default://from  w  ww  .j ava 2s  . c o m
        throw badCredentials(cause);
    }
}