SLING-2167 : Use session from default implementation to let the tests pass

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1157048 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 b3f9ecb..e3e6ba7 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
@@ -21,10 +21,12 @@
 import java.util.Hashtable;
 import java.util.Map;
 
+import javax.jcr.Credentials;
 import javax.jcr.LoginException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 
@@ -101,10 +103,10 @@
         return repository;
     }
 
+    private static char[] EMPTY_PW = new char[0];
+
     @Override
     protected SessionProvider getSessionProvider() {
-        // TODO - we have to fix this!!
-        final SessionProvider sp = super.getSessionProvider();
         return new SessionProvider() {
 
             public Session getSession(final HttpServletRequest req,
@@ -113,15 +115,20 @@
             throws LoginException, ServletException, RepositoryException {
                 final ResourceResolver resolver = (ResourceResolver) req.getAttribute(AuthenticationSupport.REQUEST_ATTRIBUTE_RESOLVER);
                 if ( resolver != null ) {
-                    final Session superSession = sp.getSession(req, repository, workspace);
-                    return superSession;
+                    final Session session = resolver.adaptTo(Session.class);
+                    // as the session might be longer used by davex than the request
+                    // we have to create a new session!
+                    if ( session != null ) {
+                        final Credentials credentials = new SimpleCredentials(session.getUserID(), EMPTY_PW);
+                        final Session newSession = session.impersonate(credentials);
+                        return newSession;
+                    }
                 }
                 return null;
             }
 
-            public void releaseSession(Session paramSession) {
-                // nothing to do
-
+            public void releaseSession(final Session session) {
+                session.logout();
             }
         };
     }