Class SessionInfo
java.lang.Object
de.craftsblock.craftsnet.api.session.SessionInfo
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 -
Constructor Summary
ConstructorsConstructorDescriptionSessionInfo(Session session) Creates a newSessionInfoinstance associated with the specified session. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidDestroys the persistent session by removing it from the cache, deleting the session file, and clearing the session cookie in the HTTP response.static @Nullable StringextractSession(Request request) Extracts the session ID from the request cookies.Retrieves theCraftsNetinstance associated with this session, if available.Retrieves theLoggerinstance associated with this session, if available.Retrieves theSessioninstance associated with this metadata.Retrieves the session ID associated with this session, if available.booleanChecks whether the session is persistent.protected voidload()Loads session metadata from the exchange and integrates it into the session system.protected voidMakes the session persistent by generating a unique session ID and updating the HTTP response with a session cookie.protected SessionPerforms a quick session check against the session storage to validate that the current session is a real session.static voidsetReferenceCookie(Cookie referenceCookie) Setting the referencecookiewhose parameters are used when session cookies are created or deleted.
-
Field Details
-
SID_COOKIE_NAME
The name of the cookie used to store session identifiers.- See Also:
-
REFERENCE_COOKIE
The referenceCookie
-
-
Constructor Details
-
SessionInfo
Creates a newSessionInfoinstance associated with the specified session.- Parameters:
session- the session associated with this metadata.
-
-
Method Details
-
setReferenceCookie
Setting the referencecookiewhose parameters are used when session cookies are created or deleted.- Parameters:
referenceCookie- The reference instancecookie.- 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
Performs a quick session check against the session storage to validate that the current session is a real session.- Returns:
Sessionfor method chaining inSessionCache.- 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
Retrieves theCraftsNetinstance associated with this session, if available.- Returns:
- the
CraftsNetinstance ornullif not available.
-
getLogger
Retrieves theLoggerinstance associated with this session, if available.- Returns:
- the
Loggerinstance ornullif not available.
-
getSessionID
Retrieves the session ID associated with this session, if available.- Returns:
- the session ID or
nullif the session is not persistent.
-
isPersistent
public boolean isPersistent()Checks whether the session is persistent.- Returns:
trueif the session is persistent, otherwisefalse.
-
getSession
Retrieves theSessioninstance associated with this metadata.- Returns:
- the associated
Session.
-
extractSession
Extracts the session ID from the request cookies.- Parameters:
request- the HTTP request to extract the session ID from.- Returns:
- the session ID or
nullif no session ID is present.
-