incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1558746 - in /sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl: CommonResourceResolverFactoryImpl.java ResourceAccessSecurityTracker.java ResourceResolverFactoryActivator.java
Date Thu, 16 Jan 2014 10:37:10 GMT
Author: cziegeler
Date: Thu Jan 16 10:37:10 2014
New Revision: 1558746

URL: http://svn.apache.org/r1558746
Log:
SLING-2698 - resource access security service for resource providers. Distinguish between
context application and provider

Modified:
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceAccessSecurityTracker.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java?rev=1558746&r1=1558745&r2=1558746&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
Thu Jan 16 10:37:10 2014
@@ -53,8 +53,6 @@ public class CommonResourceResolverFacto
     /** The activator */
     private final ResourceResolverFactoryActivator activator;
 
-    private ResourceAccessSecurityTracker resourceAccessSecurityTracker;
-
     public CommonResourceResolverFactoryImpl(final ResourceResolverFactoryActivator activator)
{
         this.activator = activator;
     }
@@ -102,7 +100,7 @@ public class CommonResourceResolverFacto
                     final boolean isAdmin)
     throws LoginException {
         // create context
-        final ResourceResolverContext ctx = new ResourceResolverContext(isAdmin, authenticationInfo,
resourceAccessSecurityTracker);
+        final ResourceResolverContext ctx = new ResourceResolverContext(isAdmin, authenticationInfo,
this.activator.getResourceAccessSecurityTracker());
 
         // login
         this.activator.getRootProviderEntry().loginToRequiredFactories(ctx);
@@ -130,9 +128,6 @@ public class CommonResourceResolverFacto
         } catch (final Exception e) {
             logger.error("activate: Cannot access repository, failed setting up Mapping Support",
e);
         }
-
-        // create and open service tracker for ResourceAccessSecurity
-        resourceAccessSecurityTracker = new ResourceAccessSecurityTracker(bundleContext);
     }
 
     /**
@@ -148,9 +143,6 @@ public class CommonResourceResolverFacto
             mapEntries.dispose();
             mapEntries = MapEntries.EMPTY;
         }
-
-        this.resourceAccessSecurityTracker.dispose();
-        this.resourceAccessSecurityTracker = null;
     }
 
     public ResourceDecoratorTracker getResourceDecoratorTracker() {
@@ -189,7 +181,7 @@ public class CommonResourceResolverFacto
      * get's the ServiceTracker of the ResourceAccessSecurity service
      */
     public ResourceAccessSecurityTracker getResourceAccessSecurityTracker () {
-        return resourceAccessSecurityTracker;
+        return this.activator.getResourceAccessSecurityTracker();
     }
 
     public ResourceResolver getServiceResourceResolver(

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceAccessSecurityTracker.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceAccessSecurityTracker.java?rev=1558746&r1=1558745&r2=1558746&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceAccessSecurityTracker.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceAccessSecurityTracker.java
Thu Jan 16 10:37:10 2014
@@ -18,32 +18,39 @@
  */
 package org.apache.sling.resourceresolver.impl;
 
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.ReferencePolicyOption;
+import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.api.security.ResourceAccessSecurity;
-import org.osgi.framework.BundleContext;
-import org.osgi.util.tracker.ServiceTracker;
 
 /**
  * This internal helper class keeps track of the resource access security services
  * and always returns the one with the highest service ranking.
  */
+@Component
+@Service(value=ResourceAccessSecurityTracker.class)
 public class ResourceAccessSecurityTracker {
 
-    private final ServiceTracker resourceAccessSecurityTracker;
-
-    public ResourceAccessSecurityTracker(final BundleContext bundleContext) {
-        resourceAccessSecurityTracker = new ServiceTracker(bundleContext, ResourceAccessSecurity.class.getName(),
null);
-        resourceAccessSecurityTracker.open();
-    }
-
-    public void dispose() {
-        this.resourceAccessSecurityTracker.close();
-    }
+    @Reference(policyOption=ReferencePolicyOption.GREEDY,
+               cardinality=ReferenceCardinality.OPTIONAL_UNARY,
+               policy=ReferencePolicy.DYNAMIC,
+               target="(" + ResourceAccessSecurity.CONTEXT + "=" + ResourceAccessSecurity.APPLICATION_CONTEXT
+ ")")
+    private ResourceAccessSecurity applicationResourceAccessSecurity;
+
+    @Reference(policyOption=ReferencePolicyOption.GREEDY,
+            cardinality=ReferenceCardinality.OPTIONAL_UNARY,
+            policy=ReferencePolicy.DYNAMIC,
+            target="(" + ResourceAccessSecurity.CONTEXT + "=" + ResourceAccessSecurity.PROVIDER_CONTEXT
+ ")")
+    private ResourceAccessSecurity providerResourceAccessSecurity;
 
     public ResourceAccessSecurity getApplicationResourceAccessSecurity() {
-        return (ResourceAccessSecurity) this.resourceAccessSecurityTracker.getService();
+        return this.applicationResourceAccessSecurity;
     }
 
     public ResourceAccessSecurity getProviderResourceAccessSecurity() {
-        return (ResourceAccessSecurity) this.resourceAccessSecurityTracker.getService();
+        return this.providerResourceAccessSecurity;
     }
 }

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java?rev=1558746&r1=1558745&r2=1558746&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
Thu Jan 16 10:37:10 2014
@@ -216,6 +216,9 @@ public class ResourceResolverFactoryActi
     @Reference
     private ServiceUserMapper serviceUserMapper;
 
+    @Reference
+    private ResourceAccessSecurityTracker resourceAccessSecurityTracker;
+
     /** ComponentContext */
     private volatile ComponentContext componentContext;
 
@@ -236,6 +239,10 @@ public class ResourceResolverFactoryActi
         return this.resourceDecoratorTracker;
     }
 
+    public ResourceAccessSecurityTracker getResourceAccessSecurityTracker() {
+        return this.resourceAccessSecurityTracker;
+    }
+
     public EventAdmin getEventAdmin() {
         return this.eventAdmin;
     }



Mime
View raw message