@Test @Sql(scripts = { "/sql/clearUserRoles.sql", "/sql/clearUsers.sql", "/sql/clearRoles.sql", "/sql/createRoles.sql", "/sql/clearAddresses.sql" }) public void test_should_set_encrypted_password_to_new_user() { final Set<Role> roles = new HashSet<>(); final String roleCode = "EMP"; roles.add(org.egov.user.domain.model.Role.builder().code(roleCode).tenantId("ap.public").build()); final String rawPassword = "rawPassword"; User domainUser = User.builder().roles(roles) .username("Test UserName").password(rawPassword).tenantId("ap.public").build(); User actualUser = userRepository.create(domainUser); assertThat(actualUser != null); assertThat(actualUser.getId().equals(1l)); assertThat(actualUser.getPassword().equals("$2a$10$begnxh5azaFpAv0yDe7sQ./uDzp2H4Xy7SrEmY/9JV2qB/cHFha5m")); }
public User create(User user) { validateAndEnrichRoles(Collections.singletonList(user)); final Long newId = getNextSequence(); user.setId(newId); user.setUuid(UUID.randomUUID().toString()); user.setCreatedDate(new Date()); user.setLastModifiedDate(new Date()); user.setCreatedBy(user.getLoggedInUserId()); user.setLastModifiedBy(user.getLoggedInUserId()); final User savedUser = save(user); if (user.getRoles().size() > 0) { saveUserRoles(user); } final Address savedCorrespondenceAddress = saveAddress(user.getCorrespondenceAddress(), savedUser.getId(), savedUser.getTenantId()); final Address savedPermanentAddress = saveAddress(user.getPermanentAddress(), savedUser.getId(), savedUser.getTenantId()); savedUser.setPermanentAddress(savedPermanentAddress); savedUser.setCorrespondenceAddress(savedCorrespondenceAddress); return savedUser; }
UserRepository { public User create(User user) { validateAndEnrichRoles(Collections.singletonList(user)); final Long newId = getNextSequence(); user.setId(newId); user.setUuid(UUID.randomUUID().toString()); user.setCreatedDate(new Date()); user.setLastModifiedDate(new Date()); user.setCreatedBy(user.getLoggedInUserId()); user.setLastModifiedBy(user.getLoggedInUserId()); final User savedUser = save(user); if (user.getRoles().size() > 0) { saveUserRoles(user); } final Address savedCorrespondenceAddress = saveAddress(user.getCorrespondenceAddress(), savedUser.getId(), savedUser.getTenantId()); final Address savedPermanentAddress = saveAddress(user.getPermanentAddress(), savedUser.getId(), savedUser.getTenantId()); savedUser.setPermanentAddress(savedPermanentAddress); savedUser.setCorrespondenceAddress(savedCorrespondenceAddress); return savedUser; } }
UserRepository { public User create(User user) { validateAndEnrichRoles(Collections.singletonList(user)); final Long newId = getNextSequence(); user.setId(newId); user.setUuid(UUID.randomUUID().toString()); user.setCreatedDate(new Date()); user.setLastModifiedDate(new Date()); user.setCreatedBy(user.getLoggedInUserId()); user.setLastModifiedBy(user.getLoggedInUserId()); final User savedUser = save(user); if (user.getRoles().size() > 0) { saveUserRoles(user); } final Address savedCorrespondenceAddress = saveAddress(user.getCorrespondenceAddress(), savedUser.getId(), savedUser.getTenantId()); final Address savedPermanentAddress = saveAddress(user.getPermanentAddress(), savedUser.getId(), savedUser.getTenantId()); savedUser.setPermanentAddress(savedPermanentAddress); savedUser.setCorrespondenceAddress(savedCorrespondenceAddress); return savedUser; } @Autowired  UserRepository(RoleRepository roleRepository, UserTypeQueryBuilder userTypeQueryBuilder,
                   AddressRepository addressRepository, UserResultSetExtractor userResultSetExtractor,
                   JdbcTemplate jdbcTemplate,
                   NamedParameterJdbcTemplate namedParameterJdbcTemplate); }
UserRepository { public User create(User user) { validateAndEnrichRoles(Collections.singletonList(user)); final Long newId = getNextSequence(); user.setId(newId); user.setUuid(UUID.randomUUID().toString()); user.setCreatedDate(new Date()); user.setLastModifiedDate(new Date()); user.setCreatedBy(user.getLoggedInUserId()); user.setLastModifiedBy(user.getLoggedInUserId()); final User savedUser = save(user); if (user.getRoles().size() > 0) { saveUserRoles(user); } final Address savedCorrespondenceAddress = saveAddress(user.getCorrespondenceAddress(), savedUser.getId(), savedUser.getTenantId()); final Address savedPermanentAddress = saveAddress(user.getPermanentAddress(), savedUser.getId(), savedUser.getTenantId()); savedUser.setPermanentAddress(savedPermanentAddress); savedUser.setCorrespondenceAddress(savedCorrespondenceAddress); return savedUser; } @Autowired  UserRepository(RoleRepository roleRepository, UserTypeQueryBuilder userTypeQueryBuilder,
                   AddressRepository addressRepository, UserResultSetExtractor userResultSetExtractor,
                   JdbcTemplate jdbcTemplate,
                   NamedParameterJdbcTemplate namedParameterJdbcTemplate); List<User> findAll(UserSearchCriteria userSearch); boolean isUserPresent(String userName, String tenantId, UserType userType); User create(User user); void update(final User user, User oldUser); void fetchFailedLoginAttemptsByUser(String uuid); List<FailedLoginAttempt> fetchFailedAttemptsByUserAndTime(String uuid, long attemptStartDate); FailedLoginAttempt insertFailedLoginAttempt(FailedLoginAttempt failedLoginAttempt); void resetFailedLoginAttemptsForUser(String uuid); }
UserRepository { public User create(User user) { validateAndEnrichRoles(Collections.singletonList(user)); final Long newId = getNextSequence(); user.setId(newId); user.setUuid(UUID.randomUUID().toString()); user.setCreatedDate(new Date()); user.setLastModifiedDate(new Date()); user.setCreatedBy(user.getLoggedInUserId()); user.setLastModifiedBy(user.getLoggedInUserId()); final User savedUser = save(user); if (user.getRoles().size() > 0) { saveUserRoles(user); } final Address savedCorrespondenceAddress = saveAddress(user.getCorrespondenceAddress(), savedUser.getId(), savedUser.getTenantId()); final Address savedPermanentAddress = saveAddress(user.getPermanentAddress(), savedUser.getId(), savedUser.getTenantId()); savedUser.setPermanentAddress(savedPermanentAddress); savedUser.setCorrespondenceAddress(savedCorrespondenceAddress); return savedUser; } @Autowired  UserRepository(RoleRepository roleRepository, UserTypeQueryBuilder userTypeQueryBuilder,
                   AddressRepository addressRepository, UserResultSetExtractor userResultSetExtractor,
                   JdbcTemplate jdbcTemplate,
                   NamedParameterJdbcTemplate namedParameterJdbcTemplate); List<User> findAll(UserSearchCriteria userSearch); boolean isUserPresent(String userName, String tenantId, UserType userType); User create(User user); void update(final User user, User oldUser); void fetchFailedLoginAttemptsByUser(String uuid); List<FailedLoginAttempt> fetchFailedAttemptsByUserAndTime(String uuid, long attemptStartDate); FailedLoginAttempt insertFailedLoginAttempt(FailedLoginAttempt failedLoginAttempt); void resetFailedLoginAttemptsForUser(String uuid);  }