Class UserSession

java.lang.Object
org.example.util.UserSession

public class UserSession extends Object
Global session manager to track the currently authenticated user. Implemented as a thread-safe singleton-like utility.
  • Method Details

    • setInstance

      public static void setInstance(String nickname)
      Initializes the session with a user's nickname.
      Parameters:
      nickname - The nickname of the logged-in user.
    • getCurrentUserNickname

      public static String getCurrentUserNickname()
      Returns:
      The nickname of the current user, or null if no one is logged in.
    • isLoggedIn

      public static boolean isLoggedIn()
      Checks if a user is currently authenticated.
      Returns:
      true if session is active.
    • cleanUserSession

      public static void cleanUserSession()
      Clears the current session (logout).