Package africa.absa.inception.security
Interface UserRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<User,,UUID> org.springframework.data.jpa.repository.JpaRepository<User,,UUID> org.springframework.data.repository.PagingAndSortingRepository<User,,UUID> org.springframework.data.repository.query.QueryByExampleExecutor<User>,org.springframework.data.repository.Repository<User,UUID>
public interface UserRepository
extends org.springframework.data.jpa.repository.JpaRepository<User,UUID>, org.springframework.data.repository.query.QueryByExampleExecutor<User>
The UserRepository interface declares the repository for the User domain type.
- Author:
- Marcus Portmann
-
Method Summary
Modifier and TypeMethodDescriptionvoidchangePassword(UUID userId, String password, int passwordAttempts, Optional<LocalDateTime> passwordExpiry) Change the password for the user.voiddeleteById(UUID userId) Delete the user.booleanexistsByUserDirectoryIdAndUsernameIgnoreCase(UUID userDirectoryId, String username) Check whether the user exists.findByUserDirectoryId(UUID userDirectoryId) Retrieve the users for the user directory.org.springframework.data.domain.Page<User>findByUserDirectoryId(UUID userDirectoryId, org.springframework.data.domain.Pageable pageable) Retrieve the users for the user directory.findByUserDirectoryIdAndUsernameIgnoreCase(UUID userDirectoryId, String username) Retrieve the user with the specified username for the user directory.org.springframework.data.domain.Page<User>findFiltered(UUID userDirectoryId, String filter, org.springframework.data.domain.Pageable pageable) Retrieve the filtered users for the user directory.getFunctionCodesByUserId(UUID userId) Retrieve the function codes for the user.getGroupNamesByUserId(UUID userId) Retrieve the group names for the usergetGroupsByUserId(UUID userId) Retrieve the groups for the user.getIdByUserDirectoryIdAndUsernameIgnoreCase(UUID userDirectoryId, String username) Retrieve the ID for the user with the specified username for the user directory.getNameByUserDirectoryIdAndUsernameIgnoreCase(UUID userDirectoryId, String username) Retrieve the name for the user with the specified username for the user directory.getPasswordHistory(UUID userId, LocalDateTime after) Retrieve the password history for the user.getRoleCodesByUserId(UUID userId) Retrieve the role codes for the user.getUserDirectoryIdByUsernameIgnoreCase(String username) Retrieve the ID for the user directory for the user with the specified username.voidincrementPasswordAttempts(UUID userId) Increment the password attempts for the user.booleanisUserInGroup(UUID userId, UUID groupId) Check whether the user is a member of the group.voidresetPassword(UUID userId, String password, LocalDateTime passwordExpiry) Reset the password for the user.voidresetPasswordHistory(UUID userId) Reset the password history for the user.voidsavePasswordInPasswordHistory(UUID userId, String password) Save the password in the password history for the user.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, findAll, findAll, findAllById, flush, getById, getOne, saveAll, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findOne
-
Method Details
-
changePassword
@Modifying @Query("update User u set u.password = :password, u.passwordAttempts = :passwordAttempts, u.passwordExpiry = :passwordExpiry where u.id = :userId") void changePassword(@Param("userId") UUID userId, @Param("password") String password, @Param("passwordAttempts") int passwordAttempts, @Param("passwordExpiry") Optional<LocalDateTime> passwordExpiry) Change the password for the user.- Parameters:
userId- the ID for the userpassword- the passwordpasswordAttempts- the password attemptspasswordExpiry- the password expiry
-
deleteById
@Modifying @Query("delete from User u where u.id = :userId") void deleteById(@Param("userId") UUID userId) Delete the user. -
existsByUserDirectoryIdAndUsernameIgnoreCase
Check whether the user exists.- Parameters:
userDirectoryId- the ID for the user directoryusername- the username- Returns:
- true if the user exists or false otherwise
-
findByUserDirectoryId
Retrieve the users for the user directory.- Parameters:
userDirectoryId- the ID for the user directory- Returns:
- the users for the user directory
-
findByUserDirectoryId
org.springframework.data.domain.Page<User> findByUserDirectoryId(UUID userDirectoryId, org.springframework.data.domain.Pageable pageable) Retrieve the users for the user directory.- Parameters:
userDirectoryId- the ID for the user directorypageable- the pagination information- Returns:
- the users for the user directory
-
findByUserDirectoryIdAndUsernameIgnoreCase
Retrieve the user with the specified username for the user directory.- Parameters:
userDirectoryId- the ID for the user directoryusername- the username- Returns:
- an Optional containing the user or an empty Optional if the user could not be found
-
findFiltered
@Query("select u from User u where ((lower(u.username) like lower(:filter)) or (lower(u.name) like lower(:filter))) and u.userDirectoryId = :userDirectoryId") org.springframework.data.domain.Page<User> findFiltered(@Param("userDirectoryId") UUID userDirectoryId, @Param("filter") String filter, org.springframework.data.domain.Pageable pageable) Retrieve the filtered users for the user directory.- Parameters:
userDirectoryId- the ID for the user directoryfilter- the filter to apply to the userspageable- the pagination information- Returns:
- the filtered users for the user directory
-
getFunctionCodesByUserId
@Query("select f.code from User u join u.groups as g join g.roles as r join r.functions as f where u.id = :userId") List<String> getFunctionCodesByUserId(@Param("userId") UUID userId) Retrieve the function codes for the user.- Parameters:
userId- the ID for the user- Returns:
- the function codes for the user
-
getGroupNamesByUserId
@Query("select g.name from User u join u.groups as g where u.id = :userId") List<String> getGroupNamesByUserId(@Param("userId") UUID userId) Retrieve the group names for the user- Parameters:
userId- the ID for the user- Returns:
- the group names for the user
-
getGroupsByUserId
@Query("select g from User u join u.groups as g where u.id = :userId") List<Group> getGroupsByUserId(@Param("userId") UUID userId) Retrieve the groups for the user.- Parameters:
userId- the ID for the user- Returns:
- the groups for the user
-
getIdByUserDirectoryIdAndUsernameIgnoreCase
@Query("select u.id from User u where u.userDirectoryId = :userDirectoryId and lower(u.username) like lower(:username)") Optional<UUID> getIdByUserDirectoryIdAndUsernameIgnoreCase(@Param("userDirectoryId") UUID userDirectoryId, @Param("username") String username) Retrieve the ID for the user with the specified username for the user directory.- Parameters:
userDirectoryId- the ID for the user directoryusername- the username- Returns:
- an Optional containing the ID for the user with the specified username for the user directory or an empty Optional if the user could not be found
-
getNameByUserDirectoryIdAndUsernameIgnoreCase
@Query("select u.name from User u where ((lower(u.username) = lower(:username)) and u.userDirectoryId = :userDirectoryId)") Optional<String> getNameByUserDirectoryIdAndUsernameIgnoreCase(UUID userDirectoryId, String username) Retrieve the name for the user with the specified username for the user directory.- Parameters:
userDirectoryId- the ID for the user directoryusername- the username- Returns:
- an Optional containing the name for the user with the specified username for the user directory or an empty Optional if the user could not be found
-
getPasswordHistory
@Query(value="select password from security.users_password_history where user_id = :userId and changed > :after", nativeQuery=true) List<String> getPasswordHistory(@Param("userId") UUID userId, @Param("after") LocalDateTime after) Retrieve the password history for the user.- Parameters:
userId- the ID for the userafter- the date and time after which password history entries will be retrieved- Returns:
- the password history for the user
-
getRoleCodesByUserId
@Query("select r.code from User u join u.groups as g join g.roles as r where u.id = :userId") List<String> getRoleCodesByUserId(@Param("userId") UUID userId) Retrieve the role codes for the user.- Parameters:
userId- the ID for the user- Returns:
- the role codes for the user
-
getUserDirectoryIdByUsernameIgnoreCase
@Query("select u.userDirectoryId from User u where lower(u.username) = lower(:username)") Optional<UUID> getUserDirectoryIdByUsernameIgnoreCase(@Param("username") String username) Retrieve the ID for the user directory for the user with the specified username.- Parameters:
username- the username- Returns:
- an Optional containing the ID for the user directory for the user with the specified username or an empty Optional if the user could not be found
-
incrementPasswordAttempts
@Modifying @Query("update User u set u.passwordAttempts = u.passwordAttempts + 1 where u.id = :userId") void incrementPasswordAttempts(@Param("userId") UUID userId) Increment the password attempts for the user.- Parameters:
userId- the ID for the user
-
isUserInGroup
@Query("select case when (count(u.id) > 0) then true else false end from User u join u.groups as g where u.id = :userId and g.id = :groupId") boolean isUserInGroup(@Param("userId") UUID userId, @Param("groupId") UUID groupId) Check whether the user is a member of the group.- Parameters:
userId- the ID for the usergroupId- the ID for the group- Returns:
- true if the user is a member of the group or false otherwise
-
resetPassword
@Modifying @Query("update User u set u.password = :password, u.passwordAttempts = 0, u.passwordExpiry = :passwordExpiry where u.id = :userId") void resetPassword(@Param("userId") UUID userId, @Param("password") String password, @Param("passwordExpiry") LocalDateTime passwordExpiry) Reset the password for the user.- Parameters:
userId- the ID for the userpassword- the passwordpasswordExpiry- the password expiry
-
resetPasswordHistory
@Modifying @Query(value="delete from security.users_password_history where user_id = :userId", nativeQuery=true) void resetPasswordHistory(@Param("userId") UUID userId) Reset the password history for the user.- Parameters:
userId- the ID for the user
-
savePasswordInPasswordHistory
@Modifying @Query(value="insert into security.users_password_history(user_id, changed, password) values (:userId, current_timestamp, :password)", nativeQuery=true) void savePasswordInPasswordHistory(@Param("userId") UUID userId, @Param("password") String password) Save the password in the password history for the user.- Parameters:
userId- the ID for the userpassword- the password
-