Class UserService

java.lang.Object
org.codelibs.fess.app.service.UserService

public class UserService extends Object
Service class for managing user operations in the Fess search system. This service provides CRUD operations for user management, including user authentication, password management, and user listing with pagination support.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.codelibs.fess.mylasta.direction.FessConfig
    Fess configuration for system settings
    protected org.codelibs.fess.opensearch.user.exbhv.UserBhv
    User behavior for database operations
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for UserService.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    changePassword(String username, String password)
    Changes the password for a user identified by username.
    void
    delete(org.codelibs.fess.opensearch.user.exentity.User user)
    Deletes a user from the system.
    List<org.codelibs.fess.opensearch.user.exentity.User>
    Retrieves a list of all available users in the system.
    org.dbflute.optional.OptionalEntity<org.codelibs.fess.opensearch.user.exentity.User>
    Retrieves a user by their unique identifier.
    org.dbflute.optional.OptionalEntity<org.codelibs.fess.opensearch.user.exentity.User>
    Retrieves a user by their username.
    List<org.codelibs.fess.opensearch.user.exentity.User>
    Retrieves a paginated list of users based on the provided pager criteria.
    protected boolean
    Tests whether the given throwable (or any of its causes) represents an OpenSearch optimistic-concurrency conflict.
    protected void
    setupListCondition(org.codelibs.fess.opensearch.user.cbean.UserCB cb, UserPager userPager)
    Sets up the search conditions for user list queries based on pager criteria.
    void
    store(org.codelibs.fess.opensearch.user.exentity.User user)
    Stores (inserts or updates) a user in the system.
    boolean
    updateStoredPasswordHash(String username, String encodedPassword)
    Updates the stored password hash directly, bypassing AuthenticationManager chain.
    boolean
    updateStoredPasswordHash(String username, String expectedCurrentHash, String newEncodedPassword)
    Updates the stored password hash with an optional compare-and-set guard.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • userBhv

      protected org.codelibs.fess.opensearch.user.exbhv.UserBhv userBhv
      User behavior for database operations
    • fessConfig

      protected org.codelibs.fess.mylasta.direction.FessConfig fessConfig
      Fess configuration for system settings
  • Constructor Details

    • UserService

      public UserService()
      Default constructor for UserService.
  • Method Details

    • getUserList

      public List<org.codelibs.fess.opensearch.user.exentity.User> getUserList(UserPager userPager)
      Retrieves a paginated list of users based on the provided pager criteria. Updates the pager with pagination information including total count and page navigation.
      Parameters:
      userPager - the pager containing search criteria and pagination settings
      Returns:
      a list of users matching the criteria
    • getUser

      public org.dbflute.optional.OptionalEntity<org.codelibs.fess.opensearch.user.exentity.User> getUser(String id)
      Retrieves a user by their unique identifier. Loads the user through the authentication manager for complete user data.
      Parameters:
      id - the unique identifier of the user
      Returns:
      an OptionalEntity containing the user if found
    • getUserByName

      public org.dbflute.optional.OptionalEntity<org.codelibs.fess.opensearch.user.exentity.User> getUserByName(String username)
      Retrieves a user by their username.
      Parameters:
      username - the username to search for
      Returns:
      an OptionalEntity containing the user if found
    • store

      public void store(org.codelibs.fess.opensearch.user.exentity.User user)
      Stores (inserts or updates) a user in the system. Handles user authentication setup and database persistence. If the surname is blank, it will be set to the user's name.
      Parameters:
      user - the user entity to store
    • changePassword

      public void changePassword(String username, String password)
      Changes the password for a user identified by username. Updates both the authentication manager and the database with the new encrypted password.
      Parameters:
      username - the username of the user
      password - the new password in plain text
      Throws:
      FessUserNotFoundException - if the user is not found
    • updateStoredPasswordHash

      public boolean updateStoredPasswordHash(String username, String encodedPassword)
      Updates the stored password hash directly, bypassing AuthenticationManager chain. Used by lazy re-hashing on successful login when the current stored hash is in a legacy format. The input value MUST already be an encoded hash (e.g., "{bcrypt}$2a$10$...") - this method does NOT hash it again. Does NOT propagate to LDAP/SSO backends because we do not have the plaintext (and LDAP manages its own credential).

      This overload performs an unconditional update. Prefer updateStoredPasswordHash(String, String, String) when a race with concurrent password changes must be avoided.

      Parameters:
      username - target user (must exist)
      encodedPassword - already-hashed password value
      Returns:
      true if updated; false if user not found or update failed
    • updateStoredPasswordHash

      public boolean updateStoredPasswordHash(String username, String expectedCurrentHash, String newEncodedPassword)
      Updates the stored password hash with an optional compare-and-set guard. When expectedCurrentHash is non-null, the update is only applied if the latest stored value equals that expected hash, mitigating a race where another code path (e.g. explicit password change) writes a new hash while this lazy re-hash is computing the new encoded value.
      Parameters:
      username - target user (must exist)
      expectedCurrentHash - the hash value observed at match time, or null to perform an unconditional update
      newEncodedPassword - already-hashed password value to store
      Returns:
      true if the update was applied; false if the user was not found, the guard did not match, or the update failed
    • isVersionConflict

      protected boolean isVersionConflict(Throwable t)
      Tests whether the given throwable (or any of its causes) represents an OpenSearch optimistic-concurrency conflict. Walks the cause chain and inspects class name / message so we do not have to depend on a specific OpenSearch exception type from the DBFlute layer above.
      Parameters:
      t - the throwable to inspect
      Returns:
      true if t looks like a version-conflict
    • delete

      public void delete(org.codelibs.fess.opensearch.user.exentity.User user)
      Deletes a user from the system. Removes the user from both the authentication manager and the database.
      Parameters:
      user - the user entity to delete
    • setupListCondition

      protected void setupListCondition(org.codelibs.fess.opensearch.user.cbean.UserCB cb, UserPager userPager)
      Sets up the search conditions for user list queries based on pager criteria. Configures the condition bean with search filters and ordering.
      Parameters:
      cb - the condition bean for the user query
      userPager - the pager containing search criteria
    • getAvailableUserList

      public List<org.codelibs.fess.opensearch.user.exentity.User> getAvailableUserList()
      Retrieves a list of all available users in the system. Returns up to the maximum configured number of users.
      Returns:
      a list of all available users