Class SessionInfo

java.lang.Object
de.craftsblock.craftsnet.api.session.SessionInfo

public class SessionInfo extends Object
Manages session metadata and handles the persistence and lifecycle of sessions. The SessionInfo class works in conjunction with Session to manage session identifiers and integrate sessions with HTTP exchanges and caches.

It provides methods to load sessions, make them persistent, and destroy them. Compatibility with HTTP exchanges is ensured through validation methods.

Since:
3.0.6-SNAPSHOT
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Cookie
    The reference Cookie
    static final String
    The name of the cookie used to store session identifiers.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new SessionInfo instance associated with the specified session.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Destroys the persistent session by removing it from the cache, deleting the session file, and clearing the session cookie in the HTTP response.
    static @Nullable String
    Extracts the session ID from the request cookies.
    Retrieves the CraftsNet instance associated with this session, if available.
    Retrieves the Logger instance associated with this session, if available.
    Retrieves the Session instance associated with this metadata.
    Retrieves the session ID associated with this session, if available.
    boolean
    Checks whether the session is persistent.
    protected void
    Loads session metadata from the exchange and integrates it into the session system.
    protected void
    Makes the session persistent by generating a unique session ID and updating the HTTP response with a session cookie.
    protected Session
    Performs a quick session check against the session storage to validate that the current session is a real session.
    static void
    setReferenceCookie(Cookie referenceCookie)
    Setting the reference cookie whose parameters are used when session cookies are created or deleted.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • SessionInfo

      public SessionInfo(Session session)
      Creates a new SessionInfo instance associated with the specified session.
      Parameters:
      session - the session associated with this metadata.
  • Method Details

    • setReferenceCookie

      public static void setReferenceCookie(Cookie referenceCookie)
      Setting the reference cookie whose parameters are used when session cookies are created or deleted.
      Parameters:
      referenceCookie - The reference instance cookie.
      Since:
      3.4.0-SNAPSHOT
    • load

      protected void load()
      Loads session metadata from the exchange and integrates it into the session system. The session is marked as persistent if a session ID is found.
    • secureSession

      protected Session secureSession()
      Performs a quick session check against the session storage to validate that the current session is a real session.
      Returns:
      Session for method chaining in SessionCache.
      Since:
      3.4.3-SNAPSHOT
    • makePersistent

      protected void makePersistent()
      Makes the session persistent by generating a unique session ID and updating the HTTP response with a session cookie. The session is added to the session cache.
      Throws:
      RuntimeException - if a secure random passphrase cannot be generated.
    • destroyPersistent

      protected void destroyPersistent()
      Destroys the persistent session by removing it from the cache, deleting the session file, and clearing the session cookie in the HTTP response.
    • getCraftsNet

      public CraftsNet getCraftsNet()
      Retrieves the CraftsNet instance associated with this session, if available.
      Returns:
      the CraftsNet instance or null if not available.
    • getLogger

      public Logger getLogger()
      Retrieves the Logger instance associated with this session, if available.
      Returns:
      the Logger instance or null if not available.
    • getSessionID

      public String getSessionID()
      Retrieves the session ID associated with this session, if available.
      Returns:
      the session ID or null if the session is not persistent.
    • isPersistent

      public boolean isPersistent()
      Checks whether the session is persistent.
      Returns:
      true if the session is persistent, otherwise false.
    • getSession

      public Session getSession()
      Retrieves the Session instance associated with this metadata.
      Returns:
      the associated Session.
    • extractSession

      @Nullable public static @Nullable String extractSession(Request request)
      Extracts the session ID from the request cookies.
      Parameters:
      request - the HTTP request to extract the session ID from.
      Returns:
      the session ID or null if no session ID is present.