Class SessionHandler

java.lang.Object
com.protegrity.ap.java.SessionHandler

public class SessionHandler extends Object
Manages user sessions for Protector operations.

This class handles session creation, validation, and lifecycle management including timeout detection. Sessions are validated based on a configurable time-to-live duration.

Since:
1.0.0
  • Constructor Details

    • SessionHandler

      public SessionHandler(int sessionTimeout)
      Constructs a new SessionHandler with the specified timeout.
      Parameters:
      sessionTimeout - session timeout in minutes
  • Method Details

    • createSession

      public SessionObject createSession(String apiUser) throws ProtectorException
      Creates a new session for the specified user.
      Parameters:
      apiUser - the username for the session
      Returns:
      a new SessionObject
      Throws:
      ProtectorException - if the username is null or empty
    • closeSession

      @Deprecated public void closeSession(SessionObject session) throws ProtectorException
      Deprecated.
      This method uses reflection to clear fields and may not be reliable.
      Closes a session by clearing all session fields.
      Parameters:
      session - the session to close
      Throws:
      ProtectorException - if closing the session fails
    • getUser

      public String getUser(SessionObject session) throws ProtectorException
      Gets the username associated with the session.
      Parameters:
      session - the session to query
      Returns:
      the username
      Throws:
      ProtectorException - if the session is invalid or expired
    • setLastError

      public void setLastError(SessionObject session, String errorMessage) throws ProtectorException
      Sets the last error message for the session.
      Parameters:
      session - the session to update
      errorMessage - the error message to set
      Throws:
      ProtectorException - if setting the error fails
    • getLastError

      public String getLastError(SessionObject session) throws ProtectorException
      Gets the last error message for the session.
      Parameters:
      session - the session to query
      Returns:
      the last error message, or null if no error occurred
      Throws:
      ProtectorException - if getting the error fails