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 2011/11/09 09:31:58 UTC

svn commit: r1199645 - in /sling/trunk/bundles/jcr/davex: pom.xml src/main/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServlet.java src/main/resources/OSGI-INF/metatype/metatype.properties

Author: fmeschbe
Date: Wed Nov  9 08:31:58 2011
New Revision: 1199645

URL: http://svn.apache.org/viewvc?rev=1199645&view=rev
Log:
SLING-2275 Consolidate configuration
  - use OsgiUtil to convert the configuration property
  - prevent indirect dependencies making Jackrabbit deps provided
  - preset Jackrabbit DavEx config:
      path prefix: same as servlet registration path
      home/tmp directory: sling.home/jackrabbit/tmp
      csrf protection: disabled
      no other parameters are set
  - use Sling settings to get sling.home location

Modified:
    sling/trunk/bundles/jcr/davex/pom.xml
    sling/trunk/bundles/jcr/davex/src/main/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServlet.java
    sling/trunk/bundles/jcr/davex/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: sling/trunk/bundles/jcr/davex/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/davex/pom.xml?rev=1199645&r1=1199644&r2=1199645&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/davex/pom.xml (original)
+++ sling/trunk/bundles/jcr/davex/pom.xml Wed Nov  9 08:31:58 2011
@@ -57,7 +57,8 @@
                         </Import-Package>
                         <Embed-Dependency>
                             jackrabbit-jcr-server,
-                            jackrabbit-webdav
+                            jackrabbit-webdav,
+                            org.apache.sling.commons.osgi;inline=org/apache/sling/commons/osgi/OsgiUtil.class
                         </Embed-Dependency>
                     </instructions>
                 </configuration>
@@ -88,13 +89,13 @@
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>jackrabbit-jcr-server</artifactId>
             <version>2.2.9</version>
-            <scope>compile</scope>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>jackrabbit-webdav</artifactId>
             <version>2.2.9</version>
-            <scope>compile</scope>
+            <scope>provided</scope>
         </dependency>
 
         <dependency>
@@ -109,6 +110,18 @@
             <version>1.0.6</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
+            <version>2.0.6</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.settings</artifactId>
+            <version>1.0.0</version>
+            <scope>provided</scope>
+        </dependency>
 
         <dependency>
             <groupId>javax.jcr</groupId>

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=1199645&r1=1199644&r2=1199645&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 Wed Nov  9 08:31:58 2011
@@ -17,17 +17,14 @@
 package org.apache.sling.jcr.davex.impl.servlets;
 
 import java.util.Dictionary;
-import java.util.Enumeration;
 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;
 
 import org.apache.felix.scr.annotations.Activate;
@@ -38,25 +35,36 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.jackrabbit.server.SessionProvider;
 import org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet;
+import org.apache.jackrabbit.webdav.util.CSRFUtil;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.auth.core.AuthenticationSupport;
-import org.osgi.service.component.ComponentContext;
+import org.apache.sling.commons.osgi.OsgiUtil;
+import org.apache.sling.settings.SlingSettingsService;
 import org.osgi.service.http.HttpService;
+import org.slf4j.LoggerFactory;
 
 /**
  * DavEx WebDav servlet which acquires a Repository instance via the OSGi
  * service registry.
  *
  */
-@Component(label = "%dav.name", description = "%dav.description")
-@Properties( { @Property(name = "alias", value = "/server"),
-        @Property(name = "init.resource-path-prefix", value = "/server"),
-        @Property(name = "init.missing-auth-mapping", value = ""),
-        @Property(name = "service.description", value = "Sling JcrRemoting Servlet"),
-        @Property(name = "service.vendor", value = "The Apache Software Foundation") })
+@SuppressWarnings("serial")
+@Component(metatype = true, label = "%dav.name", description = "%dav.description")
+@Properties({ @Property(name = "service.description", value = "Sling JcrRemoting Servlet"),
+    @Property(name = "service.vendor", value = "The Apache Software Foundation") })
 public class SlingDavExServlet extends JcrRemotingServlet {
 
-    private static final String INIT_KEY_PREFIX = "init.";
+    /**
+     * Default value for the DavEx servlet registration.
+     */
+    private static final String DEFAULT_ALIAS = "/server";
+
+    /**
+     * Name of the property to configure the location for the DavEx servlet
+     * registration. Default for the property is {@link #DEFAULT_ALIAS}.
+     */
+    @Property(value=DEFAULT_ALIAS)
+    private static final String PROP_ALIAS = "alias";
 
     @Reference
     private Repository repository;
@@ -67,35 +75,52 @@ 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
+     * <code>null</code> the DavEx servlet is not registered with the
+     * Http Service.
+     */
+    private String servletAlias;
+
     @Activate
-    protected void activate(final ComponentContext ctx)
-    throws Exception {
+    protected void activate(final Map<String, ?> config) {
         final AuthHttpContext context = new AuthHttpContext();
         context.setAuthenticationSupport(authSupport);
 
-        final String alias = (String)ctx.getProperties().get("alias");
+        final String alias = OsgiUtil.toString(config.get(PROP_ALIAS), DEFAULT_ALIAS);
+
+        // prepare DavEx servlet config
         final Dictionary<String, String> initProps = new Hashtable<String, String>();
-        @SuppressWarnings("unchecked")
-        final Enumeration<String> keyEnum = ctx.getProperties().keys();
-        while ( keyEnum.hasMoreElements() ) {
-            final String key = keyEnum.nextElement();
-            if ( key.startsWith(INIT_KEY_PREFIX) ) {
-                final String paramKey = key.substring(INIT_KEY_PREFIX.length());
-                final Object paramValue = ctx.getProperties().get(key);
 
-                if (paramValue != null) {
-                    initProps.put(paramKey, paramValue.toString());
-                }
-            }
-        }
+        // prefix to the servlet
+        initProps.put(INIT_PARAM_RESOURCE_PATH_PREFIX, alias);
 
-        this.httpService.registerServlet(alias, this, initProps, context);
+        // put the tmp files into Sling home -- or configurable ???
+        initProps.put(INIT_PARAM_HOME, slingSettings.getSlingHome() + "/jackrabbit");
+        initProps.put(INIT_PARAM_TMP_DIRECTORY, "tmp");
+
+        // disable CSRF checks for now (should be handled by Sling)
+        initProps.put(INIT_PARAM_CSRF_PROTECTION, CSRFUtil.DISABLED);
+
+        // register and handle registration failure
+        try {
+            this.httpService.registerServlet(alias, this, initProps, context);
+            this.servletAlias = alias;
+        } catch (Exception e) {
+            LoggerFactory.getLogger(getClass()).error("activate: Failed registering DavEx Servlet at " + alias, e);
+        }
     }
 
     @Deactivate
-    protected void deactivate(final Map<String, Object> props) {
-        final String alias = (String)props.get("alias");
-        this.httpService.unregister(alias);
+    protected void deactivate() {
+        if (this.servletAlias != null) {
+            this.httpService.unregister(servletAlias);
+            this.servletAlias = null;
+        }
     }
 
     @Override
@@ -112,7 +137,7 @@ public class SlingDavExServlet extends J
             public Session getSession(final HttpServletRequest req,
                     final Repository repository,
                     final String workspace)
-            throws LoginException, ServletException, RepositoryException {
+            throws LoginException, RepositoryException {
                 final ResourceResolver resolver = (ResourceResolver) req.getAttribute(AuthenticationSupport.REQUEST_ATTRIBUTE_RESOLVER);
                 if ( resolver != null ) {
                     final Session session = resolver.adaptTo(Session.class);

Modified: sling/trunk/bundles/jcr/davex/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/davex/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1199645&r1=1199644&r2=1199645&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/davex/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ sling/trunk/bundles/jcr/davex/src/main/resources/OSGI-INF/metatype/metatype.properties Wed Nov  9 08:31:58 2011
@@ -33,11 +33,6 @@ dav.description = The DavEx Servlet allo
  requests to this servlet do not pass by the Sling Main Servlet and request \
  processing.
 
-dav.root.name = Root Path
-dav.root.description = The root path at which the DavEx Servlet is \
+alias.name = Root Path
+alias.description = The root path at which the DavEx Servlet is \
  accessible. The default value is "/server".
-
-dav.realm.name = Authentication Realm
-dav.realm.description = The name of the HTTP Basic Authentication Realm \
- presented to the client to ask for authentication credentials to access the \
- repository.