sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1727818 - in /sling/trunk/bundles/resourceresolver/src: main/java/org/apache/sling/resourceresolver/impl/providers/stateful/ test/java/org/apache/sling/resourceresolver/impl/stateful/
Date Sun, 31 Jan 2016 14:11:25 GMT
Author: cziegeler
Date: Sun Jan 31 14:11:25 2016
New Revision: 1727818

URL: http://svn.apache.org/viewvc?rev=1727818&view=rev
Log:
Code cleanup, rename SecureResourceProvider, remove StatefulResourceProviderWrapper

Added:
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProviderDecorator.java
      - copied, changed from r1727817, sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProvider.java
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderDecoratorTest.java
      - copied, changed from r1727817, sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderTest.java
Removed:
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProvider.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/StatefulResourceProviderWrapper.java
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderTest.java
Modified:
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/AuthenticatedResourceProvider.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/CombinedResourceProvider.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/EmptyResourceProvider.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/ResourceProviderAuthenticator.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/StatefulResourceProvider.java

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/AuthenticatedResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/AuthenticatedResourceProvider.java?rev=1727818&r1=1727817&r2=1727818&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/AuthenticatedResourceProvider.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/AuthenticatedResourceProvider.java
Sun Jan 31 14:11:25 2016
@@ -215,7 +215,7 @@ public class AuthenticatedResourceProvid
     }
 
     @Override
-    public Resource create(String path, Map<String, Object> properties) throws PersistenceException
{
+    public Resource create(final ResourceResolver resolver, String path, Map<String, Object>
properties) throws PersistenceException {
         try {
             return rp.create(getContext(), path, properties);
         } catch (LoginException e) {
@@ -337,11 +337,6 @@ public class AuthenticatedResourceProvid
     }
 
     @Override
-    public ResourceResolver getResourceResolver() {
-        return resolver;
-    }
-
-    @Override
     public ResourceProvider<Object> getResourceProvider() {
         return rp;
     }

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/CombinedResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/CombinedResourceProvider.java?rev=1727818&r1=1727817&r2=1727818&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/CombinedResourceProvider.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/CombinedResourceProvider.java
Sun Jan 31 14:11:25 2016
@@ -303,7 +303,7 @@ public class CombinedResourceProvider {
         try {
             final StatefulResourceProvider provider = getBestMatchingModifiableProvider(path);
             if ( provider != null ) {
-                final Resource creationResultResource = provider.create(path, properties);
+                final Resource creationResultResource = provider.create(resolver, path, properties);
                 if (creationResultResource != null) {
                     return creationResultResource;
                 }

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/EmptyResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/EmptyResourceProvider.java?rev=1727818&r1=1727817&r2=1727818&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/EmptyResourceProvider.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/EmptyResourceProvider.java
Sun Jan 31 14:11:25 2016
@@ -33,11 +33,6 @@ public class EmptyResourceProvider imple
     public static final StatefulResourceProvider SINGLETON = new EmptyResourceProvider();
 
     @Override
-    public ResourceResolver getResourceResolver() {
-        return null;
-    }
-
-    @Override
     public void logout() {
     }
 
@@ -76,7 +71,7 @@ public class EmptyResourceProvider imple
     }
 
     @Override
-    public Resource create(String path, Map<String, Object> properties)
+    public Resource create(ResourceResolver resolver, String path, Map<String, Object>
properties)
             throws PersistenceException {
         return null;
     }

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/ResourceProviderAuthenticator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/ResourceProviderAuthenticator.java?rev=1727818&r1=1727817&r2=1727818&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/ResourceProviderAuthenticator.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/ResourceProviderAuthenticator.java
Sun Jan 31 14:11:25 2016
@@ -157,7 +157,7 @@ public class ResourceProviderAuthenticat
         StatefulResourceProvider authenticated;
         authenticated = new AuthenticatedResourceProvider(rp, handler.getInfo(), resolver,
authInfo, combinedProvider);
         if (handler.getInfo().getUseResourceAccessSecurity()) {
-            authenticated = new SecureResourceProvider(authenticated, securityTracker);
+            authenticated = new SecureResourceProviderDecorator(authenticated, securityTracker);
         }
         return authenticated;
     }

Copied: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProviderDecorator.java
(from r1727817, sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProvider.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProviderDecorator.java?p2=sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProviderDecorator.java&p1=sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProvider.java&r1=1727817&r2=1727818&rev=1727818&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProvider.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProviderDecorator.java
Sun Jan 31 14:11:25 2016
@@ -18,29 +18,36 @@
  */
 package org.apache.sling.resourceresolver.impl.providers.stateful;
 
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
 
+import org.apache.sling.api.resource.LoginException;
 import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.security.ResourceAccessSecurity;
 import org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker;
 import org.apache.sling.resourceresolver.impl.ResourceResolverImpl;
+import org.apache.sling.spi.resource.provider.ResolverContext;
+import org.apache.sling.spi.resource.provider.ResourceProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * This wrappers add the Sling security layer (see
+ * This wrapper adds the Sling security layer (see
  * {@link ResourceAccessSecurity}) to the underlying {@link ResourceProvider}.
  */
-public class SecureResourceProvider extends StatefulResourceProviderWrapper {
+public class SecureResourceProviderDecorator implements StatefulResourceProvider {
 
     private static final Logger logger = LoggerFactory.getLogger(ResourceResolverImpl.class);
 
+    private final StatefulResourceProvider rp;
+
     private final ResourceAccessSecurityTracker tracker;
 
-    public SecureResourceProvider(StatefulResourceProvider rp, ResourceAccessSecurityTracker
tracker) {
-        super(rp);
+    public SecureResourceProviderDecorator(final StatefulResourceProvider rp, final ResourceAccessSecurityTracker
tracker) {
+        this.rp = rp;
         if (tracker == null) {
             logger.warn("ResourceAccessSecurityTracker is null. Resource-level security will
be disabled.");
         }
@@ -48,14 +55,104 @@ public class SecureResourceProvider exte
     }
 
     @Override
-    public Resource create(final String path, Map<String, Object> properties) throws
PersistenceException {
+    public void logout() {
+        rp.logout();
+    }
+
+    @Override
+    public void refresh() {
+        rp.refresh();
+    }
+
+    @Override
+    public boolean isLive() {
+        return rp.isLive();
+    }
+
+    @Override
+    public Resource getParent(Resource child) {
+        return rp.getParent(child);
+    }
+
+    @Override
+    public Resource getResource(String path, Resource parent, Map<String, String> parameters,
boolean isResolve) {
+        return rp.getResource(path, parent, parameters, isResolve);
+    }
+
+    @Override
+    public Iterator<Resource> listChildren(Resource parent) {
+        return rp.listChildren(parent);
+    }
+
+    @Override
+    public Collection<String> getAttributeNames() {
+        return rp.getAttributeNames();
+    }
+
+    @Override
+    public Object getAttribute(String name) {
+        return rp.getAttribute(name);
+    }
+
+    @Override
+    public void revert() {
+        rp.revert();
+    }
+
+    @Override
+    public void commit() throws PersistenceException {
+        rp.commit();
+    }
+
+    @Override
+    public boolean hasChanges() {
+        return rp.hasChanges();
+    }
+
+    @Override
+    public String[] getSupportedLanguages() {
+        return rp.getSupportedLanguages();
+    }
+
+    @Override
+    public Iterator<Map<String, Object>> queryResources(String query, String
language) {
+        return rp.queryResources(query, language);
+    }
+
+    @Override
+    public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+        return rp.adaptTo(type);
+    }
+
+    @Override
+    public boolean copy(String srcAbsPath, String destAbsPath) throws PersistenceException
{
+        return rp.copy(srcAbsPath, destAbsPath);
+    }
+
+    @Override
+    public boolean move(String srcAbsPath, String destAbsPath) throws PersistenceException
{
+        return rp.move(srcAbsPath, destAbsPath);
+    }
+
+   @Override
+    public ResourceProvider<Object> getResourceProvider() {
+        return rp.getResourceProvider();
+    }
+
+    @Override
+    public ResolverContext<Object> getContext() throws LoginException {
+        return rp.getContext();
+    }
+
+    @Override
+    public Resource create(final ResourceResolver resolver, final String path, Map<String,
Object> properties) throws PersistenceException {
         if (isAllowed(new SecurityTest() {
             @Override
             public boolean isAllowed(ResourceAccessSecurity security) {
-                return security.canCreate(path, getResourceResolver());
+                return security.canCreate(path, resolver);
             }
         })) {
-            return rp.create(path, properties);
+            return rp.create(resolver, path, properties);
         } else {
             return null;
         }

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/StatefulResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/StatefulResourceProvider.java?rev=1727818&r1=1727817&r2=1727818&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/StatefulResourceProvider.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/stateful/StatefulResourceProvider.java
Sun Jan 31 14:11:25 2016
@@ -42,11 +42,6 @@ import org.apache.sling.spi.resource.pro
 public interface StatefulResourceProvider {
 
     /**
-     * Returns the resource resolver associated to this {@link StatefulResourceProvider}.
-     */
-    ResourceResolver getResourceResolver();
-
-    /**
      * @see ResourceProvider#logout(Object)
      */
     void logout();
@@ -93,7 +88,7 @@ public interface StatefulResourceProvide
     /**
      * @see ResourceProvider#create(org.apache.sling.spi.resource.provider.ResolveContext,
String, Map)
      */
-    Resource create(final String path, final Map<String, Object> properties) throws
PersistenceException;
+    Resource create(ResourceResolver resolver, String path, Map<String, Object> properties)
throws PersistenceException;
 
     /**
      * @see ResourceProvider#delete(org.apache.sling.spi.resource.provider.ResolveContext,
Resource)

Copied: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderDecoratorTest.java
(from r1727817, sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderTest.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderDecoratorTest.java?p2=sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderDecoratorTest.java&p1=sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderTest.java&r1=1727817&r2=1727818&rev=1727818&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderTest.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderDecoratorTest.java
Sun Jan 31 14:11:25 2016
@@ -35,17 +35,17 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.security.ResourceAccessSecurity;
 import org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker;
-import org.apache.sling.resourceresolver.impl.providers.stateful.SecureResourceProvider;
+import org.apache.sling.resourceresolver.impl.providers.stateful.SecureResourceProviderDecorator;
 import org.apache.sling.resourceresolver.impl.providers.stateful.StatefulResourceProvider;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 
-public class SecureResourceProviderTest {
-    
+public class SecureResourceProviderDecoratorTest {
+
     private ResourceAccessSecurity security;
     private ResourceResolver rr;
-    private SecureResourceProvider src;
+    private SecureResourceProviderDecorator src;
     private StatefulResourceProvider rp;
     private Resource first;
     private Resource second;
@@ -54,82 +54,80 @@ public class SecureResourceProviderTest
     public void prepare() throws PersistenceException {
 
         rr = mock(ResourceResolver.class);
-        
+
         security = mock(ResourceAccessSecurity.class);
         first = mock(Resource.class);
         second = mock(Resource.class);
-        
+
         when(security.getReadableResource(first)).thenReturn(first);
         when(security.getReadableResource(second)).thenReturn(null);
-        
+
         rp = mock(StatefulResourceProvider.class);
-        when(rp.create("/some/path", Collections.<String, Object> emptyMap())).thenReturn(mock(Resource.class));
+        when(rp.create(rr, "/some/path", Collections.<String, Object> emptyMap())).thenReturn(mock(Resource.class));
         when(rp.findResources("FIND ALL", "MockQueryLanguage")).thenReturn(Arrays.asList(first,
second).iterator());
-        
-        when(rp.getResourceResolver()).thenReturn(rr);
-        
+
         ResourceAccessSecurityTracker securityTracker = new ResourceAccessSecurityTracker()
{
             @Override
             public ResourceAccessSecurity getApplicationResourceAccessSecurity() {
                 return security;
             }
         };
-        
-        src = new SecureResourceProvider(rp, securityTracker);
-                
+
+        src = new SecureResourceProviderDecorator(rp, securityTracker);
+
     }
 
     @Test
     public void create_success() throws PersistenceException {
-        
+
         when(security.canCreate("/some/path", rr)).thenReturn(true);
-        
-        assertNotNull("expected resource to be created", src.create("/some/path", Collections.<String,
Object> emptyMap()));
+
+        assertNotNull("expected resource to be created", src.create(rr, "/some/path", Collections.<String,
Object> emptyMap()));
     }
-    
+
     @Test
     public void create_failure() throws PersistenceException {
-        
+
         when(security.canCreate("/some/path", rr)).thenReturn(false);
-        
-        assertNull("expected resource to not be created", src.create("/some/path", Collections.<String,
Object> emptyMap()));
+
+        assertNull("expected resource to not be created", src.create(rr, "/some/path", Collections.<String,
Object> emptyMap()));
     }
-    
+
     @Test
     public void delete_success() throws PersistenceException {
-        
+
         Resource toDelete = mock(Resource.class);
-        
+
         when(security.canDelete(toDelete)).thenReturn(true);
-        
+
         src.delete(toDelete);
-        
+
         verify(rp).delete(toDelete);
     }
-    
+
     @Test
     public void delete_failure() throws PersistenceException {
-        
+
         Resource toDelete = mock(Resource.class);
-        
+
         when(security.canDelete(toDelete)).thenReturn(false);
-        
+
         src.delete(toDelete);
-        
+
         Mockito.verifyZeroInteractions(rp);
     }
-    
+
     @Test
     public void find() {
-        
+
         Iterator<Resource> resources = src.findResources("FIND ALL", "MockQueryLanguage");
-        
+
         assertThat("resources should contain at least one item", resources.hasNext(), equalTo(true));
-        
+
         Resource resource = resources.next();
-        
+
         assertThat("unexpected resource found", resource, equalTo(first));
-        
+
         assertThat("resources should exactly at least one item", resources.hasNext(), equalTo(false));
     }
 }



Mime
View raw message