Package org.codelibs.fess.helper
Class UserInfoHelper
java.lang.Object
org.codelibs.fess.helper.UserInfoHelper
Helper class for managing user information and session tracking in Fess search system.
This class handles user identification through cookies, session management, and query tracking.
It provides functionality for generating unique user codes, managing user sessions,
and tracking search result document IDs for analytics and personalization.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe domain for the user identification cookieprotected intThe maximum age of the user identification cookie in seconds (default: 1 month)protected StringThe name of the cookie used for user identificationprotected StringThe path for the user identification cookieprotected BooleanWhether the user identification cookie should be secure (HTTPS only)protected booleanWhether the user identification cookie should be HTTP-onlyprotected intThe maximum size of the result document IDs cacheprotected static final StringThe session attribute key for storing user bean information -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcreateUserCodeFromUserId(String userCode) Creates an encrypted user code from a user ID.voiddeleteUserCodeFromCookie(jakarta.servlet.http.HttpServletRequest request) Deletes the user code cookie from the client browser.protected StringgetId()Generates a new unique identifier for user tracking.String[]getResultDocIds(String queryId) Retrieves the document IDs associated with a specific query ID.Retrieves the user code for the current request.protected StringgetUserCodeFromCookie(jakarta.servlet.http.HttpServletRequest request) Extracts the user code from the user identification cookie.protected StringgetUserCodeFromRequest(jakarta.servlet.http.HttpServletRequest request) Extracts the user code from request parameters.protected StringgetUserCodeFromUserBean(jakarta.servlet.http.HttpServletRequest request) Extracts the user code from the user bean stored in the session.protected booleanDetermines whether the user identification cookie should be marked as secure.voidsetCookieDomain(String cookieDomain) Sets the domain for the user identification cookie.voidsetCookieHttpOnly(boolean httpOnly) Sets whether the user identification cookie should be HTTP-only.voidsetCookieMaxAge(int cookieMaxAge) Sets the maximum age of the user identification cookie in seconds.voidsetCookieName(String cookieName) Sets the name of the user identification cookie.voidsetCookiePath(String cookiePath) Sets the path for the user identification cookie.voidsetCookieSecure(Boolean cookieSecure) Sets whether the user identification cookie should be marked as secure.voidsetResultDocIdsCacheSize(int resultDocIdsCacheSize) Sets the maximum size of the result document IDs cache.voidStores the document IDs associated with a search query for tracking purposes.protected voidupdateCookie(String userCode, int age) Updates the user identification cookie with the specified user code and max age.protected voidupdateUserSessionId(String userCode) Updates the user session with the provided user code.
-
Field Details
-
USER_BEAN
The session attribute key for storing user bean information- See Also:
-
resultDocIdsCacheSize
protected int resultDocIdsCacheSizeThe maximum size of the result document IDs cache -
cookieName
The name of the cookie used for user identification -
cookieDomain
The domain for the user identification cookie -
cookieMaxAge
protected int cookieMaxAgeThe maximum age of the user identification cookie in seconds (default: 1 month) -
cookiePath
The path for the user identification cookie -
cookieSecure
Whether the user identification cookie should be secure (HTTPS only) -
httpOnly
protected boolean httpOnlyWhether the user identification cookie should be HTTP-only
-
-
Constructor Details
-
UserInfoHelper
public UserInfoHelper()Default constructor for UserInfoHelper.
-
-
Method Details
-
getUserCode
Retrieves the user code for the current request. The user code is used to uniquely identify users across sessions and requests. It checks multiple sources in order: request attribute, request parameter, cookie, user bean, or generates a new one.- Returns:
- the user code string, or null if no valid session exists
-
getUserCodeFromUserBean
Extracts the user code from the user bean stored in the session. This method retrieves the authenticated user information and creates an encrypted user code.- Parameters:
request- the HTTP servlet request- Returns:
- the user code from the user bean, or null if not found or invalid
-
createUserCodeFromUserId
Creates an encrypted user code from a user ID. The user ID is encrypted using the primary cipher and validated against the configuration.- Parameters:
userCode- the raw user ID to encrypt- Returns:
- the encrypted and validated user code, or null if invalid
-
deleteUserCodeFromCookie
public void deleteUserCodeFromCookie(jakarta.servlet.http.HttpServletRequest request) Deletes the user code cookie from the client browser. This method removes the user identification cookie by setting it to an empty value with zero max age.- Parameters:
request- the HTTP servlet request
-
getUserCodeFromRequest
Extracts the user code from request parameters. This method looks for the user code in the request parameters and validates it.- Parameters:
request- the HTTP servlet request- Returns:
- the user code from request parameters, or null if not found or invalid
-
getId
Generates a new unique identifier for user tracking. Creates a UUID and removes hyphens to create a clean identifier string.- Returns:
- a new unique identifier string
-
updateUserSessionId
Updates the user session with the provided user code. This method registers the user info with the search log helper and updates the cookie.- Parameters:
userCode- the user code to associate with the session
-
updateCookie
Updates the user identification cookie with the specified user code and max age. Configures the cookie with security settings including domain, path, secure flag, and HTTP-only flag.- Parameters:
userCode- the user code to store in the cookieage- the maximum age of the cookie in seconds
-
isSecureCookie
protected boolean isSecureCookie()Determines whether the user identification cookie should be marked as secure. Checks the configured secure setting or examines request headers to detect HTTPS.- Returns:
- true if the cookie should be secure, false otherwise
-
getUserCodeFromCookie
Extracts the user code from the user identification cookie. Searches through all request cookies to find the user identification cookie and validates its value.- Parameters:
request- the HTTP servlet request- Returns:
- the user code from the cookie, or null if not found or invalid
-
storeQueryId
Stores the document IDs associated with a search query for tracking purposes. This method caches the document IDs returned for a specific query to enable click tracking and analytics.- Parameters:
queryId- the unique identifier for the search querydocumentItems- the list of document maps containing search results
-
getResultDocIds
Retrieves the document IDs associated with a specific query ID. Used for tracking which documents were displayed for a particular search query.- Parameters:
queryId- the unique identifier for the search query- Returns:
- an array of document IDs, or an empty array if not found
-
setResultDocIdsCacheSize
public void setResultDocIdsCacheSize(int resultDocIdsCacheSize) Sets the maximum size of the result document IDs cache.- Parameters:
resultDocIdsCacheSize- the maximum number of entries in the cache
-
setCookieName
Sets the name of the user identification cookie.- Parameters:
cookieName- the name to use for the user identification cookie
-
setCookieDomain
Sets the domain for the user identification cookie.- Parameters:
cookieDomain- the domain to use for the user identification cookie
-
setCookieMaxAge
public void setCookieMaxAge(int cookieMaxAge) Sets the maximum age of the user identification cookie in seconds.- Parameters:
cookieMaxAge- the maximum age in seconds
-
setCookiePath
Sets the path for the user identification cookie.- Parameters:
cookiePath- the path to use for the user identification cookie
-
setCookieSecure
Sets whether the user identification cookie should be marked as secure.- Parameters:
cookieSecure- true if the cookie should be secure (HTTPS only), false otherwise, or null for auto-detection
-
setCookieHttpOnly
public void setCookieHttpOnly(boolean httpOnly) Sets whether the user identification cookie should be HTTP-only.- Parameters:
httpOnly- true if the cookie should be HTTP-only (not accessible via JavaScript), false otherwise
-