You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2013/04/22 13:37:20 UTC

svn commit: r1470460 - in /sling/trunk/contrib/extensions/tenant/src/main/java/org/apache/sling/tenant/internal: TenantAdapterFactory.java TenantProviderImpl.java

Author: cziegeler
Date: Mon Apr 22 11:37:20 2013
New Revision: 1470460

URL: http://svn.apache.org/r1470460
Log:
Implementation is mostly resource based

Modified:
    sling/trunk/contrib/extensions/tenant/src/main/java/org/apache/sling/tenant/internal/TenantAdapterFactory.java
    sling/trunk/contrib/extensions/tenant/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java

Modified: sling/trunk/contrib/extensions/tenant/src/main/java/org/apache/sling/tenant/internal/TenantAdapterFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/tenant/src/main/java/org/apache/sling/tenant/internal/TenantAdapterFactory.java?rev=1470460&r1=1470459&r2=1470460&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/tenant/src/main/java/org/apache/sling/tenant/internal/TenantAdapterFactory.java (original)
+++ sling/trunk/contrib/extensions/tenant/src/main/java/org/apache/sling/tenant/internal/TenantAdapterFactory.java Mon Apr 22 11:37:20 2013
@@ -40,7 +40,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * JCR based tenant adapter factory, that adapts <code>ResourceResolver</code>
+ * Resource based tenant adapter factory, that adapts <code>ResourceResolver</code>
  * and <code>Resource</code> to <code>Tenant</code>.
  *
  * It tries to resolve the tenant based on logged in user by looking at the user
@@ -72,7 +72,7 @@ class TenantAdapterFactory implements Ad
         }
 
 	    Dictionary<String, Object> props = new Hashtable<String, Object>();
-	    props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling JCR Tenant Adapter");
+	    props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Tenant Adapter");
 	    props.put(AdapterFactory.ADAPTER_CLASSES, new String[]{ TENANT_CLASS.getName() });
 	    props.put(AdapterFactory.ADAPTABLE_CLASSES, new String[] { RESOURCERESOLVER_CLASS
 	            .getName(), RESOURCE_CLASS.getName() });
@@ -113,20 +113,22 @@ class TenantAdapterFactory implements Ad
 
 	private <AdapterType> AdapterType getAdapter(Session session,
 			Class<AdapterType> type) {
-		String userID = session.getUserID();
+	    if ( session != null ) {
+    		String userID = session.getUserID();
 
-		JackrabbitSession jrSession = (JackrabbitSession) session;
-		try {
-			Authorizable authorizable = jrSession.getUserManager()
-					.getAuthorizable(userID);
-			String userHome = authorizable.getPath();
-
-			// tries to get tenant information from user home
-			// i.e. /home/users/tenant1/a/admin
-			return getAdapter(userHome, type);
-		} catch (Exception e) {
-			log.error("can not get user from session", e);
-		}
+    		JackrabbitSession jrSession = (JackrabbitSession) session;
+    		try {
+    			Authorizable authorizable = jrSession.getUserManager()
+    					.getAuthorizable(userID);
+    			String userHome = authorizable.getPath();
+
+    			// tries to get tenant information from user home
+    			// i.e. /home/users/tenant1/a/admin
+    			return getAdapter(userHome, type);
+    		} catch (Exception e) {
+    			log.error("can not get user from session", e);
+    		}
+	    }
 		log.debug("Unable to adapt to resource of type {}", type.getName());
 		return null;
 	}

Modified: sling/trunk/contrib/extensions/tenant/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/tenant/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java?rev=1470460&r1=1470459&r2=1470460&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/tenant/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java (original)
+++ sling/trunk/contrib/extensions/tenant/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java Mon Apr 22 11:37:20 2013
@@ -62,16 +62,16 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * JCR Tenant Provider implementation.
+ * Resource based Tenant Provider implementation.
  */
 @Component(
         metatype = true,
-        label = "Apache Sling JCR Tenant Provider",
+        label = "Apache Sling Tenant Provider",
         description = "Service responsible for providing Tenants",
         immediate = true)
 @Service
 @Properties(value = {
-    @Property(name = Constants.SERVICE_DESCRIPTION, value = "Apache Sling JCR Tenant Provider")
+    @Property(name = Constants.SERVICE_DESCRIPTION, value = "Apache Sling Tenant Provider")
 })
 @Reference(
         name = "tenantSetup",
@@ -86,9 +86,9 @@ public class TenantProviderImpl implemen
     /**
      * Root path for tenant
      */
-    private static final String JCR_TENANT_ROOT = "/etc/tenants";
+    private static final String RESOURCE_TENANT_ROOT = "/etc/tenants";
 
-    @Property(value = JCR_TENANT_ROOT, label = "Tenants Root Path", description = "Defines tenants root path")
+    @Property(value = RESOURCE_TENANT_ROOT, label = "Tenants Root Path", description = "Defines tenants root path")
     private static final String TENANT_ROOT = "tenant.root";
 
     private static final String[] DEFAULT_PATH_MATCHER = {};
@@ -103,7 +103,7 @@ public class TenantProviderImpl implemen
             description = "Defines tenants path matcher i.e. /content/sample/([^/]+)/*, used while resolving path to tenant")
     private static final String TENANT_PATH_MATCHER = "tenant.path.matcher";
 
-    private String tenantRootPath = JCR_TENANT_ROOT;
+    private String tenantRootPath = RESOURCE_TENANT_ROOT;
 
     @Reference
     private ResourceResolverFactory factory;
@@ -114,7 +114,7 @@ public class TenantProviderImpl implemen
 
     @Activate
     private void activate(final BundleContext bundleContext, final Map<String, Object> properties) {
-        this.tenantRootPath = PropertiesUtil.toString(properties.get(TENANT_ROOT), JCR_TENANT_ROOT);
+        this.tenantRootPath = PropertiesUtil.toString(properties.get(TENANT_ROOT), RESOURCE_TENANT_ROOT);
         this.adapterFactory = new TenantAdapterFactory(bundleContext, this, PropertiesUtil.toStringArray(properties.get(TENANT_PATH_MATCHER), DEFAULT_PATH_MATCHER));
         this.plugin = new WebConsolePlugin(bundleContext, this);
     }