Package me.nickhanson.codeforge.web
Class UserContext
java.lang.Object
me.nickhanson.codeforge.web.UserContext
Helper for reading the authenticated user context (Cognito sub) from the session.
Centralizes logic to avoid repeated boilerplate in servlets.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetUserId(jakarta.servlet.http.HttpServletRequest req) Returns the Cognito subject (userId) stored in session under key "userSub".static booleanisAuthenticated(jakarta.servlet.http.HttpServletRequest req) Convenience method to check if the request is authenticated.
-
Method Details
-
getUserId
Returns the Cognito subject (userId) stored in session under key "userSub".- Parameters:
req- HttpServletRequest- Returns:
- userId string or null if not authenticated
-
isAuthenticated
public static boolean isAuthenticated(jakarta.servlet.http.HttpServletRequest req) Convenience method to check if the request is authenticated.- Parameters:
req- HttpServletRequest- Returns:
- true if a non-blank userSub is present in session
-