You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2012/01/25 00:14:14 UTC

svn commit: r1235543 - /sling/trunk/bundles/jcr/davex/src/main/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServlet.java

Author: fmeschbe
Date: Tue Jan 24 23:14:13 2012
New Revision: 1235543

URL: http://svn.apache.org/viewvc?rev=1235543&view=rev
Log:
SLING-2325 Always create a long-lived session

Modified:
    sling/trunk/bundles/jcr/davex/src/main/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServlet.java

Modified: sling/trunk/bundles/jcr/davex/src/main/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/davex/src/main/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServlet.java?rev=1235543&r1=1235542&r2=1235543&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/davex/src/main/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServlet.java (original)
+++ sling/trunk/bundles/jcr/davex/src/main/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServlet.java Tue Jan 24 23:14:13 2012
@@ -41,7 +41,6 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.auth.core.AuthenticationSupport;
 import org.apache.sling.commons.osgi.OsgiUtil;
 import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.settings.SlingSettingsService;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
@@ -80,12 +79,6 @@ public class SlingDavExServlet extends J
 
     private static char[] EMPTY_PW = new char[0];
 
-    private static final String REQUEST_METHOD_SUBSCRIBE = "SUBSCRIBE";
-
-    private static final String REQUEST_METHOD_LOCK = "LOCK";
-
-    private static final String SESSION_FLAG_LONG_LIVED = "$sling.davex$";
-
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
@@ -98,9 +91,6 @@ public class SlingDavExServlet extends J
     @Reference
     private AuthenticationSupport authSupport;
 
-    @Reference
-    private SlingSettingsService slingSettings;
-
     /**
      * The path at which the DavEx servlet has successfully been
      * registered in the {@link #activate(Map)} method. If this is
@@ -177,18 +167,9 @@ public class SlingDavExServlet extends J
                 if (resolver != null) {
                     final Session session = resolver.adaptTo(Session.class);
                     if (session != null) {
-                        if (requireLongLivedSession(req)) {
-                            // as the session might be longer used by davex than
-                            // the request we have to create a new session!
-                            final Session newSession = getLongLivedSession(session);
-                            log.debug("getSession: Creating new Session ({}) for {}", newSession,
-                                newSession.getUserID());
-                            return newSession;
-
-                        }
-
-                        log.debug("getSession: Using Session ({}) from Sling", session);
-                        return session;
+                        final Session newSession = getLongLivedSession(session);
+                        log.debug("getSession: Creating new Session ({}) for {}", newSession, newSession.getUserID());
+                        return newSession;
                     }
                 }
 
@@ -196,17 +177,8 @@ public class SlingDavExServlet extends J
             }
 
             public void releaseSession(final Session session) {
-                if (isLongLivedSession(session)) {
-                    log.debug("releaseSession: Logging out long lived Session ({})", session);
-                    session.logout();
-                } else {
-                    log.debug("releaseSession: Nothing to do with Session ({}) from Sling", session);
-                }
-            }
-
-            private boolean requireLongLivedSession(final HttpServletRequest req) {
-                final String method = req.getMethod();
-                return REQUEST_METHOD_LOCK.equals(method) || REQUEST_METHOD_SUBSCRIBE.equals(method);
+                log.debug("releaseSession: Logging out long lived Session ({})", session);
+                session.logout();
             }
 
             /**
@@ -229,13 +201,9 @@ public class SlingDavExServlet extends J
                 final String user = slingSession.getUserID();
                 try {
                     final SimpleCredentials credentials = new SimpleCredentials(user, EMPTY_PW);
-                    credentials.setAttribute(SESSION_FLAG_LONG_LIVED, Boolean.TRUE);
-
                     final String wsp = slingSession.getWorkspace().getName();
                     adminSession = SlingDavExServlet.this.repository.loginAdministrative(wsp);
-
                     return adminSession.impersonate(credentials);
-
                 } catch (RepositoryException re) {
 
                     // LoginException from impersonate (missing permission)
@@ -250,10 +218,6 @@ public class SlingDavExServlet extends J
                     }
                 }
             }
-
-            private boolean isLongLivedSession(final Session session) {
-                return session.getAttribute(SESSION_FLAG_LONG_LIVED) != null;
-            }
         };
     }
 }