@Test public void test_should_persist_changes_on_updating_password_for_non_logged_in_user() { final NonLoggedInUserUpdatePasswordRequest request = NonLoggedInUserUpdatePasswordRequest.builder() .userName("mobileNumber").tenantId("tenant").type(UserType.CITIZEN).otpReference("otpReference") .newPassword ("newPassword") .build(); final OtpValidationRequest expectedRequest = OtpValidationRequest.builder().otpReference("otpReference") .mobileNumber("mobileNumber").tenantId("tenant").build(); when(otpRepository.isOtpValidationComplete(expectedRequest)).thenReturn(true); final User domainUser =User.builder().type(UserType.SYSTEM).build(); when(userRepository.findAll(any(UserSearchCriteria.class))).thenReturn(Collections.singletonList(domainUser)); userService.updatePasswordForNonLoggedInUser(request); verify(userRepository).update(domainUser, domainUser); }
public void updatePasswordForNonLoggedInUser(NonLoggedInUserUpdatePasswordRequest request) { request.validate(); final User user = getUniqueUser(request.getUserName(), request.getTenantId(), request.getType()); if (user.getType().toString().equals(UserType.CITIZEN.toString()) && isCitizenLoginOtpBased) { log.info("CITIZEN forgot password flow is disabled"); throw new InvalidUpdatePasswordRequestException(); } if (user.getType().toString().equals(UserType.EMPLOYEE.toString()) && isEmployeeLoginOtpBased) { log.info("EMPLOYEE forgot password flow is disabled"); throw new InvalidUpdatePasswordRequestException(); } user.setOtpReference(request.getOtpReference()); validateOtp(user); user.updatePassword(encryptPwd(request.getNewPassword())); userRepository.update(user, user); }
UserService { public void updatePasswordForNonLoggedInUser(NonLoggedInUserUpdatePasswordRequest request) { request.validate(); final User user = getUniqueUser(request.getUserName(), request.getTenantId(), request.getType()); if (user.getType().toString().equals(UserType.CITIZEN.toString()) && isCitizenLoginOtpBased) { log.info("CITIZEN forgot password flow is disabled"); throw new InvalidUpdatePasswordRequestException(); } if (user.getType().toString().equals(UserType.EMPLOYEE.toString()) && isEmployeeLoginOtpBased) { log.info("EMPLOYEE forgot password flow is disabled"); throw new InvalidUpdatePasswordRequestException(); } user.setOtpReference(request.getOtpReference()); validateOtp(user); user.updatePassword(encryptPwd(request.getNewPassword())); userRepository.update(user, user); } }
UserService { public void updatePasswordForNonLoggedInUser(NonLoggedInUserUpdatePasswordRequest request) { request.validate(); final User user = getUniqueUser(request.getUserName(), request.getTenantId(), request.getType()); if (user.getType().toString().equals(UserType.CITIZEN.toString()) && isCitizenLoginOtpBased) { log.info("CITIZEN forgot password flow is disabled"); throw new InvalidUpdatePasswordRequestException(); } if (user.getType().toString().equals(UserType.EMPLOYEE.toString()) && isEmployeeLoginOtpBased) { log.info("EMPLOYEE forgot password flow is disabled"); throw new InvalidUpdatePasswordRequestException(); } user.setOtpReference(request.getOtpReference()); validateOtp(user); user.updatePassword(encryptPwd(request.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 updatePasswordForNonLoggedInUser(NonLoggedInUserUpdatePasswordRequest request) { request.validate(); final User user = getUniqueUser(request.getUserName(), request.getTenantId(), request.getType()); if (user.getType().toString().equals(UserType.CITIZEN.toString()) && isCitizenLoginOtpBased) { log.info("CITIZEN forgot password flow is disabled"); throw new InvalidUpdatePasswordRequestException(); } if (user.getType().toString().equals(UserType.EMPLOYEE.toString()) && isEmployeeLoginOtpBased) { log.info("EMPLOYEE forgot password flow is disabled"); throw new InvalidUpdatePasswordRequestException(); } user.setOtpReference(request.getOtpReference()); validateOtp(user); user.updatePassword(encryptPwd(request.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 updatePasswordForNonLoggedInUser(NonLoggedInUserUpdatePasswordRequest request) { request.validate(); final User user = getUniqueUser(request.getUserName(), request.getTenantId(), request.getType()); if (user.getType().toString().equals(UserType.CITIZEN.toString()) && isCitizenLoginOtpBased) { log.info("CITIZEN forgot password flow is disabled"); throw new InvalidUpdatePasswordRequestException(); } if (user.getType().toString().equals(UserType.EMPLOYEE.toString()) && isEmployeeLoginOtpBased) { log.info("EMPLOYEE forgot password flow is disabled"); throw new InvalidUpdatePasswordRequestException(); } user.setOtpReference(request.getOtpReference()); validateOtp(user); user.updatePassword(encryptPwd(request.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);  }