public AuthenticationException resolveException(LoginException e) { return new LockedException("This is just a test!"); } });
public void check(UserDetails user) { if (!user.isAccountNonLocked()) { logger.debug("User account is locked"); throw new LockedException(messages.getMessage( "AbstractUserDetailsAuthenticationProvider.locked", "User account is locked")); } if (!user.isEnabled()) { logger.debug("User account is disabled"); throw new DisabledException(messages.getMessage( "AbstractUserDetailsAuthenticationProvider.disabled", "User is disabled")); } if (!user.isAccountNonExpired()) { logger.debug("User account is expired"); throw new AccountExpiredException(messages.getMessage( "AbstractUserDetailsAuthenticationProvider.expired", "User account has expired")); } } }
@Test public void authenticateWhenPostAuthenticationChecksFail() { when(this.userDetailsService.findByUsername(any())).thenReturn(Mono.just(this.user)); doThrow(new LockedException("account is locked")).when(this.postAuthenticationChecks).check(any()); when(this.encoder.matches(any(), any())).thenReturn(true); this.manager.setPasswordEncoder(this.encoder); this.manager.setPostAuthenticationChecks(this.postAuthenticationChecks); assertThatExceptionOfType(LockedException.class) .isThrownBy(() -> this.manager.authenticate(new UsernamePasswordAuthenticationToken(this.user, this.user.getPassword())).block()) .withMessage("account is locked"); verify(this.postAuthenticationChecks).check(eq(this.user)); }
@Test public void testLogsEvents() { AuthenticationFailureDisabledEvent event = new AuthenticationFailureDisabledEvent( getAuthentication(), new LockedException("TEST")); LoggerListener listener = new LoggerListener(); listener.onApplicationEvent(event); } }
public void check(UserDetails user) { if (!user.isAccountNonLocked()) { logger.debug("User account is locked"); throw new LockedException(messages.getMessage( "AbstractUserDetailsAuthenticationProvider.locked", "User account is locked")); } if (!user.isEnabled()) { logger.debug("User account is disabled"); throw new DisabledException(messages.getMessage( "AbstractUserDetailsAuthenticationProvider.disabled", "User is disabled")); } if (!user.isAccountNonExpired()) { logger.debug("User account is expired"); throw new AccountExpiredException(messages.getMessage( "AbstractUserDetailsAuthenticationProvider.expired", "User account has expired")); } } }
private void raiseExceptionForErrorCode(int code, NamingException exception) { String hexString = Integer.toHexString(code); Throwable cause = new ActiveDirectoryAuthenticationException(hexString, exception.getMessage(), exception); 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: throw badCredentials(cause); } }
@Test @SuppressWarnings("deprecation") public void statusExceptionIsPublished() throws Exception { AuthenticationManager parent = mock(AuthenticationManager.class); final LockedException expected = new LockedException(""); ProviderManager mgr = new ProviderManager( Arrays.asList(createProviderWhichThrows(expected)), parent); final Authentication authReq = mock(Authentication.class); AuthenticationEventPublisher publisher = mock(AuthenticationEventPublisher.class); mgr.setAuthenticationEventPublisher(publisher); try { mgr.authenticate(authReq); fail("Expected exception"); } catch (LockedException e) { assertThat(e).isSameAs(expected); } verify(publisher).publishAuthenticationFailure(expected, authReq); }
@Override protected DirContextOperations doAuthentication( UsernamePasswordAuthenticationToken authentication) { try { return getAuthenticator().authenticate(authentication); } catch (PasswordPolicyException ppe) { // The only reason a ppolicy exception can occur during a bind is that the // account is locked. throw new LockedException(this.messages.getMessage( ppe.getStatus().getErrorCode(), ppe.getStatus().getDefaultMessage())); } catch (UsernameNotFoundException notFound) { if (this.hideUserNotFoundExceptions) { throw new BadCredentialsException(this.messages.getMessage( "LdapAuthenticationProvider.badCredentials", "Bad credentials")); } else { throw notFound; } } catch (NamingException ldapAccessFailure) { throw new InternalAuthenticationServiceException( ldapAccessFailure.getMessage(), ldapAccessFailure); } }
publisher.publishAuthenticationFailure(new DisabledException(""), a); publisher.publishAuthenticationFailure(new DisabledException("", cause), a); publisher.publishAuthenticationFailure(new LockedException(""), a); publisher.publishAuthenticationFailure(new LockedException("", cause), a); publisher.publishAuthenticationFailure(new AuthenticationServiceException(""), a); publisher.publishAuthenticationFailure(new AuthenticationServiceException("",
public void check(UserDetails user) { if (!user.isAccountNonLocked()) { throw new LockedException(messages.getMessage( "AccountStatusUserDetailsChecker.locked", "User account is locked")); } if (!user.isEnabled()) { throw new DisabledException(messages.getMessage( "AccountStatusUserDetailsChecker.disabled", "User is disabled")); } if (!user.isAccountNonExpired()) { throw new AccountExpiredException( messages.getMessage("AccountStatusUserDetailsChecker.expired", "User account has expired")); } if (!user.isCredentialsNonExpired()) { throw new CredentialsExpiredException(messages.getMessage( "AccountStatusUserDetailsChecker.credentialsExpired", "User credentials have expired")); } } }
public void check(UserDetails user) { if (!user.isAccountNonLocked()) { throw new LockedException(messages.getMessage( "AccountStatusUserDetailsChecker.locked", "User account is locked")); } if (!user.isEnabled()) { throw new DisabledException(messages.getMessage( "AccountStatusUserDetailsChecker.disabled", "User is disabled")); } if (!user.isAccountNonExpired()) { throw new AccountExpiredException( messages.getMessage("AccountStatusUserDetailsChecker.expired", "User account has expired")); } if (!user.isCredentialsNonExpired()) { throw new CredentialsExpiredException(messages.getMessage( "AccountStatusUserDetailsChecker.credentialsExpired", "User credentials have expired")); } } }
else if(user.isLocked()) { if(canUnlockUser(user)){ logger.info("|*|*| Unlocking account. Account Lock Timer Over.. |*|*|*|"); loginHistoryService.lockUserAccount(user.getUserId(), false); } else { throw new LockedException("Account is Locked"); } }
else if(user.isLocked()) { if(canUnlockUser(user)){ logger.info("|*|*| Unlocking account. Account Lock Timer Over.. |*|*|*|"); loginHistoryService.lockUserAccount(user.getUserId(), false); } else { throw new LockedException("Account is Locked"); } }
private void assertUserNotLocked(String username) { if(isLockMechanismDisabled()) { return; } Date logindate = lastFailedLogin.get(username); if(logindate != null && isWaitTimeOver(logindate)) { accessCounter.remove(username); lastFailedLogin.remove(username); } if (accessCounter.get(username) != null && accessCounter.get(username) >= maxLoginFailures) { throw new LockedException("The user '" + username + "' is temporary locked."); } }
public void check(UserDetails user) { if (!user.isAccountNonLocked()) { logger.debug("User account is locked"); throw new LockedException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.locked", "User account is locked"), user); } if (!user.isEnabled()) { logger.debug("User account is disabled"); throw new DisabledException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.disabled", "User is disabled"), user); } if (!user.isAccountNonExpired()) { logger.debug("User account is expired"); throw new AccountExpiredException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.expired", "User account has expired"), user); } } }
public void check( UserDetails user ) { if ( !user.isAccountNonLocked() ) { LOG.debug( "User account is locked" ); throw new LockedException( messages.getMessage( "AbstractUserInDirectoryAuthenticationProvider.locked", "User account is locked" ) ); } if ( !user.isEnabled() ) { LOG.debug( "User account is disabled" ); throw new DisabledException( messages.getMessage( "AbstractUserInDirectoryAuthenticationProvider.disabled", "User is disabled" ) ); } if ( !user.isAccountNonExpired() ) { LOG.debug( "User account is expired" ); throw new AccountExpiredException( messages.getMessage( "AbstractUserInDirectoryAuthenticationProvider.expired", "User account has expired" ) ); } } }
private class Demo implements UserDetailsChecker { public void check(UserDetails user) { if (!user.isAccountNonLocked()) throw new LockedException("User account is locked"); if (!user.isEnabled()) throw new DisabledException("User is disabled")); if (!user.isAccountNonExpired()) throw new AccountExpiredException("User account has expired"); //And here comes you! } }
@Override protected UserDetails retrieveUser(String userId, UsernamePasswordAuthenticationToken token) { try { if (!userService.authenticate(token.getPrincipal().toString(), token.getCredentials().toString())) { throw new BadCredentialsException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_FAIL)); } PortalUserDetails portalUserData = userService.getUserData(userId); if (!portalUserData.isAccountNonLocked()) { throw new LockedException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_LOCKED)); } return portalUserData; } catch (AuthenticationException e) { throw e; } catch (Exception e) { throw new AuthenticationServiceException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_SERVICE_EXCEPTION), e); } }
protected AuthenticationException getException(String errorCodeString) { CasLoginErrorCode errorCode = CasLoginErrorCode.valueOf(errorCodeString); switch (errorCode) { case INVALID_EMIAL: return new NoCredentialsException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_NO_CREDENTIALS_PREFIX + NoCredentialsException.Reason.INVALID_LOGIN), NoCredentialsException.Reason.INVALID_LOGIN); case EMPTY_USERNAME: return new NoCredentialsException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_NO_CREDENTIALS_PREFIX + NoCredentialsException.Reason.NO_LOGIN), NoCredentialsException.Reason.NO_LOGIN); case EMPTY_PASSWORD: return new NoCredentialsException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_NO_CREDENTIALS_PREFIX + NoCredentialsException.Reason.NO_PASSWORD), NoCredentialsException.Reason.NO_PASSWORD); case USER_LOCKED: return new LockedException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_LOCKED)); case BAD_CREDENTIALS: return new BadCredentialsException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_FAIL)); } throw new IllegalStateException("Login error '" + errorCode + "' is not supported by login controller"); }
public void check(UserDetails user) { if (!user.isAccountNonLocked()) { throw new LockedException(messages.getMessage("AccountStatusUserDetailsChecker.locked", "User account is locked"), user); } if (!user.isEnabled()) { throw new DisabledException(messages.getMessage("AccountStatusUserDetailsChecker.disabled", "User is disabled"), user); } if (!user.isAccountNonExpired()) { throw new AccountExpiredException(messages.getMessage("AccountStatusUserDetailsChecker.expired", "User account has expired"), user); } if (!user.isCredentialsNonExpired()) { throw new CredentialsExpiredException(messages.getMessage("AccountStatusUserDetailsChecker.credentialsExpired", "User credentials have expired"), user); } } }