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 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 user
      password - the password
      passwordAttempts - the password attempts
      passwordExpiry - the password expiry
    • deleteById

      @Modifying @Query("delete from User u where u.id = :userId") void deleteById(@Param("userId") UUID userId)
      Delete the user.
      Specified by:
      deleteById in interface org.springframework.data.repository.CrudRepository<User,UUID>
      Parameters:
      userId - the ID for the user
    • existsByUserDirectoryIdAndUsernameIgnoreCase

      boolean existsByUserDirectoryIdAndUsernameIgnoreCase(UUID userDirectoryId, String username)
      Check whether the user exists.
      Parameters:
      userDirectoryId - the ID for the user directory
      username - the username
      Returns:
      true if the user exists or false otherwise
    • findByUserDirectoryId

      List<User> findByUserDirectoryId(UUID userDirectoryId)
      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 directory
      pageable - the pagination information
      Returns:
      the users for the user directory
    • findByUserDirectoryIdAndUsernameIgnoreCase

      Optional<User> findByUserDirectoryIdAndUsernameIgnoreCase(UUID userDirectoryId, String username)
      Retrieve the user with the specified username for the user directory.
      Parameters:
      userDirectoryId - the ID for the user directory
      username - 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 directory
      filter - the filter to apply to the users
      pageable - 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 directory
      username - 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 directory
      username - 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 user
      after - 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 user
      groupId - 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 user
      password - the password
      passwordExpiry - 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 user
      password - the password