try {
// Retrieve the person object that is associated with the request
person = PersonManagerFactory.getPersonManagerInstance().getPerson(request);
} catch (Exception e) {
log.error( "UserInstanceManager: Unable to retrieve IPerson!", e);
throw (new PortalSecurityException("Could not retrieve IPerson", e));
}
HttpSession session = request.getSession(false);
// Return the UserInstance object if it's in the session
UserInstance userInstance = null;
UserInstanceHolder holder = (UserInstanceHolder)session.getAttribute(UserInstanceHolder.KEY);
if (holder != null)
userInstance = holder.getUserInstance();
if (userInstance != null) {
return (userInstance);
}
// Create either a UserInstance or a GuestUserInstance
if (person.isGuest()) {
GuestUserInstance guestUserInstance = (GuestUserInstance) guestUserInstances.get(new Integer(person.getID()));
if(guestUserInstance==null) {
guestUserInstance = new GuestUserInstance(person);
guestUserInstances.put(new Integer(person.getID()),guestUserInstance);
}
guestUserInstance.registerSession(request);
userInstance = guestUserInstance;
} else {
if(person.getSecurityContext().isAuthenticated()) {
userInstance = new UserInstance(person);
} else {
// we can't allow for unauthenticated, non-guest user to come into the system
throw new PortalSecurityException("System does not allow for unauthenticated non-guest users.");
}
}
if (holder == null)
holder = new UserInstanceHolder();