1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.container.session;
18
19 import javax.servlet.http.HttpSession;
20 import javax.servlet.http.HttpSessionBindingEvent;
21 import javax.servlet.http.HttpSessionEvent;
22
23 import org.apache.jetspeed.container.session.PortalSessionsManager;
24 import org.apache.jetspeed.container.session.PortletApplicationSessionMonitor;
25 import org.apache.jetspeed.services.JetspeedPortletServices;
26 import org.apache.jetspeed.services.PortletServices;
27
28 /***
29 * PortletApplicationSessionMonitorImpl
30 *
31 * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
32 * @version $Id: $
33 */
34 public class PortletApplicationSessionMonitorImpl implements PortletApplicationSessionMonitor
35 {
36 private static final long serialVersionUID = -6729032046828426324L;
37
38 private String contextPath;
39 private String portalSessionId;
40 private long portalSessionKey;
41 private transient HttpSession session;
42 private boolean forceInvalidate;
43
44 public PortletApplicationSessionMonitorImpl(String contextPath, String portalSessionId, long portalSessionKey)
45 {
46 this(contextPath, portalSessionId, portalSessionKey, true);
47 }
48
49 public PortletApplicationSessionMonitorImpl(String contextPath, String portalSessionId, long portalSessionKey, boolean forceInvalidate)
50 {
51 this.contextPath = contextPath;
52 this.portalSessionId = portalSessionId;
53 this.portalSessionKey = portalSessionKey;
54 this.forceInvalidate = forceInvalidate;
55 }
56
57
58
59
60 public long getPortalSessionKey()
61 {
62 return portalSessionKey;
63 }
64
65
66
67
68 public String getPortalSessionId()
69 {
70 return portalSessionId;
71 }
72
73 public HttpSession getSession()
74 {
75 return session;
76 }
77
78
79
80
81 public String getContextPath()
82 {
83 return contextPath;
84 }
85
86
87
88
89 public void invalidateSession()
90 {
91 if ( session != null )
92 {
93 HttpSession thisSession = session;
94 session = null;
95 if (forceInvalidate)
96 {
97 try
98 {
99 thisSession.invalidate();
100 }
101 catch (Exception ise)
102 {
103
104 }
105 }
106 }
107 }
108
109
110
111
112 public void valueBound(HttpSessionBindingEvent event)
113 {
114 this.session = event.getSession();
115 }
116
117
118
119
120 public void valueUnbound(HttpSessionBindingEvent event)
121 {
122 if ( session != null )
123 {
124 PortalSessionsManager manager = getManager();
125 if ( manager != null )
126 {
127 manager.sessionDestroyed(this);
128 }
129 session = null;
130 }
131 }
132
133
134
135
136 public void sessionDidActivate(HttpSessionEvent event)
137 {
138 this.session = event.getSession();
139 PortalSessionsManager manager = getManager();
140 if ( manager != null )
141 {
142 manager.sessionDidActivate(this);
143 }
144 }
145
146
147
148
149 public void sessionWillPassivate(HttpSessionEvent event)
150 {
151 PortalSessionsManager manager = getManager();
152 if ( manager != null )
153 {
154 manager.sessionWillPassivate(this);
155 }
156 session = null;
157 }
158
159 private PortalSessionsManager getManager()
160 {
161 PortletServices services = JetspeedPortletServices.getSingleton();
162 if (services != null)
163 {
164 return (PortalSessionsManager)services.getService(PortalSessionsManager.SERVICE_NAME);
165 }
166 return null;
167 }
168 }