SessionHelper Class
- public class SessionHelper
extends Object
-
Hierarchy
-
Object
SessionHelper
public static final String |
-
LOGIN_UID
- Constant to indicate user has logged in with a valid user id
|
public static final String |
-
PROFILE_WRAPPER
- constant to look up the current profile wrapper
|
public static String |
-
getAuthenticatedUserId(HttpServletRequest req)
- Get the logged in user's id from the request.
|
public static boolean |
-
getFireLoginEvent(HttpSession session)
|
public static ProfileWrapper |
-
getProfile(HttpServletRequest req)
- Get the current profile from either the session or the request.
|
public static ProfileWrapper |
-
getProfile(HttpServletRequest req, boolean createNew)
- Look for a profile in the request, with the option to create a new
Session if there is not a current one in the Request object.
|
public static ProfileWrapper |
-
getProfile(HttpSession session)
- Get the current profile from the session
|
public static String |
-
getUserId(HttpServletRequest req)
- Get the (not neccessarily logged in) user's id from the request.
|
public static void |
-
postCreateUser(HttpServletRequest request, String username, String password, boolean saveAnonymous, boolean fireEvent, boolean login)
- Actions to be performed upon user creation (self-registration style).
|
public static void |
-
postLogin(HttpServletRequest request)
- Option to fire SessionLoginEvent
|
public static void |
-
putProfileInRequest(HttpServletRequest req, ProfileWrapper profile)
- Put a profile in the request.
|
public static void |
-
putProfileInSession(HttpServletRequest req, ProfileWrapper profile)
- Put a profile in the session.
|
public static void |
-
putProfileInSession(HttpSession session, ProfileWrapper profile)
- Put a profile in the session.
|
public static ProfileWrapper |
-
removeAndReturnProfile(HttpSession session)
- Removes profile wrapper references from the session and returns it.
|
public static void |
-
removeProfile(HttpServletRequest req)
- Removes profile wrapper references from both the request and the
session.
|
public static void |
-
removeProfile(HttpSession session)
- Removes profile wrapper references from the session.
|
public static void |
-
setFireLoginEvent(ServletContext sc, boolean doFire)
- Look in web.xml to see if we're going to fire SessionLoginEvents upon
user login.
|
public static boolean |
-
userIsRegistered(HttpSession session)
- Determine whether user is authenticated by presence of attribute in
Session
|
Methods from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LOGIN_UID
public static final String LOGIN_UID
- Constant to indicate user has logged in with a valid user id
PROFILE_WRAPPER
public static final String PROFILE_WRAPPER
- constant to look up the current profile wrapper
SessionHelper
public SessionHelper()
getAuthenticatedUserId(HttpServletRequest) Method
public static String getAuthenticatedUserId(HttpServletRequest req)
Get the logged in user's id from the request.
This checks for the user principal on the request.
Parameters
-
req
- the servlet request.
Returns
- the user id, null if not authenticated.
getFireLoginEvent(HttpSession) Method
public static boolean getFireLoginEvent(HttpSession session)
getProfile(HttpServletRequest) Method
public static ProfileWrapper getProfile(HttpServletRequest req)
Get the current profile from either the session or the request.
Looks in the session first, then the request.
getProfile(HttpServletRequest, boolean) Method
public static ProfileWrapper getProfile(HttpServletRequest req,
boolean createNew)
Look for a profile in the request, with the option to create a new
Session if there is not a current one in the Request object.
getProfile(HttpSession) Method
public static ProfileWrapper getProfile(HttpSession session)
Get the current profile from the session
getUserId(HttpServletRequest) Method
public static String getUserId(HttpServletRequest req)
Get the (not neccessarily logged in) user's id from the request.
This will check the username of a profile in the request/session
first (this will handle tracked anonymous users). If there's no profile
or it's fully anonymous, this will check the authenticated user id.
Parameters
-
req
- the servlet request.
Returns
- the user id, null if cannot be determined.
postCreateUser(HttpServletRequest, String, String, boolean, boolean, boolean) Method
public static void postCreateUser(HttpServletRequest request,
String username,
String password,
boolean saveAnonymous,
boolean fireEvent,
boolean login)
throws LoginException
Actions to be performed upon user creation (self-registration style).
This will authenticate the new user in the request, update the user
profile in the session as needed, fire a SessionLoginEvent, then fire
a UserRegistrationEvent.
NOTE that this method always removes the original profile and
replaces it with a new one representing the new user, regardless of whether
they logged in. That new profile is ProfileType.REGISTERED.
Exceptions
-
LoginException
postLogin(HttpServletRequest) Method
public static void postLogin(HttpServletRequest request)
Option to fire SessionLoginEvent
putProfileInRequest(HttpServletRequest, ProfileWrapper) Method
public static void putProfileInRequest(HttpServletRequest req,
ProfileWrapper profile)
Put a profile in the request.
putProfileInSession(HttpServletRequest, ProfileWrapper) Method
public static void putProfileInSession(HttpServletRequest req,
ProfileWrapper profile)
Put a profile in the session.
putProfileInSession(HttpSession, ProfileWrapper) Method
public static void putProfileInSession(HttpSession session,
ProfileWrapper profile)
Put a profile in the session.
removeAndReturnProfile(HttpSession) Method
public static ProfileWrapper removeAndReturnProfile(HttpSession session)
Removes profile wrapper references from the session and returns it.
Returns
- the ProfileWrapper, or null if none was found
removeProfile(HttpServletRequest) Method
public static void removeProfile(HttpServletRequest req)
Removes profile wrapper references from both the request and the
session.
removeProfile(HttpSession) Method
public static void removeProfile(HttpSession session)
Removes profile wrapper references from the session.
setFireLoginEvent(ServletContext, boolean) Method
public static void setFireLoginEvent(ServletContext sc,
boolean doFire)
Look in web.xml to see if we're going to fire SessionLoginEvents upon
user login. Specified as follows:
PortalServletFilter
com.bea.p13n.servlets.PortalServletFilter
fireSessionLoginEvent
false
Option to fire SessionLoginEvent , defaults to true if not set
userIsRegistered(HttpSession) Method
public static boolean userIsRegistered(HttpSession session)
Determine whether user is authenticated by presence of attribute in
Session