1 package org
.argeo
.cms
.internal
.kernel
;
3 import java
.util
.ArrayList
;
5 import java
.util
.Hashtable
;
8 import javax
.servlet
.http
.HttpServletRequest
;
9 import javax
.servlet
.http
.HttpSession
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.cms
.auth
.WebCmsSession
;
14 import org
.osgi
.framework
.BundleContext
;
15 import org
.osgi
.framework
.FrameworkUtil
;
16 import org
.osgi
.framework
.ServiceRegistration
;
17 import org
.osgi
.service
.http
.HttpContext
;
18 import org
.osgi
.service
.useradmin
.Authorization
;
20 public class WebCmsSessionImpl
implements WebCmsSession
{
21 private final BundleContext bc
= FrameworkUtil
.getBundle(getClass()).getBundleContext();
22 private final static Log log
= LogFactory
.getLog(WebCmsSessionImpl
.class);
24 private final String id
;
25 private final Authorization authorization
;
27 private List
<SubHttpSession
> subHttpSessions
= new ArrayList
<>();
29 private ServiceRegistration
<WebCmsSession
> serviceRegistration
;
31 public WebCmsSessionImpl(String sessionId
, Authorization authorization
) {
33 this.authorization
= authorization
;
34 // register as service
35 Hashtable
<String
, String
> props
= new Hashtable
<>();
36 props
.put(WebCmsSession
.CMS_DN
, authorization
.getName());
37 props
.put(WebCmsSession
.CMS_SESSION_ID
, sessionId
);
38 serviceRegistration
= bc
.registerService(WebCmsSession
.class, this, props
);
41 public void cleanUp() {
42 for (SubHttpSession subSession
: subHttpSessions
)
44 serviceRegistration
.unregister();
48 public Authorization
getAuthorization() {
52 public ServiceRegistration
<WebCmsSession
> getServiceRegistration() {
53 return serviceRegistration
;
56 public void addHttpSession(HttpServletRequest request
) {
57 subHttpSessions
.add(new SubHttpSession(request
));
60 public String
getId() {
64 public String
toString() {
65 return "CMS Session #" + id
;
68 static class SubHttpSession
{
69 private final HttpSession httpSession
;
70 private final String sessionId
;
71 // private final String originalURI;
72 // private final String servletPath;
74 private final Date start
= new Date();
76 public SubHttpSession(HttpServletRequest request
) {
77 this.httpSession
= request
.getSession();
78 this.sessionId
= httpSession
.getId();
79 // this.originalURI = request.getRequestURI();
80 // this.servletPath = request.getServletPath();
83 public Date
getStart() {
87 public void cleanUp() {
89 httpSession
.setAttribute(HttpContext
.AUTHORIZATION
, null);
90 // httpSession.setMaxInactiveInterval(1);
91 } catch (Exception e
) {
92 log
.warn("Could not clean up " + sessionId
, e
);