Source Code Cross Referenced for UserInstanceManager.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2001 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal;
007:
008:        import java.io.Serializable;
009:        import java.util.Hashtable;
010:
011:        import javax.servlet.http.HttpServletRequest;
012:        import javax.servlet.http.HttpSession;
013:        import javax.servlet.http.HttpSessionBindingEvent;
014:        import javax.servlet.http.HttpSessionBindingListener;
015:
016:        import org.jasig.portal.security.IPerson;
017:        import org.jasig.portal.security.PersonManagerFactory;
018:        import org.jasig.portal.security.PortalSecurityException;
019:        import org.apache.commons.logging.Log;
020:        import org.apache.commons.logging.LogFactory;
021:
022:        /**
023:         * Determines which user instance object to use for a given user.
024:         *
025:         * @author Peter Kharchenko  {@link <a href="mailto:pkharchenko@interactivebusiness.com"">pkharchenko@interactivebusiness.com"</a>}
026:         * @version $Revision 1.1$
027:         */
028:        public class UserInstanceManager {
029:
030:            private static final Log log = LogFactory
031:                    .getLog(UserInstanceManager.class);
032:
033:            // a table to keep guestUserInstance objects
034:            static Hashtable guestUserInstances = new Hashtable();
035:
036:            /**
037:             * Returns the UserInstance object that is associated with the given request.
038:             * @param request Incoming HttpServletRequest
039:             * @return UserInstance object associated with the given request
040:             */
041:            public static UserInstance getUserInstance(
042:                    HttpServletRequest request) throws PortalException {
043:                IPerson person = null;
044:                try {
045:                    // Retrieve the person object that is associated with the request
046:                    person = PersonManagerFactory.getPersonManagerInstance()
047:                            .getPerson(request);
048:                    if (person == null) {
049:                        throw new IllegalStateException(
050:                                "Configured PersonManager returned null person for this request.  With no user, there's no UserInstance.  Is PersonManager misconfigured?  RDBMS access misconfigured?");
051:                    }
052:                } catch (Exception e) {
053:                    log.error(
054:                            "UserInstanceManager: Unable to retrieve IPerson!",
055:                            e);
056:                    throw (new PortalSecurityException(
057:                            "Could not retrieve IPerson", e));
058:                }
059:
060:                HttpSession session = request.getSession(false);
061:
062:                // Return the UserInstance object if it's in the session
063:                UserInstance userInstance = null;
064:                UserInstanceHolder holder = (UserInstanceHolder) session
065:                        .getAttribute(UserInstanceHolder.KEY);
066:                if (holder != null)
067:                    userInstance = holder.getUserInstance();
068:
069:                if (userInstance != null) {
070:                    return (userInstance);
071:                }
072:                // Create either a UserInstance or a GuestUserInstance
073:                if (person.isGuest()) {
074:                    GuestUserInstance guestUserInstance = (GuestUserInstance) guestUserInstances
075:                            .get(new Integer(person.getID()));
076:                    if (guestUserInstance == null) {
077:                        guestUserInstance = new GuestUserInstance(person);
078:                        guestUserInstances.put(new Integer(person.getID()),
079:                                guestUserInstance);
080:                    }
081:                    guestUserInstance.registerSession(request);
082:                    userInstance = guestUserInstance;
083:                } else {
084:                    if (person.getSecurityContext().isAuthenticated()) {
085:                        userInstance = new UserInstance(person);
086:                    } else {
087:                        // we can't allow for unauthenticated, non-guest user to come into the system
088:                        throw new PortalSecurityException(
089:                                "System does not allow for unauthenticated non-guest users.");
090:                    }
091:                }
092:
093:                if (holder == null)
094:                    holder = new UserInstanceHolder();
095:                holder.setUserInstance(userInstance);
096:
097:                // Put the user instance in the user's session
098:                session.setAttribute(UserInstanceHolder.KEY, holder);
099:
100:                // Return the new UserInstance
101:                return (userInstance);
102:            }
103:
104:            /**
105:             * <p>Serializable wrapper class so the UserInstance object can
106:             * be indirectly stored in the session. The manager can deal with
107:             * this class returning a null value and its field is transient
108:             * so the session can be serialized successfully with the
109:             * UserInstance object in it.</p>
110:             * <p>Implements HttpSessionBindingListener and delegates those methods to
111:             * the wrapped UserInstance, if present.</p>
112:             */
113:            private static class UserInstanceHolder implements  Serializable,
114:                    HttpSessionBindingListener {
115:                public transient static final String KEY = UserInstanceHolder.class
116:                        .getName();
117:
118:                private transient UserInstance ui = null;
119:
120:                /**
121:                 * @return Returns the userInstance.
122:                 */
123:                protected UserInstance getUserInstance() {
124:                    return this .ui;
125:                }
126:
127:                /**
128:                 * @param userInstance The userInstance to set.
129:                 */
130:                protected void setUserInstance(UserInstance userInstance) {
131:                    this .ui = userInstance;
132:                }
133:
134:                public void valueBound(HttpSessionBindingEvent bindingEvent) {
135:                    // delegate to contained UserInstance if there is one
136:                    if (this .ui != null) {
137:                        this .ui.valueBound(bindingEvent);
138:                    }
139:
140:                }
141:
142:                public void valueUnbound(HttpSessionBindingEvent bindingEvent) {
143:                    // delegate to contained UserInstance if there is one
144:                    if (this.ui != null) {
145:                        this.ui.valueUnbound(bindingEvent);
146:                    }
147:
148:                }
149:            }
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.