@Test(expected = IllegalArgumentException.class) public void isValidShouldNotBeValidWhenPasswordChangeDTOsPasswordFieldIsNull() throws PasswordOldMatchValidationException { PasswordChangeDTO passwordChangeDTO = PasswordChangeDTO.builder().newPassword(NEW_PASSWORD) .newPasswordConfirm(NEW_PASSWORD_CONFIRM).oldPassword(null).build(); passwordOldPasswordMatchesRule.validate(passwordChangeDTO); }
@Override public void validate(PasswordChangeDTO passwordChangeDTO) throws PasswordOldMatchValidationException { Assert.notNull(passwordChangeDTO); Assert.notNull(passwordChangeDTO.getOldPassword()); UserDetails userDetails; try { userDetails = authenticationService.getCurrentUserDetails(); } catch (UserNotLoggedInException e) { log.error("User is not logged in: ", e); throw new PasswordOldMatchValidationException(); } if (!(bCryptPasswordEncoder .matches(passwordChangeDTO.getOldPassword(), userDetails.getPassword()))) { throw new PasswordOldMatchValidationException(); } }
PasswordOldPasswordMatchesRule implements PasswordValidationRule { @Override public void validate(PasswordChangeDTO passwordChangeDTO) throws PasswordOldMatchValidationException { Assert.notNull(passwordChangeDTO); Assert.notNull(passwordChangeDTO.getOldPassword()); UserDetails userDetails; try { userDetails = authenticationService.getCurrentUserDetails(); } catch (UserNotLoggedInException e) { log.error("User is not logged in: ", e); throw new PasswordOldMatchValidationException(); } if (!(bCryptPasswordEncoder .matches(passwordChangeDTO.getOldPassword(), userDetails.getPassword()))) { throw new PasswordOldMatchValidationException(); } } }
PasswordOldPasswordMatchesRule implements PasswordValidationRule { @Override public void validate(PasswordChangeDTO passwordChangeDTO) throws PasswordOldMatchValidationException { Assert.notNull(passwordChangeDTO); Assert.notNull(passwordChangeDTO.getOldPassword()); UserDetails userDetails; try { userDetails = authenticationService.getCurrentUserDetails(); } catch (UserNotLoggedInException e) { log.error("User is not logged in: ", e); throw new PasswordOldMatchValidationException(); } if (!(bCryptPasswordEncoder .matches(passwordChangeDTO.getOldPassword(), userDetails.getPassword()))) { throw new PasswordOldMatchValidationException(); } } PasswordOldPasswordMatchesRule(AuthenticationService authenticationService); }
PasswordOldPasswordMatchesRule implements PasswordValidationRule { @Override public void validate(PasswordChangeDTO passwordChangeDTO) throws PasswordOldMatchValidationException { Assert.notNull(passwordChangeDTO); Assert.notNull(passwordChangeDTO.getOldPassword()); UserDetails userDetails; try { userDetails = authenticationService.getCurrentUserDetails(); } catch (UserNotLoggedInException e) { log.error("User is not logged in: ", e); throw new PasswordOldMatchValidationException(); } if (!(bCryptPasswordEncoder .matches(passwordChangeDTO.getOldPassword(), userDetails.getPassword()))) { throw new PasswordOldMatchValidationException(); } } PasswordOldPasswordMatchesRule(AuthenticationService authenticationService); @Override void validate(PasswordChangeDTO passwordChangeDTO); }
PasswordOldPasswordMatchesRule implements PasswordValidationRule { @Override public void validate(PasswordChangeDTO passwordChangeDTO) throws PasswordOldMatchValidationException { Assert.notNull(passwordChangeDTO); Assert.notNull(passwordChangeDTO.getOldPassword()); UserDetails userDetails; try { userDetails = authenticationService.getCurrentUserDetails(); } catch (UserNotLoggedInException e) { log.error("User is not logged in: ", e); throw new PasswordOldMatchValidationException(); } if (!(bCryptPasswordEncoder .matches(passwordChangeDTO.getOldPassword(), userDetails.getPassword()))) { throw new PasswordOldMatchValidationException(); } } PasswordOldPasswordMatchesRule(AuthenticationService authenticationService); @Override void validate(PasswordChangeDTO passwordChangeDTO);  }