jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1236820 - in /jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit: server/SessionProviderImpl.java server/jcr/JCRWebdavServer.java webdav/jcr/observation/SubscriptionImpl.java
Date Fri, 27 Jan 2012 18:55:10 GMT
Author: jukka
Date: Fri Jan 27 18:55:09 2012
New Revision: 1236820

URL: http://svn.apache.org/viewvc?rev=1236820&view=rev
Log:
JCR-3222: Allow servlet filters to specify custom session providers

Move the Link header handling from SessionProviderImpl to JCRWebdavServer to avoid breaking
functionality when using an external SessionProvider implementation

Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/SessionProviderImpl.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/jcr/JCRWebdavServer.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/observation/SubscriptionImpl.java

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/SessionProviderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/SessionProviderImpl.java?rev=1236820&r1=1236819&r2=1236820&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/SessionProviderImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/SessionProviderImpl.java
Fri Jan 27 18:55:09 2012
@@ -16,11 +16,8 @@
  */
 package org.apache.jackrabbit.server;
 
-import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Locale;
 import java.util.Map;
 
 import javax.jcr.Credentials;
@@ -31,11 +28,6 @@ import javax.jcr.Session;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 
-import org.apache.jackrabbit.commons.webdav.JcrRemotingConstants;
-import org.apache.jackrabbit.spi.commons.SessionExtensions;
-import org.apache.jackrabbit.util.Text;
-import org.apache.jackrabbit.webdav.util.LinkHeaderFieldParser;
-
 /**
  * This class implements a default session provider based on a given
  * {@link CredentialsProvider credentials provider}. Additionally,
@@ -46,8 +38,6 @@ import org.apache.jackrabbit.webdav.util
  */
 public class SessionProviderImpl implements SessionProvider {
 
-    public static final String ATTRIBUTE_SESSION_ID = SessionProviderImpl.class + "#sessionid()";
-    
     /**
      * the credentials provider
      */
@@ -99,17 +89,6 @@ public class SessionProviderImpl impleme
             }
         }
 
-        // extract information from Link header fields
-        LinkHeaderFieldParser lhfp = new LinkHeaderFieldParser(
-                request.getHeaders("Link"));
-        String userData = getJcrUserData(lhfp);
-        s.getWorkspace().getObservationManager().setUserData(userData);
-
-        String sessionId = getSessionIdentifier(lhfp);
-        if (s instanceof SessionExtensions) {
-            SessionExtensions xs = (SessionExtensions) s;
-            xs.setAttribute(ATTRIBUTE_SESSION_ID, sessionId);
-        }
         return s;
     }
 
@@ -127,46 +106,4 @@ public class SessionProviderImpl impleme
         }
     }
 
-    // find first link relation for JCR User Data
-    private String getJcrUserData(LinkHeaderFieldParser lhfp) {
-        String jcrUserData = null;
-        String target = lhfp
-                .getFirstTargetForRelation(JcrRemotingConstants.RELATION_USER_DATA);
-        if (target != null) {
-            jcrUserData = getJcrUserData(target);
-        }
-
-        return jcrUserData;
-    }
-
-    // find first link relation for remote session identifier
-    private String getSessionIdentifier(LinkHeaderFieldParser lhfp) {
-        return lhfp
-                .getFirstTargetForRelation(JcrRemotingConstants.RELATION_REMOTE_SESSION_ID);
-    }
-
-    // extracts User Data string from RFC 2397 "data" URI
-    // only supports the simple case of "data:,..." for now
-    private String getJcrUserData(String target) {
-        try {
-            URI datauri = new URI(target);
-
-            String scheme = datauri.getScheme();
-
-            // Poor Man's data: URI parsing
-            if (scheme != null
-                    && "data".equals(scheme.toLowerCase(Locale.ENGLISH))) {
-
-                String sspart = datauri.getRawSchemeSpecificPart();
-
-                if (sspart.startsWith(",")) {
-                    return Text.unescape(sspart.substring(1));
-                }
-            }
-        } catch (URISyntaxException ex) {
-            // not a URI, skip
-        }
-
-        return null;
-    }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/jcr/JCRWebdavServer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/jcr/JCRWebdavServer.java?rev=1236820&r1=1236819&r2=1236820&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/jcr/JCRWebdavServer.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/jcr/JCRWebdavServer.java
Fri Jan 27 18:55:09 2012
@@ -16,7 +16,10 @@
  */
 package org.apache.jackrabbit.server.jcr;
 
+import org.apache.jackrabbit.commons.webdav.JcrRemotingConstants;
 import org.apache.jackrabbit.server.SessionProvider;
+import org.apache.jackrabbit.spi.commons.SessionExtensions;
+import org.apache.jackrabbit.util.Text;
 import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.DavMethods;
 import org.apache.jackrabbit.webdav.DavSession;
@@ -25,6 +28,7 @@ import org.apache.jackrabbit.webdav.Webd
 import org.apache.jackrabbit.webdav.header.IfHeader;
 import org.apache.jackrabbit.webdav.jcr.JcrDavException;
 import org.apache.jackrabbit.webdav.jcr.JcrDavSession;
+import org.apache.jackrabbit.webdav.util.LinkHeaderFieldParser;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -32,8 +36,12 @@ import javax.jcr.LoginException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletResponse;
+
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
@@ -325,7 +333,17 @@ public class JCRWebdavServer implements 
                 if (DavMethods.DAV_MKWORKSPACE != DavMethods.getMethodCode(request.getMethod()))
{
                     workspaceName = request.getRequestLocator().getWorkspaceName();
                 }
-                return sessionProvider.getSession(request, repository, workspaceName);
+
+                Session session = sessionProvider.getSession(
+                        request, repository, workspaceName);
+
+                // extract information from Link header fields
+                LinkHeaderFieldParser lhfp =
+                        new LinkHeaderFieldParser(request.getHeaders("Link"));
+                setJcrUserData(session, lhfp);
+                setSessionIdentifier(session, lhfp);
+
+                return session;
             } catch (LoginException e) {
                 // LoginException results in UNAUTHORIZED,
                 throw new JcrDavException(e);
@@ -337,6 +355,53 @@ public class JCRWebdavServer implements 
             }
         }
 
+        /**
+         * Find first link relation for JCR user data and set it as
+         * the user data of the observation manager of the given session.
+         */
+        private void setJcrUserData(
+                Session session, LinkHeaderFieldParser lhfp)
+                throws RepositoryException {
+            String data = null;
+
+            // extract User Data string from RFC 2397 "data" URI
+            // only supports the simple case of "data:,..." for now
+            String target = lhfp.getFirstTargetForRelation(
+                    JcrRemotingConstants.RELATION_USER_DATA);
+            if (target != null) {
+                try {
+                    URI uri = new URI(target);
+                    // Poor Man's data: URI parsing
+                    if ("data".equalsIgnoreCase(uri.getScheme())) {
+                        String sspart = uri.getRawSchemeSpecificPart();
+                        if (sspart.startsWith(",")) {
+                            data = Text.unescape(sspart.substring(1));
+                        }
+                    }
+                } catch (URISyntaxException ex) {
+                    // not a URI, skip
+                }
+            }
+
+            try {
+                session.getWorkspace().getObservationManager().setUserData(data);
+            } catch (UnsupportedRepositoryOperationException ignore) {
+            }
+        }
+
+        /**
+         * Find first link relation for remote session identifier and set
+         * it as an attribute of the given session.
+         */
+        private void setSessionIdentifier(
+                Session session, LinkHeaderFieldParser lhfp) {
+            if (session instanceof SessionExtensions) {
+                String name = JcrRemotingConstants.RELATION_REMOTE_SESSION_ID;
+                String id = lhfp.getFirstTargetForRelation(name);
+                ((SessionExtensions) session).setAttribute(name, id);
+            }
+        }
+
         private String getUserID(DavSession session) {
             try {
                 Session s = DavSessionImpl.getRepositorySession(session);

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/observation/SubscriptionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/observation/SubscriptionImpl.java?rev=1236820&r1=1236819&r2=1236820&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/observation/SubscriptionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/observation/SubscriptionImpl.java
Fri Jan 27 18:55:09 2012
@@ -17,7 +17,7 @@
 package org.apache.jackrabbit.webdav.jcr.observation;
 
 import org.apache.jackrabbit.commons.webdav.EventUtil;
-import org.apache.jackrabbit.server.SessionProviderImpl;
+import org.apache.jackrabbit.commons.webdav.JcrRemotingConstants;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.AdditionalEventInfo;
 import org.apache.jackrabbit.spi.commons.SessionExtensions;
@@ -462,17 +462,18 @@ public class SubscriptionImpl implements
                 if (!localFlagSet) {
                     // obtain remote session identifier
                     localFlagSet = true;
-                    String forSessionId = (String) session
-                            .getAttribute(SessionProviderImpl.ATTRIBUTE_SESSION_ID);
+                    String name = JcrRemotingConstants.RELATION_REMOTE_SESSION_ID;
+                    Object forSessionId = session.getAttribute(name);
                     // calculate "local" flags
                     if (forSessionId != null
                             && event instanceof AdditionalEventInfo) {
+                        AdditionalEventInfo aei = (AdditionalEventInfo) event;
                         try {
-                            String eventforSessionId = (String) ((AdditionalEventInfo) event)
-                                    .getSessionAttribute(SessionProviderImpl.ATTRIBUTE_SESSION_ID);
-                            boolean isLocal = forSessionId
-                                    .equals(eventforSessionId);
-                            DomUtil.setAttribute(bundle, XML_EVENT_LOCAL, null, Boolean.toString(isLocal));
+                            boolean isLocal = forSessionId.equals(
+                                    aei.getSessionAttribute(name));
+                            DomUtil.setAttribute(
+                                    bundle, XML_EVENT_LOCAL, null,
+                                    Boolean.toString(isLocal));
                         } catch (UnsupportedRepositoryOperationException ex) {
                             // optional feature
                         }



Mime
View raw message