You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:47:28 UTC
[sling-org-apache-sling-jcr-davex] 24/44: 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
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.jcr.davex-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-davex.git
commit 19eb0c87b1bd8853052aa6bc677c99c1c0fb7316
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Wed Nov 9 08:31:58 2011 +0000
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
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/davex@1199645 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 19 ++++-
.../jcr/davex/impl/servlets/SlingDavExServlet.java | 89 ++++++++++++++--------
.../OSGI-INF/metatype/metatype.properties | 9 +--
3 files changed, 75 insertions(+), 42 deletions(-)
diff --git a/pom.xml b/pom.xml
index d46d3e3..be90d86 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
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 29f42d6..8e925bb 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
@@ -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.Property;
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 JcrRemotingServlet {
@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());
- }
- }
- }
- this.httpService.registerServlet(alias, this, initProps, context);
+ // prefix to the servlet
+ initProps.put(INIT_PARAM_RESOURCE_PATH_PREFIX, alias);
+
+ // 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 JcrRemotingServlet {
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);
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
index de8962e..1eee1cd 100644
--- a/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ b/src/main/resources/OSGI-INF/metatype/metatype.properties
@@ -33,11 +33,6 @@ dav.description = The DavEx Servlet allows direct access to the \
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.
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.