© 2001 BEA Systems, Inc.

com.beasys.commerce.user
Class UserHelper

java.lang.Object
  |
  +--com.beasys.commerce.user.UserHelper

public class UserHelper
extends java.lang.Object

Helper class to retrieve lightweight user profile objects outside of a JSP/Servlet context.


Inner Class Summary
static class UserHelper.ConfigurableEntityProfileWrapper
          A ProfileWrapper for a ConfigurableEntity.
 
Constructor Summary
UserHelper()
           
 
Method Summary
protected static ConfigurableEntity getEntity(java.lang.String key, java.lang.String typeName)
          Go through the DirectPropertyManager to get the entity specified by the given key and typeName
static ProfileWrapper getProfile(java.lang.String profileKey)
          Retrieve a profile based on the key.
static ProfileWrapper getProfile(java.lang.String profileKey, java.lang.String profileType)
          Retrieve a profile based on the key and type.
static java.lang.String getUserId(javax.servlet.http.HttpServletRequest req)
          Get the logged in user's id from the request.
static ProfileWrapper getUserProfileWrapper(javax.servlet.http.HttpServletRequest req)
          Get a user profile wrapper from the given request.
static ProfileWrapper getUserProfileWrapper(java.lang.String userId)
          Get a user profile wrapper for the given user id.
static ProfileWrapper getUserProfileWrapper(java.lang.String userId, javax.servlet.http.HttpServletRequest req)
          Get a user profile wrapper for the given user id from the given request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserHelper

public UserHelper()
Method Detail

getUserId

public static java.lang.String getUserId(javax.servlet.http.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.

getProfile

public static ProfileWrapper getProfile(java.lang.String profileKey)
                                 throws UserManagementException
Retrieve a profile based on the key. If the profile type for this user is recorded in the database, it will be retrieved and used. This will also try to get a ref to the actual entity bean for security; if the bean cannot be retrieved, this will return a null.
Parameters:
profileKey - the user id
Returns:
a ProfileWrapper representing this profile, or null if it cannot be found
Throws:
UserManagementException - if an error occurs retrieving the profile

getProfile

public static ProfileWrapper getProfile(java.lang.String profileKey,
                                        java.lang.String profileType)
                                 throws UserManagementException
Retrieve a profile based on the key and type. If the profile type for this user is recorded in the database, and is different than the provided type, the type from the database will be retrieved and used.
Parameters:
profileKey - the user id
profileType - the user's profile type
Returns:
a ProfileWrapper representing this profile
Throws:
UserManagementException - if an error occurs retrieving the profile

getEntity

protected static ConfigurableEntity getEntity(java.lang.String key,
                                              java.lang.String typeName)
                                       throws java.rmi.RemoteException,
                                              javax.ejb.CreateException,
                                              ToolkitException
Go through the DirectPropertyManager to get the entity specified by the given key and typeName
Parameters:
key - the profile key
typeName - the profile type
Returns:
a ConfigurableEntity ejb representing the profile
Throws:
java.rmi.RemoteException - if an RMI error occurs
CreateException - if the DirectPropertyManager cannot be created
ToolkitException - if the DirectPropertyManagerHome cannot be found in the JNDI tree

getUserProfileWrapper

public static ProfileWrapper getUserProfileWrapper(java.lang.String userId,
                                                   javax.servlet.http.HttpServletRequest req)
                                            throws UserManagementException
Get a user profile wrapper for the given user id from the given request.

This will first try the profile in the request/session. If that exists and is keyed to the specified user, then it will be used. Otherwise, a profile will be retrieved for the user.

Parameters:
userId - the user id.
req - the servlet request.
Returns:
the profile wrapper or null if not found.
Throws:
UserManagementException - thrown on an error getting the user.

getUserProfileWrapper

public static ProfileWrapper getUserProfileWrapper(java.lang.String userId)
                                            throws UserManagementException
Get a user profile wrapper for the given user id.

This will not use the cached version of the profile, and therefore, probably won't have a successor.

Parameters:
userId - the user id.
Returns:
the profile wrapper or null if not found.
Throws:
UserManagementException - thrown on an error getting the user.

getUserProfileWrapper

public static ProfileWrapper getUserProfileWrapper(javax.servlet.http.HttpServletRequest req)
Get a user profile wrapper from the given request.

This will attempt to retrieve the cached profile. Generally, the <um:getProfile> tag will populate the cached profile.

If the cached profile is not available from the request, this will use the request.getRemoteUser() method to determine the remote username, and create a lightweight profile from that username.

Parameters:
req - the servlet request.
Returns:
the ProfileWrapper or null if not found.

© 2001 BEA Systems, Inc.

Copyright © 2001 BEA Systems, Inc. All Rights Reserved