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 2022/05/31 13:31:48 UTC

[sling-org-apache-sling-jcr-davex] branch master updated: SLING-11323: Sling update to 47 (#1)

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-davex.git


The following commit(s) were added to refs/heads/master by this push:
     new 629183f  SLING-11323: Sling update to 47 (#1)
629183f is described below

commit 629183fa44557885d418f61caf27efd5eeceeee4
Author: Ashok Pelluru <37...@users.noreply.github.com>
AuthorDate: Tue May 31 15:31:44 2022 +0200

    SLING-11323: Sling update to 47 (#1)
---
 bnd.bnd                                            |  14 +++
 pom.xml                                            |  92 +++++++++----------
 .../jcr/davex/impl/servlets/AuthHttpContext.java   |  28 +++---
 .../jcr/davex/impl/servlets/SlingDavExServlet.java | 101 +++++++++++----------
 ...l.servlets.SlingDavExServlet$Config.properties} |   0
 .../davex/impl/servlets/SlingDavExServletTest.java |  54 +++++++++++
 6 files changed, 179 insertions(+), 110 deletions(-)

diff --git a/bnd.bnd b/bnd.bnd
new file mode 100644
index 0000000..97b7661
--- /dev/null
+++ b/bnd.bnd
@@ -0,0 +1,14 @@
+Bundle-Category: sling,jcr
+Private-Package:\
+    org.apache.jackrabbit.server,\
+    org.apache.jackrabbit.server.jcr,\
+    org.apache.jackrabbit.server.remoting.davex,\
+    org.apache.jackrabbit.server.util,\
+    org.apache.jackrabbit.webdav.jcr.*,\
+    org.apache.sling.jcr.davex.impl.*
+
+-includeresource:\
+    @jackrabbit-jcr-server-*.jar!/org/apache/jackrabbit/server/io/IOUtil*.class
+
+-removeheaders:\
+  Include-Resource
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 9343292..2a3dea8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,13 +12,12 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.sling</groupId>
-        <artifactId>sling</artifactId>
-        <version>26</version>
+        <artifactId>sling-bundle-parent</artifactId>
+        <version>47</version>
         <relativePath />
     </parent>
 
     <artifactId>org.apache.sling.jcr.davex</artifactId>
-    <packaging>bundle</packaging>
     <version>1.3.11-SNAPSHOT</version>
 
     <name>Apache Sling JCR DavEx</name>
@@ -30,41 +29,20 @@
         <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-davex.git</connection>
         <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-davex.git</developerConnection>
         <url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-jcr-davex.git</url>
-      <tag>HEAD</tag>
-  </scm>
+        <tag>HEAD</tag>
+    </scm>
 
     <properties>
-        <jackrabbit.version>2.14.2</jackrabbit.version>
+        <sling.java.version>8</sling.java.version>
+        <jackrabbit.version>2.14.3</jackrabbit.version>
+        <project.build.outputTimestamp>1</project.build.outputTimestamp>
     </properties>
 
     <build>
         <plugins>
             <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-scr-plugin</artifactId>
-                <version>1.26.4</version>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-                <extensions>true</extensions>
-                <configuration>
-                    <instructions>
-                        <Bundle-Category>sling,jcr</Bundle-Category>
-                        <Private-Package>
-                            org.apache.jackrabbit.server,
-                            org.apache.jackrabbit.server.jcr,
-                            org.apache.jackrabbit.server.remoting.davex,
-                            org.apache.jackrabbit.server.util,
-                            org.apache.jackrabbit.webdav.jcr.*,
-                            org.apache.sling.jcr.davex.impl.*
-                        </Private-Package>
-                        <Embed-Dependency>
-                            jackrabbit-jcr-server;inline=org/apache/jackrabbit/server/io/IOUtil*.class,
-                            org.apache.sling.commons.osgi;inline=org/apache/sling/commons/osgi/OsgiUtil.class
-                        </Embed-Dependency>
-                    </instructions>
-                </configuration>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-maven-plugin</artifactId>
             </plugin>
         </plugins>
     </build>
@@ -83,11 +61,6 @@
     </reporting>
 
     <dependencies>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.annotations</artifactId>
-        </dependency>
-
         <dependency>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>jackrabbit-jcr-server</artifactId>
@@ -119,12 +92,6 @@
             <version>2.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>
@@ -135,11 +102,10 @@
         <dependency>
             <groupId>javax.jcr</groupId>
             <artifactId>jcr</artifactId>
-            <version>2.0</version>
         </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>
-            <artifactId>servlet-api</artifactId>
+            <artifactId>javax.servlet-api</artifactId>
         </dependency>
 
         <dependency>
@@ -150,12 +116,28 @@
         <!-- OSGi Libraries -->
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
+            <artifactId>osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.metatype.annotations</artifactId>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.service.http.whiteboard</artifactId>
-            <version>1.0.0</version>
+            <version>1.1.1</version>
         </dependency>
 
         <!-- JUnit -->
@@ -163,5 +145,23 @@
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>4.5.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
+            <version>3.2.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.osgi-mock.junit4</artifactId>
+            <version>3.2.2</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/src/main/java/org/apache/sling/jcr/davex/impl/servlets/AuthHttpContext.java b/src/main/java/org/apache/sling/jcr/davex/impl/servlets/AuthHttpContext.java
index e508b83..cb99803 100644
--- a/src/main/java/org/apache/sling/jcr/davex/impl/servlets/AuthHttpContext.java
+++ b/src/main/java/org/apache/sling/jcr/davex/impl/servlets/AuthHttpContext.java
@@ -22,26 +22,20 @@ import java.util.Set;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.auth.core.AuthenticationSupport;
-import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.propertytypes.ServiceDescription;
+import org.osgi.service.component.propertytypes.ServiceRanking;
+import org.osgi.service.component.propertytypes.ServiceVendor;
 import org.osgi.service.http.context.ServletContextHelper;
-import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardContext;
 
-@Component(metatype = false, policy = ConfigurationPolicy.IGNORE)
-@Service(ServletContextHelper.class)
-@Properties({
-    @Property(name = Constants.SERVICE_DESCRIPTION, value = "Sling JcrRemoting Servlet"),
-    @Property(name = Constants.SERVICE_VENDOR, value = "The Apache Software Foundation"),
-    @Property(name = HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, value = AuthHttpContext.HTTP_CONTEXT_NAME),
-    @Property(name = HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, value = "/"),
-    @Property(name = Constants.SERVICE_RANKING, intValue = 5)
-})
+@Component(service = ServletContextHelper.class)
+@HttpWhiteboardContext(name = AuthHttpContext.HTTP_CONTEXT_NAME, path = "/")
+@ServiceDescription("Sling JcrRemoting Servlet")
+@ServiceVendor("The Apache Software Foundation")
+@ServiceRanking(5)
 public class AuthHttpContext extends ServletContextHelper {
 
     /**
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 04d1965..18617c8 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
@@ -18,7 +18,6 @@ package org.apache.sling.jcr.davex.impl.servlets;
 
 import java.util.Dictionary;
 import java.util.Hashtable;
-import java.util.Map;
 
 import javax.jcr.LoginException;
 import javax.jcr.Repository;
@@ -29,26 +28,28 @@ import javax.servlet.Servlet;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Properties;
-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.apache.sling.commons.osgi.OsgiUtil;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.osgi.service.component.propertytypes.ServiceDescription;
+import org.osgi.service.component.propertytypes.ServiceVendor;
 
 /**
  * DavEx WebDav servlet which acquires a Repository instance via the OSGi
@@ -56,46 +57,50 @@ import org.slf4j.LoggerFactory;
  *
  */
 @SuppressWarnings("serial")
-@Component(metatype = true, label = "%dav.name",
-           description = "%dav.description",
-           policy = ConfigurationPolicy.REQUIRE)
-@Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "Sling JcrRemoting Servlet"),
-    @Property(name = Constants.SERVICE_VENDOR, value = "The Apache Software Foundation") })
+@Component(configurationPolicy = ConfigurationPolicy.REQUIRE)
+@ServiceVendor(SlingDavExServlet.SERVICE_VENDOR)
+@ServiceDescription(SlingDavExServlet.SERVICE_DESCRIPTION)
+@Designate(ocd = SlingDavExServlet.Config.class)
 public class SlingDavExServlet extends JcrRemotingServlet {
 
+    protected static final String SERVICE_VENDOR = "The Apache Software Foundation";
+    protected static final String SERVICE_DESCRIPTION = "Sling JcrRemoting Servlet";
+
+    @SuppressWarnings("java:S100")
+    @ObjectClassDefinition(name = "%dav.name",  description = "%dav.description")
+    public @interface Config {
+
+        /**
+         * Name of the property to configure the location for the DavEx servlet
+         * registration. Default for the property is {@link #DEFAULT_DAV_ROOT}.
+         */
+        @AttributeDefinition(name = "%alias.name", description = "%alias.description")
+        String alias() default DEFAULT_DAV_ROOT;
+
+        /**
+         * Name of the property to configure whether absolute URIs ({@code true}) or
+         * absolute paths ({@code false}) are generated in responses. Default for
+         * the property is true.
+         */
+        @AttributeDefinition( name = "%dav.create-absolute-uri.name", description = "%dav.create-absolute-uri.description")
+        boolean dav_create$_$absolute$_$uri() default true;
+
+        /**
+         * defines the Protected handlers for the Jcr Remoting Servlet
+         */
+        @AttributeDefinition
+        String dav_protectedhandlers() default DEFAULT_PROTECTED_HANDLERS;
+    }
+
     /**
      * Default value for the DavEx servlet registration.
      */
     private static final String DEFAULT_DAV_ROOT = "/server";
-
-    /**
-     * Name of the property to configure the location for the DavEx servlet
-     * registration. Default for the property is {@link #DEFAULT_DAV_ROOT}.
-     */
-    @Property(value=DEFAULT_DAV_ROOT)
-    private static final String PROP_DAV_ROOT = "alias";
-
-    private static final boolean DEFAULT_CREATE_ABSOLUTE_URI = true;
-
     /**
-     * Name of the property to configure whether absolute URIs ({@code true}) or
-     * absolute paths ({@code false}) are generated in responses. Default for
-     * the property is {@link #DEFAULT_CREATE_ABSOLUTE_URI}.
-     */
-    @Property(boolValue=DEFAULT_CREATE_ABSOLUTE_URI)
-    private static final String PROP_CREATE_ABSOLUTE_URI = "dav.create-absolute-uri";
-
-    /**
-     * Default value for the configuration {@link #PROP_PROTECTED_HANDLERS}
+     * Default value for the configuration
      */
     private static final String DEFAULT_PROTECTED_HANDLERS = "org.apache.jackrabbit.server.remoting.davex.AclRemoveHandler";
 
-    /**
-     * defines the Protected handlers for the Jcr Remoting Servlet
-     */
-    @Property(value=DEFAULT_PROTECTED_HANDLERS)
-    private static final String PROP_PROTECTED_HANDLERS = "dav.protectedhandlers";
-
     /**
      * The name of the service property of the registered dummy service to cause
      * the path to the DavEx servlet to not be subject to forced authentication.
@@ -116,23 +121,25 @@ public class SlingDavExServlet extends JcrRemotingServlet {
     private ServiceRegistration davServlet;
 
     @Activate
-    protected void activate(final BundleContext bundleContext, final Map<String, ?> config) {
-        final String davRoot = OsgiUtil.toString(config.get(PROP_DAV_ROOT), DEFAULT_DAV_ROOT);
-        final boolean createAbsoluteUri = OsgiUtil.toBoolean(config.get(PROP_CREATE_ABSOLUTE_URI), DEFAULT_CREATE_ABSOLUTE_URI);
-        final String protectedHandlers = OsgiUtil.toString(config.get(PROP_PROTECTED_HANDLERS), DEFAULT_PROTECTED_HANDLERS);
+    protected void activate(final BundleContext bundleContext, Config config) {
+        final String davRoot = config.alias();
+        final boolean createAbsoluteUri = config.dav_create$_$absolute$_$uri();
+        final String protectedHandlers = config.dav_protectedhandlers();
 
         // prepare DavEx servlet config
-        final Dictionary<String, Object> initProps = new Hashtable<String, Object>();
+        final Dictionary<String, Object> initProps = new Hashtable<>();
+
         initProps.put(toInitParamProperty(INIT_PARAM_RESOURCE_PATH_PREFIX), davRoot);
         initProps.put(toInitParamProperty(INIT_PARAM_CREATE_ABSOLUTE_URI), Boolean.toString(createAbsoluteUri));
         initProps.put(toInitParamProperty(INIT_PARAM_CSRF_PROTECTION), CSRFUtil.DISABLED);
         initProps.put(toInitParamProperty(INIT_PARAM_PROTECTED_HANDLERS_CONFIG), protectedHandlers);
         initProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, davRoot.concat("/*"));
+        initProps.put(Constants.SERVICE_VENDOR, SERVICE_VENDOR);
+        initProps.put(Constants.SERVICE_DESCRIPTION, SERVICE_DESCRIPTION);
         initProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
             "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" + AuthHttpContext.HTTP_CONTEXT_NAME + ")");
-        initProps.put(Constants.SERVICE_VENDOR, config.get(Constants.SERVICE_VENDOR));
-        initProps.put(Constants.SERVICE_DESCRIPTION, config.get(Constants.SERVICE_DESCRIPTION));
-        initProps.put(PAR_AUTH_REQ, "-" + davRoot); // make sure this is not forcible authenticated !
+        initProps.put(PAR_AUTH_REQ, "-" + davRoot); // make sure this is not forcibly authenticated !
+
         this.davServlet = bundleContext.registerService(Servlet.class.getName(), this, initProps);
     }
 
diff --git a/src/main/resources/OSGI-INF/l10n/metatype.properties b/src/main/resources/OSGI-INF/l10n/org.apache.sling.jcr.davex.impl.servlets.SlingDavExServlet$Config.properties
similarity index 100%
rename from src/main/resources/OSGI-INF/l10n/metatype.properties
rename to src/main/resources/OSGI-INF/l10n/org.apache.sling.jcr.davex.impl.servlets.SlingDavExServlet$Config.properties
diff --git a/src/test/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServletTest.java b/src/test/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServletTest.java
new file mode 100644
index 0000000..2cf512d
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/davex/impl/servlets/SlingDavExServletTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.sling.jcr.davex.impl.servlets;
+
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.apache.sling.testing.mock.sling.MockJcrSlingRepository;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(MockitoJUnitRunner.class)
+public class SlingDavExServletTest {
+
+    @Rule
+    public final OsgiContext context = new OsgiContext();
+    private SlingDavExServlet slingDavExServlet;
+
+    @Before
+    public void setUp() {
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        context.registerInjectActivateService(new MockJcrSlingRepository());
+        slingDavExServlet = context.registerInjectActivateService(new SlingDavExServlet(), properties);
+    }
+
+    @Test
+    public void testIfServiceActive() {
+        assertNotNull(slingDavExServlet);
+        assertNotNull(slingDavExServlet.getRepository());
+        assertNotNull(slingDavExServlet.getSessionProvider());
+    }
+
+}
\ No newline at end of file