sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1657383 - in /sling/whiteboard/bdelacretaz/multisling2015/xxx: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/ms2015/ src/main/java/org/apache/sl...
Date Wed, 04 Feb 2015 19:22:02 GMT
Author: bdelacretaz
Date: Wed Feb  4 19:22:02 2015
New Revision: 1657383

URL: http://svn.apache.org/r1657383
Log:
SLING-4386 - tenant-specific script search paths work, very basic MultitenantServletResolver
for now

Added:
    sling/whiteboard/bdelacretaz/multisling2015/xxx/
    sling/whiteboard/bdelacretaz/multisling2015/xxx/pom.xml
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/ContentDrivenTenant.java
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/impl/
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/impl/ContentDrivenTenantAdapterFactory.java
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/impl/ContentDrivenTenantImpl.java
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/package-info.java
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/tenantresolver/
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/tenantresolver/impl/
    sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/tenantresolver/impl/ContentBasedTenant.java

Added: sling/whiteboard/bdelacretaz/multisling2015/xxx/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/multisling2015/xxx/pom.xml?rev=1657383&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/multisling2015/xxx/pom.xml (added)
+++ sling/whiteboard/bdelacretaz/multisling2015/xxx/pom.xml Wed Feb  4 19:22:02 2015
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>22</version>
+    </parent>
+    
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.ms2015.cdtenants</artifactId>
+    <version>0.1.1-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+    <name>Apache Sling MultiSling 2015 prototype - Content-Driven Tenants</name>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Private-Package>org.apache.sling.ms2015.*</Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+	    <dependency>
+			<groupId>biz.aQute</groupId>
+			<artifactId>bndlib</artifactId>
+			<version>1.50.0</version>
+			<scope>provided</scope>
+	    </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.api</artifactId>
+            <version>2.8.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
+            <version>2.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+        </dependency>
+    </dependencies>
+</project>

Added: sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/ContentDrivenTenant.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/ContentDrivenTenant.java?rev=1657383&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/ContentDrivenTenant.java
(added)
+++ sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/ContentDrivenTenant.java
Wed Feb  4 19:22:02 2015
@@ -0,0 +1,28 @@
+/*
+ * 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.ms2015.cdtenants;
+
+/** A content-based tenant, mostly used to define the script search
+ *  paths used to process requests for resources that belong to 
+ *  content-based tenants.
+ */
+public interface ContentDrivenTenant {
+    String getId();
+    String [] getSearchPath();
+}

Added: sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/impl/ContentDrivenTenantAdapterFactory.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/impl/ContentDrivenTenantAdapterFactory.java?rev=1657383&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/impl/ContentDrivenTenantAdapterFactory.java
(added)
+++ sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/impl/ContentDrivenTenantAdapterFactory.java
Wed Feb  4 19:22:02 2015
@@ -0,0 +1,113 @@
+/*
+ * 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.ms2015.cdtenants.impl;
+
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.adapter.AdapterFactory;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.ms2015.cdtenants.ContentDrivenTenant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Adapt a Resource found under our content root to a Tenant, based
+ *  on the content path.  
+ */
+@Component
+@Service(value=AdapterFactory.class)
+@Properties({
+    @Property(name="adaptables", 
+        value="org.apache.sling.api.resource.Resource", 
+        propertyPrivate=true),
+    @Property(name="adapters", 
+        value={"org.apache.sling.ms2015.cdtenants.ContentDrivenTenant"}, 
+        propertyPrivate=true),
+    @Property(name="adapter.condition", 
+        value="If the resource is inside our tenants content path under a sling:tenantRoot",
+        propertyPrivate=true)
+})
+public class ContentDrivenTenantAdapterFactory implements AdapterFactory {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    public static final String CDTENANT_CLASS = ContentDrivenTenant.class.getName();
+    public static final String DEFAULT_CONTENT_ROOT_PATH = "/content/T";
+    public static final String TENANT_ROOT_PROP = "sling:tenantRoot";
+    
+    @Property(value=DEFAULT_CONTENT_ROOT_PATH)
+    public static final String CONTENT_ROOT_PATH = "content.root.path";
+    private String contentRootPath;
+    
+    @Activate
+    protected void activate(final Map<String, Object> properties) {
+        contentRootPath = PropertiesUtil.toString(properties.get(CONTENT_ROOT_PATH), DEFAULT_CONTENT_ROOT_PATH);
+    }
+    
+    @SuppressWarnings("unchecked")
+    public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType>
type) {
+        if(type == ContentDrivenTenant.class && adaptable instanceof Resource) {
+            return (AdapterType)getTenant((Resource)adaptable);
+        }
+        return null;
+    }
+    
+    /** Return the Tenant that applies to r, null if not found */
+    private ContentDrivenTenant getTenant(Resource r) {
+        final String path = r.getPath();
+        ContentDrivenTenant result = null;
+        // TODO testing for the contentRootPath might not
+        // be needed anymore, as we just go up the tree to find a
+        // sling:tenantId
+        if(!path.startsWith(contentRootPath)) {
+            log.debug("Path {} does not start with {}, Resource ignored", path, contentRootPath);
+        }
+        
+        final String tenantPath = getTenantPath(r);
+        if(tenantPath != null) {
+            // TODO we might need a service user to access the tenant data 
+            result = new ContentDrivenTenantImpl(tenantPath, r.getResourceResolver());
+        }
+        
+        log.info("{} -> {}", r, result);
+        return result;
+    }
+    
+    /** Look for a sling:tenantId property in this resource
+     *  or its ancestors.
+     */
+    private String getTenantPath(Resource r) {
+        String result = null;
+        while(r != null) {
+            final ValueMap m = r.adaptTo(ValueMap.class);
+            if(m != null && m.containsKey(TENANT_ROOT_PROP)) {
+                result = r.getPath().substring(contentRootPath.length() + 1);
+                break;
+            }
+            r = r.getParent();
+        }
+        return result;
+    }
+}
\ No newline at end of file

Added: sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/impl/ContentDrivenTenantImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/impl/ContentDrivenTenantImpl.java?rev=1657383&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/impl/ContentDrivenTenantImpl.java
(added)
+++ sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/impl/ContentDrivenTenantImpl.java
Wed Feb  4 19:22:02 2015
@@ -0,0 +1,98 @@
+/*
+ * 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.ms2015.cdtenants.impl;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.ms2015.cdtenants.ContentDrivenTenant;
+
+/** Adapt a Resource found under our content root to a Tenant, based
+ *  on the content path.  
+ */
+public class ContentDrivenTenantImpl implements ContentDrivenTenant {
+
+    private final String id;
+    private final String [] searchPath;
+    
+    // TODO should be configurable
+    public static final String TENANTS_ROOT_PATH = "/tenants";
+    
+    public static final String SLING_TENANT = "sling:tenant";
+    public static final String SEARCH_PATH = "searchPath";
+    public static final String EXEC_PATH = "executionPath";
+    
+    public static final String TENANT_PATH_PROP = "sling.tenant.path";
+    public static final String TENANT_SEARCH_PATH_PROP = "sling.tenant.search.path";
+    public static final String TENANT_EXEC_PATH_PROP = "sling.tenant.execution.path";
+    
+    ContentDrivenTenantImpl(String id, ResourceResolver tenantResourceResolver) {
+        this.id = id;
+        
+        // Get this tenant's search path from under /tenants
+        // TODO should be cached
+        final String tenantPath = TENANTS_ROOT_PATH + "/" + id + "/" + SLING_TENANT;
+        String [] p = {};
+        final Resource r = tenantResourceResolver.resolve(tenantPath);
+        if(r != null) {
+            final ValueMap props = r.adaptTo(ValueMap.class);
+            if(props != null) {
+                p = normalizeSearchPath(props.get(SEARCH_PATH, String[].class));
+                
+            }
+        }
+        
+        this.searchPath = p;
+    }
+    
+    static String [] normalizeSearchPath(String [] path) {
+        for(int i=0 ; i < path.length; i++) {
+            if(!path[i].endsWith("/")) {
+                path[i] += "/";
+            }
+        }
+        return path;
+    }
+    
+    private void dumpPath(StringBuilder sb, String info, String [] path) {
+        sb.append(", ").append(info).append("=");
+        for(int i=0; i < path.length; i++) {
+            if(i > 0) {
+                sb.append(", ");
+            }
+            sb.append(path[i]);
+        }
+    }
+    
+    public String toString() {
+        final StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(", id=").append(id);
+        dumpPath(sb, "search path", searchPath);
+        return sb.toString();
+    }
+    
+    public String [] getSearchPath() {
+        return searchPath;
+    }
+    
+    public String getId() {
+        return id;
+    }
+}
\ No newline at end of file

Added: sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/package-info.java?rev=1657383&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/package-info.java
(added)
+++ sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/cdtenants/package-info.java
Wed Feb  4 19:22:02 2015
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+@Version("1.0")
+package org.apache.sling.ms2015.cdtenants;
+
+import aQute.bnd.annotation.Version;

Added: sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/tenantresolver/impl/ContentBasedTenant.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/multisling2015/xxx/src/main/java/org/apache/sling/ms2015/tenantresolver/impl/ContentBasedTenant.java?rev=1657383&view=auto
==============================================================================
    (empty)



Mime
View raw message