Package org.codelibs.fess.app.service
Class UserService
java.lang.Object
org.codelibs.fess.app.service.UserService
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
FieldsModifier and TypeFieldDescriptionprotected org.codelibs.fess.mylasta.direction.FessConfigFess configuration for system settingsprotected org.codelibs.fess.opensearch.user.exbhv.UserBhvUser behavior for database operations -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchangePassword(String username, String password) Changes the password for a user identified by username.voiddelete(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> getUserByName(String username) Retrieves a user by their username.List<org.codelibs.fess.opensearch.user.exentity.User> getUserList(UserPager userPager) Retrieves a paginated list of users based on the provided pager criteria.protected booleanTests whether the given throwable (or any of its causes) represents an OpenSearch optimistic-concurrency conflict.protected voidsetupListCondition(org.codelibs.fess.opensearch.user.cbean.UserCB cb, UserPager userPager) Sets up the search conditions for user list queries based on pager criteria.voidstore(org.codelibs.fess.opensearch.user.exentity.User user) Stores (inserts or updates) a user in the system.booleanupdateStoredPasswordHash(String username, String encodedPassword) Updates the stored password hash directly, bypassing AuthenticationManager chain.booleanupdateStoredPasswordHash(String username, String expectedCurrentHash, String newEncodedPassword) Updates the stored password hash with an optional compare-and-set guard.
-
Field Details
-
userBhv
protected org.codelibs.fess.opensearch.user.exbhv.UserBhv userBhvUser behavior for database operations -
fessConfig
protected org.codelibs.fess.mylasta.direction.FessConfig fessConfigFess configuration for system settings
-
-
Constructor Details
-
UserService
public UserService()Default constructor for UserService.
-
-
Method Details
-
getUserList
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
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 userpassword- the new password in plain text- Throws:
FessUserNotFoundException- if the user is not found
-
updateStoredPasswordHash
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. WhenexpectedCurrentHashis 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, ornullto perform an unconditional updatenewEncodedPassword- already-hashed password value to store- Returns:
trueif the update was applied;falseif the user was not found, the guard did not match, or the update failed
-
isVersionConflict
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:
trueiftlooks 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 queryuserPager- the pager containing search criteria
-
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
-