List of usage examples for org.apache.shiro.authc DisabledAccountException DisabledAccountException
public DisabledAccountException(Throwable cause)
From source file:org.cherchgk.security.realms.HibernateRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; String username = token.getUsername(); User user = getUser(username);/*w w w. j a v a 2 s . c o m*/ if (user.getBlocked()) { throw new DisabledAccountException("Account for user [" + username + "] is locked"); } return new SimpleAuthenticationInfo(username, ByteSource.Util.bytes(Hex.decode(user.getPassword())), ByteSource.Util.bytes(Hex.decode(user.getPasswordSalt())), getName()); }
From source file:org.sonatype.nexus.jsecurity.realms.external.crowd.CrowdAuthenticatingRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { if (!(authenticationToken instanceof UsernamePasswordToken)) { throw new UnsupportedTokenException("Token of type " + authenticationToken.getClass().getName() + " is not " + "supported. A " + UsernamePasswordToken.class.getName() + " is required."); }/*from w ww .ja v a2 s . c o m*/ UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; String password = new String(token.getPassword()); try { crowdClientHolder.getAuthenticationManager().authenticate(token.getUsername(), password); return new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), getName()); } catch (RemoteException e) { throw new AuthenticationException("Could not retrieve info from Crowd.", e); } catch (InactiveAccountException e) { throw new DisabledAccountException(e); } catch (ExpiredCredentialException e) { throw new IncorrectCredentialsException(e); } catch (InvalidAuthenticationException e) { throw new IncorrectCredentialsException(e); } catch (InvalidAuthorizationTokenException e) { throw new AuthenticationException("Could not retrieve info from Crowd.", e); } catch (ApplicationAccessDeniedException e) { throw new AuthenticationException("Could not retrieve info from Crowd.", e); } }
From source file:org.sonatype.nexus.security.internal.AuthenticatingRealmImpl.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; CUser user;/*from w ww . j av a 2 s . c o m*/ try { user = configuration.readUser(upToken.getUsername()); } catch (UserNotFoundException e) { throw new AccountException("User '" + upToken.getUsername() + "' cannot be retrieved.", e); } if (user.getPassword() == null) { throw new AccountException( "User '" + upToken.getUsername() + "' has no password, cannot authenticate."); } if (CUser.STATUS_ACTIVE.equals(user.getStatus())) { // Check for legacy user that has unsalted password hash // Update if unsalted password hash and valid credentials were specified if (hasLegacyPassword(user) && isValidCredentials(upToken, user)) { reHashPassword(user, new String(upToken.getPassword())); } return createAuthenticationInfo(user); } else if (CUser.STATUS_DISABLED.equals(user.getStatus())) { throw new DisabledAccountException("User '" + upToken.getUsername() + "' is disabled."); } else { throw new AccountException( "User '" + upToken.getUsername() + "' is in illegal status '" + user.getStatus() + "'."); } }
From source file:org.sonatype.security.realms.AuthenticatingRealmImpl.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; CUser user;/*from ww w . j ava2 s .co m*/ try { user = configuration.readUser(upToken.getUsername()); } catch (UserNotFoundException e) { throw new AccountException("User '" + upToken.getUsername() + "' cannot be retrieved.", e); } if (user.getPassword() == null) { throw new AccountException( "User '" + upToken.getUsername() + "' has no password, cannot authenticate."); } if (CUser.STATUS_ACTIVE.equals(user.getStatus())) { // Check for legacy user that has unsalted password hash // Update if unsalted password hash and valid credentials were specified if (hasLegacyPassword(user) && isValidCredentials(upToken, user)) { reHashPassword(user, new String(upToken.getPassword())); } return this.createAuthenticationInfo(user); } else if (CUser.STATUS_DISABLED.equals(user.getStatus())) { throw new DisabledAccountException("User '" + upToken.getUsername() + "' is disabled."); } else { throw new AccountException( "User '" + upToken.getUsername() + "' is in illegal status '" + user.getStatus() + "'."); } }
From source file:org.sonatype.security.realms.XmlAuthenticatingRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; CUser user;/*from ww w . j a va 2s .c o m*/ try { user = configuration.readUser(upToken.getUsername()); } catch (UserNotFoundException e) { throw new AccountException("User '" + upToken.getUsername() + "' cannot be retrieved.", e); } if (user.getPassword() == null) { throw new AccountException( "User '" + upToken.getUsername() + "' has no password, cannot authenticate."); } if (CUser.STATUS_ACTIVE.equals(user.getStatus())) { //Check for legacy user that has unsalted password hash //Update if legacy user, and valid credentials were specified if (this.isLegacyUser(user) && this.isValidCredentials(upToken, user)) { this.reHashPassword(user, new String(upToken.getPassword())); } return this.createAuthenticationInfo(user); } else if (CUser.STATUS_DISABLED.equals(user.getStatus())) { throw new DisabledAccountException("User '" + upToken.getUsername() + "' is disabled."); } else { throw new AccountException( "User '" + upToken.getUsername() + "' is in illegal status '" + user.getStatus() + "'."); } }
From source file:org.xaloon.core.security.shiro.AbstractRealm.java
License:Apache License
protected AuthenticationInfo doGetAuthenticationInfoInternal(String username) { org.xaloon.core.api.security.model.UserDetails userDetailPrincipal = getLoginService() .loadUserDetails(username);/*from ww w . j a va 2 s .c o m*/ if (userDetailPrincipal == null) { throw new CredentialsException(SecurityFacade.INVALID_USERNAME_PASSWORD); } if (!userDetailPrincipal.isEnabled()) { throw new DisabledAccountException(SecurityFacade.ACCOUNT_DISABLED); } if (!userDetailPrincipal.isAccountNonExpired()) { throw new ExpiredCredentialsException(SecurityFacade.ACCOUNT_EXPIRED); } if (!userDetailPrincipal.isAccountNonLocked()) { throw new LockedAccountException(SecurityFacade.ACCOUNT_LOCKED); } if (!userDetailPrincipal.isCredentialsNonExpired()) { throw new ExpiredCredentialsException(SecurityFacade.CREDENTIALS_EXPIRED); } //Everything should be fine now. User userPrincipal = getUserDao().getUserByUsername(username); Collection<Object> principalCollection = new ArrayList<Object>(); principalCollection.add(userDetailPrincipal); principalCollection.add(userPrincipal); return new SimpleAuthenticationInfo(new SimplePrincipalCollection(principalCollection, getName()), userDetailPrincipal.getPassword(), getName()); }