01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.security.provider;
07:
08: import javax.servlet.http.HttpServletRequest;
09: import javax.servlet.http.HttpSession;
10:
11: import org.jasig.portal.security.IPerson;
12: import org.jasig.portal.security.IPersonManager;
13: import org.jasig.portal.security.PersonFactory;
14: import org.jasig.portal.security.PortalSecurityException;
15: import org.apache.commons.logging.Log;
16: import org.apache.commons.logging.LogFactory;
17:
18: /**
19: * Manages the storage of an IPerson object in a user's session.
20: * @author Bernie Durfee, bdurfee@interactivebusiness.com
21: */
22: public class SimplePersonManager implements IPersonManager {
23:
24: private static final Log log = LogFactory
25: .getLog(SimplePersonManager.class);
26:
27: /**
28: * Retrieve an IPerson object for the incoming request
29: * @param request the servlet request object
30: * @return the IPerson object for the incoming request
31: */
32: public IPerson getPerson(HttpServletRequest request)
33: throws PortalSecurityException {
34: HttpSession session = request.getSession(false);
35: IPerson person = null;
36: // Return the person object if it exists in the user's session
37: if (session != null)
38: person = (IPerson) session.getAttribute(PERSON_SESSION_KEY);
39: if (person == null) {
40: try {
41: // Create a guest person
42: person = PersonFactory.createGuestPerson();
43: } catch (Exception e) {
44: // Log the exception
45: log.error("Exception creating guest person.", e);
46: }
47: // Add this person object to the user's session
48: if (person != null && session != null)
49: session.setAttribute(PERSON_SESSION_KEY, person);
50: }
51: return person;
52: }
53: }
|