Author: [email protected]
Date: Thu Nov 24 14:28:25 2011
New Revision: 1762

Log:
AMDATU-468 Refactored useradmin decorator to use whiteboard tenant services

Modified:
   
trunk/amdatu-core/tenantuseradmindecorator/src/main/java/org/amdatu/core/tenantuseradmindecorator/osgi/Activator.java
   
trunk/amdatu-core/tenantuseradmindecorator/src/main/java/org/amdatu/core/tenantuseradmindecorator/service/TenantUserAdminDecorator.java

Modified: 
trunk/amdatu-core/tenantuseradmindecorator/src/main/java/org/amdatu/core/tenantuseradmindecorator/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-core/tenantuseradmindecorator/src/main/java/org/amdatu/core/tenantuseradmindecorator/osgi/Activator.java
       (original)
+++ 
trunk/amdatu-core/tenantuseradmindecorator/src/main/java/org/amdatu/core/tenantuseradmindecorator/osgi/Activator.java
       Thu Nov 24 14:28:25 2011
@@ -15,19 +15,18 @@
  */
 package org.amdatu.core.tenantuseradmindecorator.osgi;
 
-import org.amdatu.core.tenant.TenantManagementService;
-import 
org.amdatu.core.tenantuseradmindecorator.service.TenantUserAdminDecorator;
-import org.apache.felix.dm.DependencyActivatorBase;
-import org.apache.felix.dm.DependencyManager;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.service.log.LogService;
-import org.osgi.service.useradmin.UserAdmin;
+import 
org.amdatu.core.tenantuseradmindecorator.service.TenantUserAdminDecorator;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.log.LogService;
+import org.osgi.service.useradmin.UserAdmin;
 
 /**
  * This class represents the OSGi activator for the Tenant UserAdmin decorator 
service
  * 
- * @author ivol
+ * @author <a href="mailto:[email protected]";>Amdatu Project 
Team</a>
  */
 public class Activator extends DependencyActivatorBase {
     public void init(BundleContext context, DependencyManager manager) throws 
Exception {
@@ -39,9 +38,6 @@
             createAspectService(UserAdmin.class, filter, 30, null)
             .setImplementation(TenantUserAdminDecorator.class)
             .add(createServiceDependency()
-                       .setService(TenantManagementService.class)
-                       .setRequired(true))
-            .add(createServiceDependency()
                        .setService(LogService.class)
                        .setRequired(false))
             );

Modified: 
trunk/amdatu-core/tenantuseradmindecorator/src/main/java/org/amdatu/core/tenantuseradmindecorator/service/TenantUserAdminDecorator.java
==============================================================================
--- 
trunk/amdatu-core/tenantuseradmindecorator/src/main/java/org/amdatu/core/tenantuseradmindecorator/service/TenantUserAdminDecorator.java
     (original)
+++ 
trunk/amdatu-core/tenantuseradmindecorator/src/main/java/org/amdatu/core/tenantuseradmindecorator/service/TenantUserAdminDecorator.java
     Thu Nov 24 14:28:25 2011
@@ -13,86 +13,86 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.amdatu.core.tenantuseradmindecorator.service;
-
-import java.util.Dictionary;
-
-import org.amdatu.core.tenant.Tenant;
-import org.amdatu.core.tenant.TenantException;
-import org.amdatu.core.tenant.TenantManagementService;
-import org.apache.felix.dm.Component;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.service.log.LogService;
-import org.osgi.service.useradmin.Authorization;
-import org.osgi.service.useradmin.Role;
-import org.osgi.service.useradmin.User;
-import org.osgi.service.useradmin.UserAdmin;
-
-/**
- * This class decorated UserAdmin services with tenant service properties. The 
UserAdmin service is tenant 
- * aware since we register a UserAdmin service for each tenant. But the 
UserAdmin implementation itself is 
- * not aware of that fact (Amdatu currently uses the Pax implementation which 
obviously is not tenant aware).
- * So the UserAdmin service does not set the Amdatu-specific tenant properties 
(tenant_id and tenant_name)
- * used by services to define the proper service dependencies on UserAdmin. 
This decorator service is an aspect
- * of UserAdmin appending those properties. 
- * Note that effectively, this aspect will double the amount of registered 
UserAdmin services; for each tenant
- * the 'normal' UserAdmin and one TenantUserAdminDecorator aspect. When using 
UserAdmin in a multi-tenant 
- * environment, you must ensure defining the proper service dependencies in 
order to get the proper UserAdmin
- * service injected.
- * 
- * @author ivol
- */
-public class TenantUserAdminDecorator implements UserAdmin {
-       // Service dependencies injected by the dependency manager
-    private volatile UserAdmin m_userAdmin;
-    private volatile TenantManagementService m_tenantManagementService;
-    private volatile LogService m_logService;
-    
-    // Private members
-    private Tenant m_tenant;
-
-    @SuppressWarnings("unchecked")
-    public void init(Component component) {
-        Dictionary properties = component.getServiceProperties();
-        String pid = (String) properties.get("service.pid");
-        try {
-            // The Pax UserAdmin service sets a service property "service.pid" 
which equals the
-            // syntax org.ops4j.pax.useradmin.[storage provider id]. Since we 
register the storage providers ourselves
-            // by convention we postfix the storage provider id by _[tenant 
id]. So we can retrieve the tenant id from
-            // this property.
-            String tenantId = pid.substring(pid.lastIndexOf("_") + 1);
-            m_tenant = m_tenantManagementService.getTenantById(tenantId);
-            properties.put(Tenant.TENANT_ID_SERVICEPROPERTY, m_tenant.getId());
-            properties.put(Tenant.TENANT_NAME_SERVICEPROPERTY, 
m_tenant.getName());
-            component.setServiceProperties(properties);
-            m_logService.log(LogService.LOG_INFO, "Decorated UserAdmin for pid 
'" + pid + "' with tenant '" + m_tenant.getId() + "'");
-        }
-        catch (TenantException e) {
-            m_logService.log(LogService.LOG_ERROR, "Could not decorate 
UserAdmin for pid '" + pid + "'");
-        }
-    }
-
-    public Role createRole(String name, int type) {
-        return m_userAdmin.createRole(name, type);
-    }
-
-    public Authorization getAuthorization(User user) {
-        return m_userAdmin.getAuthorization(user);
-    }
-
-    public Role getRole(String name) {
-        return m_userAdmin.getRole(name);
-    }
-
-    public Role[] getRoles(String filter) throws InvalidSyntaxException {
-        return m_userAdmin.getRoles(filter);
-    }
-
-    public User getUser(String key, String value) {
-        return m_userAdmin.getUser(key, value);
-    }
-
-    public boolean removeRole(String name) {
-        return m_userAdmin.removeRole(name);
-    }
-}
+package org.amdatu.core.tenantuseradmindecorator.service;
+
+import java.util.Dictionary;
+
+import org.amdatu.core.tenant.Tenant;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.Dependency;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.log.LogService;
+import org.osgi.service.useradmin.Authorization;
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
+import org.osgi.service.useradmin.UserAdmin;
+
+/**
+ * This class decorated UserAdmin services with tenant service properties. The 
UserAdmin service is tenant
+ * aware since we register a UserAdmin service for each tenant. But the 
UserAdmin implementation itself is
+ * not aware of that fact (Amdatu currently uses the Pax implementation which 
obviously is not tenant aware).
+ * So the UserAdmin service does not set the Amdatu-specific tenant properties 
(tenant_id and tenant_name)
+ * used by services to define the proper service dependencies on UserAdmin. 
This decorator service is an aspect
+ * of UserAdmin appending those properties.
+ * Note that effectively, this aspect will double the amount of registered 
UserAdmin services; for each tenant
+ * the 'normal' UserAdmin and one TenantUserAdminDecorator aspect. When using 
UserAdmin in a multi-tenant
+ * environment, you must ensure defining the proper service dependencies in 
order to get the proper UserAdmin
+ * service injected.
+ * 
+ * @author <a href="mailto:[email protected]";>Amdatu Project 
Team</a>
+ */
+public class TenantUserAdminDecorator implements UserAdmin {
+    // Service dependencies injected by the dependency manager
+    private volatile DependencyManager m_dependencyManager;
+    private volatile Component m_component;
+    private volatile UserAdmin m_userAdmin;
+    private volatile LogService m_logService;
+
+    private volatile Tenant m_tenant;
+
+    @SuppressWarnings("rawtypes")
+    public void init(Component component) {
+        Dictionary/* <String, Object> */properties = 
component.getServiceProperties();
+        String pid = (String) properties.get("service.pid");
+        String tenantId = pid.substring(pid.lastIndexOf("_") + 1);
+
+        Dependency tenantDep = m_dependencyManager.createServiceDependency()
+            .setService(Tenant.class, "(" + Tenant.TENANT_ID_SERVICEPROPERTY + 
"=" + tenantId + ")")
+            .setRequired(true);
+        component.add(tenantDep);
+    }
+
+    @SuppressWarnings("rawtypes")
+    public void start() {
+        m_logService.log(LogService.LOG_DEBUG, "Starting useradmin decorator 
for tenant " + m_tenant.getId());
+        Dictionary/* <String, Object> */properties = 
m_component.getServiceProperties();
+        properties.put(Tenant.TENANT_ID_SERVICEPROPERTY, m_tenant.getId());
+        properties.put(Tenant.TENANT_NAME_SERVICEPROPERTY, m_tenant.getName());
+        m_component.setServiceProperties(properties);
+    }
+
+    public Role createRole(String name, int type) {
+        return m_userAdmin.createRole(name, type);
+    }
+
+    public Authorization getAuthorization(User user) {
+        return m_userAdmin.getAuthorization(user);
+    }
+
+    public Role getRole(String name) {
+        return m_userAdmin.getRole(name);
+    }
+
+    public Role[] getRoles(String filter) throws InvalidSyntaxException {
+        return m_userAdmin.getRoles(filter);
+    }
+
+    public User getUser(String key, String value) {
+        return m_userAdmin.getUser(key, value);
+    }
+
+    public boolean removeRole(String name) {
+        return m_userAdmin.removeRole(name);
+    }
+}
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to