Class UserInfoHelper

java.lang.Object
org.codelibs.fess.helper.UserInfoHelper

public class UserInfoHelper extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    protected String
    The domain for the user identification cookie
    protected int
    The maximum age of the user identification cookie in seconds (default: 1 month)
    protected String
    The name of the cookie used for user identification
    protected String
    The path for the user identification cookie
    protected Boolean
    Whether the user identification cookie should be secure (HTTPS only)
    protected boolean
    Whether the user identification cookie should be HTTP-only
    protected int
    The maximum size of the result document IDs cache
    protected static final String
    The session attribute key for storing user bean information
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for UserInfoHelper.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    Creates an encrypted user code from a user ID.
    void
    deleteUserCodeFromCookie(jakarta.servlet.http.HttpServletRequest request)
    Deletes the user code cookie from the client browser.
    protected String
    Generates a new unique identifier for user tracking.
    Retrieves the document IDs associated with a specific query ID.
    Retrieves the user code for the current request.
    protected String
    getUserCodeFromCookie(jakarta.servlet.http.HttpServletRequest request)
    Extracts the user code from the user identification cookie.
    protected String
    getUserCodeFromRequest(jakarta.servlet.http.HttpServletRequest request)
    Extracts the user code from request parameters.
    protected String
    getUserCodeFromUserBean(jakarta.servlet.http.HttpServletRequest request)
    Extracts the user code from the user bean stored in the session.
    protected boolean
    Determines whether the user identification cookie should be marked as secure.
    void
    setCookieDomain(String cookieDomain)
    Sets the domain for the user identification cookie.
    void
    setCookieHttpOnly(boolean httpOnly)
    Sets whether the user identification cookie should be HTTP-only.
    void
    setCookieMaxAge(int cookieMaxAge)
    Sets the maximum age of the user identification cookie in seconds.
    void
    setCookieName(String cookieName)
    Sets the name of the user identification cookie.
    void
    setCookiePath(String cookiePath)
    Sets the path for the user identification cookie.
    void
    setCookieSecure(Boolean cookieSecure)
    Sets whether the user identification cookie should be marked as secure.
    void
    setResultDocIdsCacheSize(int resultDocIdsCacheSize)
    Sets the maximum size of the result document IDs cache.
    void
    storeQueryId(String queryId, List<Map<String,Object>> documentItems)
    Stores the document IDs associated with a search query for tracking purposes.
    protected void
    updateCookie(String userCode, int age)
    Updates the user identification cookie with the specified user code and max age.
    protected void
    Updates the user session with the provided user code.

    Methods inherited from class java.lang.Object

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

    • USER_BEAN

      protected static final String USER_BEAN
      The session attribute key for storing user bean information
      See Also:
    • resultDocIdsCacheSize

      protected int resultDocIdsCacheSize
      The maximum size of the result document IDs cache
    • cookieName

      protected String cookieName
      The name of the cookie used for user identification
    • cookieDomain

      protected String cookieDomain
      The domain for the user identification cookie
    • cookieMaxAge

      protected int cookieMaxAge
      The maximum age of the user identification cookie in seconds (default: 1 month)
    • cookiePath

      protected String cookiePath
      The path for the user identification cookie
    • cookieSecure

      protected Boolean cookieSecure
      Whether the user identification cookie should be secure (HTTPS only)
    • httpOnly

      protected boolean httpOnly
      Whether the user identification cookie should be HTTP-only
  • Constructor Details

    • UserInfoHelper

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

    • getUserCode

      public String 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

      protected String getUserCodeFromUserBean(jakarta.servlet.http.HttpServletRequest request)
      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

      protected String createUserCodeFromUserId(String userCode)
      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

      protected String getUserCodeFromRequest(jakarta.servlet.http.HttpServletRequest request)
      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

      protected String 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

      protected void updateUserSessionId(String userCode)
      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

      protected void updateCookie(String userCode, int age)
      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 cookie
      age - 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

      protected String getUserCodeFromCookie(jakarta.servlet.http.HttpServletRequest request)
      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

      public void storeQueryId(String queryId, List<Map<String,Object>> documentItems)
      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 query
      documentItems - the list of document maps containing search results
    • getResultDocIds

      public String[] getResultDocIds(String queryId)
      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

      public void setCookieName(String cookieName)
      Sets the name of the user identification cookie.
      Parameters:
      cookieName - the name to use for the user identification cookie
    • setCookieDomain

      public void setCookieDomain(String cookieDomain)
      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

      public void setCookiePath(String cookiePath)
      Sets the path for the user identification cookie.
      Parameters:
      cookiePath - the path to use for the user identification cookie
    • setCookieSecure

      public void setCookieSecure(Boolean cookieSecure)
      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