SLING-2325 Always create a long-lived session
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1235543 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServlet.java b/src/main/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServlet.java
index 4933671..ec1f85d 100644
--- a/src/main/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServlet.java
+++ b/src/main/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServlet.java
@@ -41,7 +41,6 @@
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 @@
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 @@
@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 @@
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 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 @@
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 @@
}
}
}
-
- private boolean isLongLivedSession(final Session session) {
- return session.getAttribute(SESSION_FLAG_LONG_LIVED) != null;
- }
};
}
}