Improve CMS session.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / http / WebCmsSessionImpl.java
index 06ff57355d0b92ac3b42bb14acc514d163b45492..3d5e3fe4c612d65781e5fe8196078dc4c05cafcb 100644 (file)
@@ -2,21 +2,36 @@ package org.argeo.cms.internal.http;
 
 import javax.security.auth.Subject;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
 
 import org.argeo.cms.auth.CmsSession;
 import org.argeo.cms.internal.auth.CmsSessionImpl;
 import org.osgi.service.useradmin.Authorization;
 
 public class WebCmsSessionImpl extends CmsSessionImpl {
+       // private final static Log log =
+       // LogFactory.getLog(WebCmsSessionImpl.class);
 
-       public WebCmsSessionImpl(Subject initialSubject, Authorization authorization, String httpSessionId) {
-               super(initialSubject, authorization, httpSessionId);
+       private HttpSession httpSession;
+
+       public WebCmsSessionImpl(Subject initialSubject, Authorization authorization, HttpServletRequest request) {
+               super(initialSubject, authorization, request.getSession(false).getId());
+               httpSession = request.getSession(false);
+       }
+
+       @Override
+       public boolean isValid() {
+               if (isClosed())
+                       return false;
+               try {// test http session
+                       httpSession.getCreationTime();
+                       return true;
+               } catch (IllegalStateException ise) {
+                       return false;
+               }
        }
 
        public static CmsSession getCmsSession(HttpServletRequest request) {
-//             CmsSession cmsSession = (CmsSession) request.getAttribute(CmsSession.class.getName());
-//             if (cmsSession != null)
-//                     return cmsSession;
-               return CmsSessionImpl.getByLocalId(request.getSession().getId());
+               return CmsSessionImpl.getByLocalId(request.getSession(false).getId());
        }
 }