sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-tenant] 14/44: Implementation is mostly resource based
Date Wed, 18 Oct 2017 23:25:55 GMT
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-tenant.git

commit 48183e033629cfb0f57674caa7d74cbb96035383
Author: Carsten Ziegeler <cziegeler@apache.org>
AuthorDate: Mon Apr 22 11:37:20 2013 +0000

    Implementation is mostly resource based
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1470460 13f79535-47bb-0310-9956-ffa450edef68
---
 .../tenant/internal/TenantAdapterFactory.java      | 34 ++++++++++++----------
 .../sling/tenant/internal/TenantProviderImpl.java  | 14 ++++-----
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/src/main/java/org/apache/sling/tenant/internal/TenantAdapterFactory.java b/src/main/java/org/apache/sling/tenant/internal/TenantAdapterFactory.java
index 691f956..3494615 100644
--- a/src/main/java/org/apache/sling/tenant/internal/TenantAdapterFactory.java
+++ b/src/main/java/org/apache/sling/tenant/internal/TenantAdapterFactory.java
@@ -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 AdapterFactory {
         }
 
 	    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 AdapterFactory {
 
 	private <AdapterType> AdapterType getAdapter(Session session,
 			Class<AdapterType> type) {
-		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);
-		}
+	    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);
+    		}
+	    }
 		log.debug("Unable to adapt to resource of type {}", type.getName());
 		return null;
 	}
diff --git a/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java b/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java
index 669e054..e52c884 100644
--- a/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java
+++ b/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java
@@ -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 implements TenantProvider, TenantManager
{
     /**
      * 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 implements TenantProvider, TenantManager
{
             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 implements TenantProvider, TenantManager
{
 
     @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);
     }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message