@Test(expected = UserProfileUpdateDeniedException.class) public void test_should_throw_exception_when_logged_in_user_is_different_from_user_being_updated() { final User user = User.builder().id(12L).username("xyz").uuid("zyz").type(UserType.CITIZEN).loggedInUserId(11L) .tenantId ("default").build(); when(userRepository.findAll(any(UserSearchCriteria.class))).thenReturn(Collections.singletonList(user)); userService.partialUpdate(user); }
public User partialUpdate(final User user) { final User existingUser = getUserByUuid(user.getUuid()); validateProfileUpdateIsDoneByTheSameLoggedInUser(user); user.nullifySensitiveFields(); userRepository.update(user, existingUser); User updatedUser = getUserByUuid(user.getUuid()); setFileStoreUrlsByFileStoreIds(Collections.singletonList(updatedUser)); return updatedUser; }
UserService { public User partialUpdate(final User user) { final User existingUser = getUserByUuid(user.getUuid()); validateProfileUpdateIsDoneByTheSameLoggedInUser(user); user.nullifySensitiveFields(); userRepository.update(user, existingUser); User updatedUser = getUserByUuid(user.getUuid()); setFileStoreUrlsByFileStoreIds(Collections.singletonList(updatedUser)); return updatedUser; } }
UserService { public User partialUpdate(final User user) { final User existingUser = getUserByUuid(user.getUuid()); validateProfileUpdateIsDoneByTheSameLoggedInUser(user); user.nullifySensitiveFields(); userRepository.update(user, existingUser); User updatedUser = getUserByUuid(user.getUuid()); setFileStoreUrlsByFileStoreIds(Collections.singletonList(updatedUser)); return updatedUser; } 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 User partialUpdate(final User user) { final User existingUser = getUserByUuid(user.getUuid()); validateProfileUpdateIsDoneByTheSameLoggedInUser(user); user.nullifySensitiveFields(); userRepository.update(user, existingUser); User updatedUser = getUserByUuid(user.getUuid()); setFileStoreUrlsByFileStoreIds(Collections.singletonList(updatedUser)); return updatedUser; } 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 User partialUpdate(final User user) { final User existingUser = getUserByUuid(user.getUuid()); validateProfileUpdateIsDoneByTheSameLoggedInUser(user); user.nullifySensitiveFields(); userRepository.update(user, existingUser); User updatedUser = getUserByUuid(user.getUuid()); setFileStoreUrlsByFileStoreIds(Collections.singletonList(updatedUser)); return updatedUser; } 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);  }