public class SessionManager extends Object
| Modifier and Type | Field and Description |
|---|---|
static String | SESSION_ATTR_USERSESSION_ATTR_USER. |
static String | SESSION_COOKIE_NAMESESSION_COOKIE_NAME. |
| Modifier and Type | Method and Description |
|---|---|
void | clearFailedLogins(String ip)Clear failed login attempts for an IP after successful login. |
String | createSession(String username)Create a new session for a user with default 30 min expiry. |
String | createSession(String username,
long expiryMs)Create a new session for a user with custom expiry. |
static SessionManager | getInstance() |
void | invalidateSession(String token)Invalidate a session. |
boolean | isBlocked(String ip)Check if IP is blocked due to too many failed attempts. |
void | recordFailedLogin(String ip)Record a failed login attempt from an IP address. |
void | restoreSession(String token,
String username,
long expiresAt)Restore a persisted session with its original token. |
void | shutdown()shutdown. |
String | validateSession(String token)Validate a session token. |
public static final String SESSION_ATTR_USER
public static final String SESSION_COOKIE_NAME
public void clearFailedLogins(String ip)
public String createSession(String username)
public String createSession(String username, long expiryMs)
username - the usernameexpiryMs - expiry time in milliseconds, or -1 for no expiry (forever)public static SessionManager getInstance()
public void invalidateSession(String token)
public boolean isBlocked(String ip)
public void recordFailedLogin(String ip)
public void restoreSession(String token, String username, long expiresAt)
token - the original session token from persistenceusername - the usernameexpiresAt - absolute expiry time, or -1 for no expirypublic void shutdown()