@Test @Ignore public void test_should_validate_update_password_request() { final LoggedInUserUpdatePasswordRequest updatePasswordRequest = LoggedInUserUpdatePasswordRequest.builder() .userName("xyz") .tenantId("default") .type(UserType.CITIZEN) .newPassword("newPassword") .existingPassword("existingPassword") .build(); User user = User.builder().username("xyz").tenantId("default").type(UserType.CITIZEN).build(); when(userRepository.findAll(any(UserSearchCriteria.class))).thenReturn(Collections.singletonList(user)); when(passwordEncoder.matches(anyString(), anyString())).thenReturn(true); userService.updatePasswordForLoggedInUser(updatePasswordRequest); verify(updatePasswordRequest).validate(); }
public void updatePasswordForLoggedInUser(LoggedInUserUpdatePasswordRequest updatePasswordRequest) { updatePasswordRequest.validate(); final User user = getUniqueUser(updatePasswordRequest.getUserName(), updatePasswordRequest.getTenantId(), updatePasswordRequest.getType()); if (user.getType().toString().equals(UserType.CITIZEN.toString()) && isCitizenLoginOtpBased) throw new InvalidUpdatePasswordRequestException(); if (user.getType().toString().equals(UserType.EMPLOYEE.toString()) && isEmployeeLoginOtpBased) throw new InvalidUpdatePasswordRequestException(); validateExistingPassword(user, updatePasswordRequest.getExistingPassword()); user.updatePassword(encryptPwd(updatePasswordRequest.getNewPassword())); userRepository.update(user, user); }
UserService { public void updatePasswordForLoggedInUser(LoggedInUserUpdatePasswordRequest updatePasswordRequest) { updatePasswordRequest.validate(); final User user = getUniqueUser(updatePasswordRequest.getUserName(), updatePasswordRequest.getTenantId(), updatePasswordRequest.getType()); if (user.getType().toString().equals(UserType.CITIZEN.toString()) && isCitizenLoginOtpBased) throw new InvalidUpdatePasswordRequestException(); if (user.getType().toString().equals(UserType.EMPLOYEE.toString()) && isEmployeeLoginOtpBased) throw new InvalidUpdatePasswordRequestException(); validateExistingPassword(user, updatePasswordRequest.getExistingPassword()); user.updatePassword(encryptPwd(updatePasswordRequest.getNewPassword())); userRepository.update(user, user); } }
UserService { public void updatePasswordForLoggedInUser(LoggedInUserUpdatePasswordRequest updatePasswordRequest) { updatePasswordRequest.validate(); final User user = getUniqueUser(updatePasswordRequest.getUserName(), updatePasswordRequest.getTenantId(), updatePasswordRequest.getType()); if (user.getType().toString().equals(UserType.CITIZEN.toString()) && isCitizenLoginOtpBased) throw new InvalidUpdatePasswordRequestException(); if (user.getType().toString().equals(UserType.EMPLOYEE.toString()) && isEmployeeLoginOtpBased) throw new InvalidUpdatePasswordRequestException(); validateExistingPassword(user, updatePasswordRequest.getExistingPassword()); user.updatePassword(encryptPwd(updatePasswordRequest.getNewPassword())); userRepository.update(user, user); } UserService(UserRepository userRepository, OtpRepository otpRepository, FileStoreRepository fileRepository,
                       PasswordEncoder passwordEncoder, TokenStore tokenStore,
                       @Value("${default.password.expiry.in.days}") int defaultPasswordExpiryInDays,
                       @Value("${citizen.login.password.otp.enabled}") boolean isCitizenLoginOtpBased,
                       @Value("${employee.login.password.otp.enabled}") boolean isEmployeeLoginOtpBased); }
UserService { public void updatePasswordForLoggedInUser(LoggedInUserUpdatePasswordRequest updatePasswordRequest) { updatePasswordRequest.validate(); final User user = getUniqueUser(updatePasswordRequest.getUserName(), updatePasswordRequest.getTenantId(), updatePasswordRequest.getType()); if (user.getType().toString().equals(UserType.CITIZEN.toString()) && isCitizenLoginOtpBased) throw new InvalidUpdatePasswordRequestException(); if (user.getType().toString().equals(UserType.EMPLOYEE.toString()) && isEmployeeLoginOtpBased) throw new InvalidUpdatePasswordRequestException(); validateExistingPassword(user, updatePasswordRequest.getExistingPassword()); user.updatePassword(encryptPwd(updatePasswordRequest.getNewPassword())); userRepository.update(user, user); } UserService(UserRepository userRepository, OtpRepository otpRepository, FileStoreRepository fileRepository,
                       PasswordEncoder passwordEncoder, TokenStore tokenStore,
                       @Value("${default.password.expiry.in.days}") int defaultPasswordExpiryInDays,
                       @Value("${citizen.login.password.otp.enabled}") boolean isCitizenLoginOtpBased,
                       @Value("${employee.login.password.otp.enabled}") boolean isEmployeeLoginOtpBased); User getUniqueUser(String userName, String tenantId, UserType userType); User getUserByUuid(String uuid); List<org.egov.user.domain.model.User> searchUsers(UserSearchCriteria searchCriteria,
                                                             boolean isInterServiceCall); User createUser(User user); User createCitizen(User user); Object registerWithLogin(User user); Boolean validateOtp(User user); User updateWithoutOtpValidation(final User user); void removeTokensByUser(User user); User partialUpdate(final User user); void updatePasswordForLoggedInUser(LoggedInUserUpdatePasswordRequest updatePasswordRequest); void updatePasswordForNonLoggedInUser(NonLoggedInUserUpdatePasswordRequest request); void resetFailedLoginAttempts(User user); boolean isAccountUnlockAble(User user); void handleFailedLogin(User user, String ipAddress); }
UserService { public void updatePasswordForLoggedInUser(LoggedInUserUpdatePasswordRequest updatePasswordRequest) { updatePasswordRequest.validate(); final User user = getUniqueUser(updatePasswordRequest.getUserName(), updatePasswordRequest.getTenantId(), updatePasswordRequest.getType()); if (user.getType().toString().equals(UserType.CITIZEN.toString()) && isCitizenLoginOtpBased) throw new InvalidUpdatePasswordRequestException(); if (user.getType().toString().equals(UserType.EMPLOYEE.toString()) && isEmployeeLoginOtpBased) throw new InvalidUpdatePasswordRequestException(); validateExistingPassword(user, updatePasswordRequest.getExistingPassword()); user.updatePassword(encryptPwd(updatePasswordRequest.getNewPassword())); userRepository.update(user, user); } UserService(UserRepository userRepository, OtpRepository otpRepository, FileStoreRepository fileRepository,
                       PasswordEncoder passwordEncoder, TokenStore tokenStore,
                       @Value("${default.password.expiry.in.days}") int defaultPasswordExpiryInDays,
                       @Value("${citizen.login.password.otp.enabled}") boolean isCitizenLoginOtpBased,
                       @Value("${employee.login.password.otp.enabled}") boolean isEmployeeLoginOtpBased); User getUniqueUser(String userName, String tenantId, UserType userType); User getUserByUuid(String uuid); List<org.egov.user.domain.model.User> searchUsers(UserSearchCriteria searchCriteria,
                                                             boolean isInterServiceCall); User createUser(User user); User createCitizen(User user); Object registerWithLogin(User user); Boolean validateOtp(User user); User updateWithoutOtpValidation(final User user); void removeTokensByUser(User user); User partialUpdate(final User user); void updatePasswordForLoggedInUser(LoggedInUserUpdatePasswordRequest updatePasswordRequest); void updatePasswordForNonLoggedInUser(NonLoggedInUserUpdatePasswordRequest request); void resetFailedLoginAttempts(User user); boolean isAccountUnlockAble(User user); void handleFailedLogin(User user, String ipAddress);  }