X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fkernel%2FWebCmsSessionImpl.java;h=b30b00323eab91659404831e7b7560e6325f8825;hb=277bb126a4b8523b93c2cd9abd345833a8387eba;hp=ac4b35336bed9e77da980920fdc19430689cd16e;hpb=7add600d7837fb72f019de190bd5cafd817a0a0c;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/WebCmsSessionImpl.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/WebCmsSessionImpl.java index ac4b35336..b30b00323 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/WebCmsSessionImpl.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/WebCmsSessionImpl.java @@ -2,6 +2,7 @@ package org.argeo.cms.internal.kernel; import java.util.ArrayList; import java.util.Date; +import java.util.Hashtable; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -10,11 +11,14 @@ import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.cms.auth.WebCmsSession; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceRegistration; import org.osgi.service.http.HttpContext; import org.osgi.service.useradmin.Authorization; public class WebCmsSessionImpl implements WebCmsSession { + private final BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext(); private final static Log log = LogFactory.getLog(WebCmsSessionImpl.class); private final String id; @@ -24,9 +28,14 @@ public class WebCmsSessionImpl implements WebCmsSession { private ServiceRegistration serviceRegistration; - public WebCmsSessionImpl(String id, Authorization authorization) { - this.id = id; + public WebCmsSessionImpl(String sessionId, Authorization authorization) { + this.id = sessionId; this.authorization = authorization; + // register as service + Hashtable props = new Hashtable<>(); + props.put(WebCmsSession.CMS_DN, authorization.getName()); + props.put(WebCmsSession.CMS_SESSION_ID, sessionId); + serviceRegistration = bc.registerService(WebCmsSession.class, this, props); } public void cleanUp() { @@ -40,7 +49,10 @@ public class WebCmsSessionImpl implements WebCmsSession { return authorization; } - @Override + public ServiceRegistration getServiceRegistration() { + return serviceRegistration; + } + public void addHttpSession(HttpServletRequest request) { subHttpSessions.add(new SubHttpSession(request)); } @@ -49,10 +61,6 @@ public class WebCmsSessionImpl implements WebCmsSession { return id; } - public void setServiceRegistration(ServiceRegistration serviceRegistration) { - this.serviceRegistration = serviceRegistration; - } - public String toString() { return "CMS Session #" + id; } @@ -60,16 +68,16 @@ public class WebCmsSessionImpl implements WebCmsSession { static class SubHttpSession { private final HttpSession httpSession; private final String sessionId; -// private final String originalURI; -// private final String servletPath; + // private final String originalURI; + // private final String servletPath; private final Date start = new Date(); public SubHttpSession(HttpServletRequest request) { this.httpSession = request.getSession(); this.sessionId = httpSession.getId(); -// this.originalURI = request.getRequestURI(); -// this.servletPath = request.getServletPath(); + // this.originalURI = request.getRequestURI(); + // this.servletPath = request.getServletPath(); } public Date getStart() { @@ -79,7 +87,7 @@ public class WebCmsSessionImpl implements WebCmsSession { public void cleanUp() { try { httpSession.setAttribute(HttpContext.AUTHORIZATION, null); - //httpSession.setMaxInactiveInterval(1); + // httpSession.setMaxInactiveInterval(1); } catch (Exception e) { log.warn("Could not clean up " + sessionId, e); }