@Test(expected = PasswordUniqueValidationException.class) public void isValidShouldNotBeValidWhenNewPasswordIsInThreeElementPasswordHistory() throws PasswordUniqueValidationException { PasswordChangeDTO passwordChangeDto = PasswordChangeDTO.builder() .newPassword(PASSWORD_HISTORY_1) .build(); given(passwordChangeService.getOldPasswords(USER_ID)).willReturn(threeElementPasswordHistory); passwordUniqueRule.validate(passwordChangeDto); }
@Override public void validate(PasswordChangeDTO passwordChangeDTO) throws PasswordUniqueValidationException { UserDetailsAdapter userDetails = null; try { userDetails = authenticationService.getCurrentUserDetails(); } catch (UserNotLoggedInException e) { throw new BackendException(e); } List<String> oldPasswords = passwordChangeService.getOldPasswords(userDetails.getUserId()); for (String password : oldPasswords) { if (bCryptPasswordEncoder.matches(passwordChangeDTO.getNewPassword(), password)) { throw new PasswordUniqueValidationException(); } } }
PasswordUniqueRule implements PasswordValidationRule { @Override public void validate(PasswordChangeDTO passwordChangeDTO) throws PasswordUniqueValidationException { UserDetailsAdapter userDetails = null; try { userDetails = authenticationService.getCurrentUserDetails(); } catch (UserNotLoggedInException e) { throw new BackendException(e); } List<String> oldPasswords = passwordChangeService.getOldPasswords(userDetails.getUserId()); for (String password : oldPasswords) { if (bCryptPasswordEncoder.matches(passwordChangeDTO.getNewPassword(), password)) { throw new PasswordUniqueValidationException(); } } } }
PasswordUniqueRule implements PasswordValidationRule { @Override public void validate(PasswordChangeDTO passwordChangeDTO) throws PasswordUniqueValidationException { UserDetailsAdapter userDetails = null; try { userDetails = authenticationService.getCurrentUserDetails(); } catch (UserNotLoggedInException e) { throw new BackendException(e); } List<String> oldPasswords = passwordChangeService.getOldPasswords(userDetails.getUserId()); for (String password : oldPasswords) { if (bCryptPasswordEncoder.matches(passwordChangeDTO.getNewPassword(), password)) { throw new PasswordUniqueValidationException(); } } } PasswordUniqueRule(PasswordChangeService passwordChangeService,
                            AuthenticationService authenticationService); }
PasswordUniqueRule implements PasswordValidationRule { @Override public void validate(PasswordChangeDTO passwordChangeDTO) throws PasswordUniqueValidationException { UserDetailsAdapter userDetails = null; try { userDetails = authenticationService.getCurrentUserDetails(); } catch (UserNotLoggedInException e) { throw new BackendException(e); } List<String> oldPasswords = passwordChangeService.getOldPasswords(userDetails.getUserId()); for (String password : oldPasswords) { if (bCryptPasswordEncoder.matches(passwordChangeDTO.getNewPassword(), password)) { throw new PasswordUniqueValidationException(); } } } PasswordUniqueRule(PasswordChangeService passwordChangeService,
                            AuthenticationService authenticationService); @Override void validate(PasswordChangeDTO passwordChangeDTO); }
PasswordUniqueRule implements PasswordValidationRule { @Override public void validate(PasswordChangeDTO passwordChangeDTO) throws PasswordUniqueValidationException { UserDetailsAdapter userDetails = null; try { userDetails = authenticationService.getCurrentUserDetails(); } catch (UserNotLoggedInException e) { throw new BackendException(e); } List<String> oldPasswords = passwordChangeService.getOldPasswords(userDetails.getUserId()); for (String password : oldPasswords) { if (bCryptPasswordEncoder.matches(passwordChangeDTO.getNewPassword(), password)) { throw new PasswordUniqueValidationException(); } } } PasswordUniqueRule(PasswordChangeService passwordChangeService,
                            AuthenticationService authenticationService); @Override void validate(PasswordChangeDTO passwordChangeDTO);  }