Package com.mcawful

Class PanelSessionManager

java.lang.Object
com.mcawful.PanelSessionManager

public final class PanelSessionManager extends Object
Panel login sessions that are started by signing in with a passkey.

The browser holds a random session ID in a cookie. Only the SHA-256 of the ID is kept here, and only in memory, so every session ends when the bot restarts.

Author:
mcawful
  • Field Details

  • Method Details

    • createSession

      public static String createSession(String username, String origin, String passkey, long lifetime)
      Starts a session
      Parameters:
      username - the name of the user who signed in
      origin - the origin the user signed in on
      passkey - the primary key of the passkey that was used
      lifetime - how long the session lasts, in milliseconds
      Returns:
      the session ID to send to the browser in the COOKIE cookie
    • getSession

      public static PanelSessionManager.Session getSession(HttpHeaders headers)
      Finds the session of a request
      Parameters:
      headers - the HttpHeaders of the request
      Returns:
      the PanelSessionManager.Session; null if there is no valid session
    • revokeSession

      public static boolean revokeSession(HttpHeaders headers)
      Ends the session of a request, if it has one and the request comes from the origin the user signed in on. Other sites must not be able to sign the user out
      Parameters:
      headers - the HttpHeaders of the request
      Returns:
      true if a session was ended
    • revokePasskey

      public static void revokePasskey(String passkey)
      Ends all sessions that were started with a passkey
      Parameters:
      passkey - the primary key of the passkey
    • revokeUser

      public static void revokeUser(String username)
      Ends all sessions of a user
      Parameters:
      username - the user's name