incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1510413 [2/2] - in /sling/trunk/bundles: api/ api/src/main/java/org/apache/sling/api/resource/ extensions/serviceusermapper/ extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/ extensions/serviceusermapper/src/m...
Date Mon, 05 Aug 2013 10:08:51 GMT
Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java?rev=1510413&r1=1510412&r2=1510413&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java
Mon Aug  5 10:08:50 2013
@@ -47,8 +47,13 @@ import org.apache.sling.commons.osgi.Pro
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.resource.JcrResourceConstants;
 import org.apache.sling.jcr.resource.internal.JcrResourceListener;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * The <code>JcrResourceProviderFactory</code> creates
@@ -65,20 +70,39 @@ import org.osgi.service.component.Compon
 })
 public class JcrResourceProviderFactory implements ResourceProviderFactory {
 
+    /** default log */
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private static final String REPOSITORY_REFERNENCE_NAME = "repository";
+
     /** The dynamic class loader */
     @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY, policy = ReferencePolicy.DYNAMIC)
     private DynamicClassLoaderManager dynamicClassLoaderManager;
 
-    @Reference
+    @Reference(name = REPOSITORY_REFERNENCE_NAME, referenceInterface = SlingRepository.class)
+    private ServiceReference repositoryReference;
+
     private SlingRepository repository;
 
     /** The jcr resource listner. */
     private JcrResourceListener listener;
 
     @Activate
-    protected void activate(final ComponentContext context)
-    throws RepositoryException {
+    protected void activate(final ComponentContext context) throws RepositoryException {
+
+        SlingRepository repository = (SlingRepository) context.locateService(REPOSITORY_REFERNENCE_NAME,
+            this.repositoryReference);
+        if (repository == null) {
+            // concurrent unregistration of SlingRepository service
+            // don't care, this component is going to be deactivated
+            // so we just stop working
+            log.warn("activate: Activation failed because SlingRepository may have been unregistered
concurrently");
+            return;
+        }
+
         final String root = PropertiesUtil.toString(context.getProperties().get(ResourceProvider.ROOTS),
"/");
+
+        this.repository = repository;
         this.listener = new JcrResourceListener(root, null, this.repository, context.getBundleContext());
     }
 
@@ -99,6 +123,20 @@ public class JcrResourceProviderFactory 
         return null;
     }
 
+    @SuppressWarnings("unused")
+    private void bindRepository(final ServiceReference ref) {
+        this.repositoryReference = ref;
+        this.repository = null; // make sure ...
+    }
+
+    @SuppressWarnings("unused")
+    private void unbindRepository(final ServiceReference ref) {
+        if (this.repositoryReference == ref) {
+            this.repositoryReference = null;
+            this.repository = null; // make sure ...
+        }
+    }
+
     /**
      * @see org.apache.sling.api.resource.ResourceProviderFactory#getResourceProvider(java.util.Map)
      */
@@ -126,12 +164,14 @@ public class JcrResourceProviderFactory 
         // by default any session used by the resource resolver returned is
         // closed when the resource resolver is closed
         boolean logoutSession = true;
+        RepositoryHolder holder = new RepositoryHolder();
 
         // derive the session to be used
         Session session;
         try {
             final String workspace = getWorkspace(authenticationInfo);
             if (isAdmin) {
+
                 // requested admin session to any workspace (or default)
                 session = repository.loginAdministrative(workspace);
 
@@ -139,11 +179,49 @@ public class JcrResourceProviderFactory 
 
                 session = getSession(authenticationInfo);
                 if (session == null) {
-                    // requested non-admin session to any workspace (or default)
-                    final Credentials credentials = getCredentials(authenticationInfo);
-                    session = repository.login(credentials, workspace);
+
+                    final Object serviceBundleObject = authenticationInfo.get(SERVICE_BUNDLE);
+                    if (serviceBundleObject instanceof Bundle) {
+
+                        final String subServiceName = (authenticationInfo.get(ResourceResolverFactory.SUBSERVICE)
instanceof String)
+                                ? (String) authenticationInfo.get(ResourceResolverFactory.SUBSERVICE)
+                                : null;
+
+                                final BundleContext bc = ((Bundle) serviceBundleObject).getBundleContext();
+
+                        final SlingRepository repo = (SlingRepository) bc.getService(repositoryReference);
+                        if (repo == null) {
+                            log.warn(
+                                "getResourceProviderInternal: Cannot login service because
cannot get SlingRepository on behalf of bundle {} ({})",
+                                bc.getBundle().getSymbolicName(), bc.getBundle().getBundleId());
+                            throw new LoginException(); // TODO: correct ??
+                        }
+
+                        try {
+                            session = repo.loginService(subServiceName, workspace);
+                            holder.setRepositoryReference(bc, repositoryReference);
+                            holder.setSession(session);
+                        } finally {
+                            // unget the repository if the service cannot
+                            // login to it, otherwise the repository service
+                            // is let go off when the resource resolver is
+                            // closed and the session logged out
+                            if (session == null) {
+                                bc.ungetService(repositoryReference);
+                            }
+                        }
+
+                    } else {
+
+                        // requested non-admin session to any workspace (or
+                        // default)
+                        final Credentials credentials = getCredentials(authenticationInfo);
+                        session = repository.login(credentials, workspace);
+
+                    }
 
                 } else if (workspace != null) {
+
                     // session provided by map; but requested a different
                     // workspace impersonate can only change the user not switch
                     // the workspace as a workaround we login to the requested
@@ -166,6 +244,7 @@ public class JcrResourceProviderFactory 
                     }
 
                 } else {
+
                     // session provided; no special workspace; just make sure
                     // the session is not logged out when the resolver is closed
                     logoutSession = false;
@@ -177,7 +256,11 @@ public class JcrResourceProviderFactory 
 
         session = handleImpersonation(session, authenticationInfo, logoutSession);
 
-        return new JcrResourceProvider(session, this.getDynamicClassLoader(), logoutSession);
+        if (logoutSession) {
+            holder.setSession(session);
+        }
+
+        return new JcrResourceProvider(session, this.getDynamicClassLoader(), holder);
     }
 
     /**

Propchange: sling/trunk/bundles/resourceresolver/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Aug  5 10:08:50 2013
@@ -0,0 +1 @@
+/sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver:1458693-1499675

Modified: sling/trunk/bundles/resourceresolver/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/pom.xml?rev=1510413&r1=1510412&r2=1510413&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/pom.xml (original)
+++ sling/trunk/bundles/resourceresolver/pom.xml Mon Aug  5 10:08:50 2013
@@ -119,6 +119,11 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.serviceusermapper</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>

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=1510413&r1=1510412&r2=1510413&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
Mon Aug  5 10:08:50 2013
@@ -45,8 +45,11 @@ import org.apache.sling.resourceresolver
 import org.apache.sling.resourceresolver.impl.mapping.MapEntries;
 import org.apache.sling.resourceresolver.impl.mapping.Mapping;
 import org.apache.sling.resourceresolver.impl.tree.RootResourceProviderEntry;
+import org.apache.sling.serviceusermapping.ServiceUserMapper;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.event.EventAdmin;
@@ -76,10 +79,6 @@ import org.osgi.service.event.EventAdmin
 public class ResourceResolverFactoryActivator {
 
     private static final class FactoryRegistration {
-
-        /** Registered resource resolver factory. */
-        public volatile ResourceResolverFactoryImpl factory;
-
         /** Registration .*/
         public volatile ServiceRegistration factoryRegistration;
     }
@@ -159,6 +158,10 @@ public class ResourceResolverFactoryActi
     @Reference
     EventAdmin eventAdmin;
 
+    /** Service User Mapper */
+    @Reference
+    private ServiceUserMapper serviceUserMapper;
+
     /** ComponentContext */
     private volatile ComponentContext componentContext;
 
@@ -324,9 +327,6 @@ public class ResourceResolverFactoryActi
             if ( local.factoryRegistration != null ) {
                 local.factoryRegistration.unregister();
             }
-            if ( local.factory != null ) {
-                local.factory.deactivate();
-            }
         }
     }
 
@@ -334,23 +334,38 @@ public class ResourceResolverFactoryActi
      * Try to register the factory.
      */
     private void registerFactory(final ComponentContext localContext) {
-        FactoryRegistration local = null;
-        synchronized ( this ) {
-            if ( this.factoryRegistration == null ) {
+        final FactoryRegistration local;
+        synchronized (this) {
+            if (this.factoryRegistration == null) {
                 this.factoryRegistration = new FactoryRegistration();
                 local = this.factoryRegistration;
+            } else {
+                local = null;
             }
         }
+
         if ( local != null ) {
             // activate and register factory
-            local.factory = new ResourceResolverFactoryImpl(this);
-            local.factory.activate(localContext.getBundleContext());
+
             final Dictionary<String, Object> serviceProps = new Hashtable<String,
Object>();
             serviceProps.put(Constants.SERVICE_VENDOR, localContext.getProperties().get(Constants.SERVICE_VENDOR));
             serviceProps.put(Constants.SERVICE_DESCRIPTION, localContext.getProperties().get(Constants.SERVICE_DESCRIPTION));
 
-            local.factoryRegistration = localContext.getBundleContext().registerService(ResourceResolverFactory.class.getName(),
-                    local.factory, serviceProps);
+            local.factoryRegistration = localContext.getBundleContext().registerService(
+                ResourceResolverFactory.class.getName(), new ServiceFactory() {
+                    public Object getService(Bundle bundle, ServiceRegistration registration)
{
+                        final ResourceResolverFactoryImpl r = new ResourceResolverFactoryImpl(
+                            ResourceResolverFactoryActivator.this, bundle,
+                            ResourceResolverFactoryActivator.this.serviceUserMapper);
+                        r.activate(localContext.getBundleContext());
+                        return r;
+                    }
+
+                    public void ungetService(Bundle bundle, ServiceRegistration registration,
Object service) {
+                        ((ResourceResolverFactoryImpl) service).deactivate();
+                    }
+                }, serviceProps);
+
             // check if an unregister happened in between
             boolean doUnregister = false;
             synchronized ( this ) {

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java?rev=1510413&r1=1510412&r2=1510413&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java
Mon Aug  5 10:08:50 2013
@@ -18,10 +18,12 @@
  */
 package org.apache.sling.resourceresolver.impl;
 
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.collections.BidiMap;
 import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.ResourceProviderFactory;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.api.security.ResourceAccessSecurity;
@@ -32,6 +34,8 @@ import org.apache.sling.resourceresolver
 import org.apache.sling.resourceresolver.impl.mapping.MapEntries;
 import org.apache.sling.resourceresolver.impl.mapping.Mapping;
 import org.apache.sling.resourceresolver.impl.tree.RootResourceProviderEntry;
+import org.apache.sling.serviceusermapping.ServiceUserMapper;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
@@ -57,26 +61,72 @@ public class ResourceResolverFactoryImpl
 
     /** The activator */
     private final ResourceResolverFactoryActivator activator;
-    
+
     private ServiceTracker resourceAccessSecurityTracker;
 
-    public ResourceResolverFactoryImpl(final ResourceResolverFactoryActivator activator)
{
+    private final ServiceUserMapper serviceUserMapper;
+
+    private final Bundle usingBundle;
+
+    public ResourceResolverFactoryImpl(final ResourceResolverFactoryActivator activator,
final Bundle usingBundle,
+            final ServiceUserMapper serviceUserMapper) {
         this.activator = activator;
+        this.serviceUserMapper = serviceUserMapper;
+        this.usingBundle = usingBundle;
     }
 
     // ---------- Resource Resolver Factory ------------------------------------
 
-    /**
-     * @see org.apache.sling.api.resource.ResourceResolverFactory#getAdministrativeResourceResolver(java.util.Map)
-     */
+    public ResourceResolver getServiceResourceResolver(Map<String, Object> authenticationInfo)
throws LoginException {
+
+        // clean authenticaiton from password and get service info
+        final String subServiceName;
+        if (authenticationInfo != null) {
+            authenticationInfo.remove(PASSWORD);
+            final Object info = authenticationInfo.get(SUBSERVICE);
+            subServiceName = (info instanceof String) ? (String) info : null;
+        } else {
+            authenticationInfo = new HashMap<String, Object>();
+            subServiceName = null;
+        }
+
+        // Ensure a mapped user name: If no user is defined for a bundle
+        // acting as a service, the user may be null. We can decide whether
+        // this should yield guest access or no access at all. For now
+        // no access is granted if there is no service user defined for
+        // the bundle.
+        final String userName = this.serviceUserMapper.getServiceUserID(this.usingBundle,
subServiceName);
+        if (userName == null) {
+            throw new LoginException("Cannot derive user name for service "
+                + this.serviceUserMapper.getServiceID(this.usingBundle, subServiceName));
+        }
+
+        // ensure proper user name and service bundle
+        authenticationInfo.put(ResourceResolverFactory.USER, userName);
+        authenticationInfo.put(ResourceProviderFactory.SERVICE_BUNDLE, this.usingBundle);
+
+        return getResourceResolverInternal(authenticationInfo, false);
+    }
+
     public ResourceResolver getAdministrativeResourceResolver(final Map<String, Object>
authenticationInfo) throws LoginException {
+
+        // make sure there is no leaking of service bundle and info props
+        if (authenticationInfo != null) {
+            authenticationInfo.remove(ResourceProviderFactory.SERVICE_BUNDLE);
+            authenticationInfo.remove(SUBSERVICE);
+        }
+
         return getResourceResolverInternal(authenticationInfo, true);
     }
 
-    /**
-     * @see org.apache.sling.api.resource.ResourceResolverFactory#getResourceResolver(java.util.Map)
-     */
     public ResourceResolver getResourceResolver(final Map<String, Object> authenticationInfo)
throws LoginException {
+
+        // make sure there is no leaking of service bundle and info props
+        if (authenticationInfo != null) {
+            authenticationInfo.remove(ResourceProviderFactory.SERVICE_BUNDLE);
+            authenticationInfo.remove(SUBSERVICE);
+        }
+
         return getResourceResolverInternal(authenticationInfo, false);
     }
 
@@ -121,7 +171,7 @@ public class ResourceResolverFactoryImpl
         } 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 ServiceTracker(bundleContext, ResourceAccessSecurity.class.getName(),
null);
         resourceAccessSecurityTracker.open();
@@ -175,11 +225,11 @@ public class ResourceResolverFactoryImpl
     public int getDefaultVanityPathRedirectStatus() {
         return this.activator.getDefaultVanityPathRedirectStatus();
     }
-    
+
     /**
      * get's the ServiceTracker of the ResourceAccessSecurity service
      */
-    
+
     public ServiceTracker getResourceAccessSecurityTracker () {
         return resourceAccessSecurityTracker;
     }

Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java?rev=1510413&r1=1510412&r2=1510413&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
Mon Aug  5 10:08:50 2013
@@ -44,8 +44,10 @@ import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceFactory;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.event.EventAdmin;
 
@@ -73,6 +75,12 @@ public class MockedResourceResolverImplT
     @Mock
     private BundleContext bundleContext;
 
+    @Mock
+    private Bundle usingBundle;
+
+    @Mock
+    private BundleContext usingBundleContext;
+
     private Map<String, Object> services = new HashMap<String, Object>();
 
     private Map<String, Object> serviceProperties = new HashMap<String, Object>();
@@ -122,15 +130,15 @@ public class MockedResourceResolverImplT
         activator.eventAdmin = eventAdmin;
 
         activator.bindResourceProvider(resourceProvider,
-            buildResourceProviderProperties("org.apache.sling.resourceresolver.impl.DummyTestProvider",

-                10L, 
+            buildResourceProviderProperties("org.apache.sling.resourceresolver.impl.DummyTestProvider",
+                10L,
                 new String[] { "/single" }));
-        
+
         // setup mapping resources at /etc/map to exercise vanity etc.
         // hmm, can't provide the resolver since its not up and ready.
         // mapping almost certainly work properly until this can be setup correctly.
         Resource etcMapResource = buildMappingResource("/etc/map", mappingResourceProvider,
null);
-        
+
         activator.bindResourceProvider(mappingResourceProvider,
             buildResourceProviderProperties("org.apache.sling.resourceresolver.impl.MapProvider",
                 11L,
@@ -148,7 +156,7 @@ public class MockedResourceResolverImplT
         Mockito.when(
             resourceProviderFactory.getAdministrativeResourceProvider(Mockito.anyMap())).thenReturn(
             factoryAdministrativeResourceProvider);
-        
+
         activator.bindResourceProviderFactory(resourceProviderFactory,
             buildResourceProviderProperties("org.apache.sling.resourceresolver.impl.DummyTestProviderFactory",
                 12L,
@@ -162,6 +170,10 @@ public class MockedResourceResolverImplT
         // activate the components.
         activator.activate(componentContext);
 
+        // configure using Bundle
+        Mockito.when(usingBundle.getBundleContext()).thenReturn(usingBundleContext);
+        Mockito.when(usingBundleContext.getBundle()).thenReturn(usingBundle);
+
         // extract any services that were registered into a map.
         ArgumentCaptor<String> classesCaptor = ArgumentCaptor.forClass(String.class);
         ArgumentCaptor<Object> serviceCaptor = ArgumentCaptor.forClass(Object.class);
@@ -182,24 +194,27 @@ public class MockedResourceResolverImplT
         }
         // verify that a ResourceResolverFactoryImpl was created and registered.
         Assert.assertNotNull(services.get(ResourceResolverFactory.class.getName()));
-        ResourceResolverFactory rrf = (ResourceResolverFactory) services.get(ResourceResolverFactory.class.getName());
+        Object rrf = services.get(ResourceResolverFactory.class.getName());
+        if (rrf instanceof ServiceFactory) {
+            rrf = ((ServiceFactory) rrf).getService(usingBundle, null);
+        }
         Assert.assertTrue(rrf instanceof ResourceResolverFactoryImpl);
         resourceResolverFactory = (ResourceResolverFactoryImpl) rrf;
     }
-    
+
     private Resource buildMappingResource(String path,
             ResourceProvider provider, ResourceResolver resourceResolver) {
         List<Resource> localHostAnyList = new ArrayList<Resource>();
         localHostAnyList.add(buildResource(path+"/http/example.com.80/cgi-bin", EMPTY_RESOURCE_LIST,
resourceResolver, provider, "sling:internalRedirect", "/scripts" ));
         localHostAnyList.add(buildResource(path+"/http/example.com.80/gateway", EMPTY_RESOURCE_LIST,
resourceResolver, provider,"sling:internalRedirect", "http://gbiv.com"));
         localHostAnyList.add(buildResource(path+"/http/example.com.80/stories", EMPTY_RESOURCE_LIST,
resourceResolver, provider,"sling:internalRedirect", "/anecdotes/$1"));
-        
+
         List<Resource> mappingChildren = new ArrayList<Resource>();
         mappingChildren.add(buildResource(path+"/http/example.com.80", EMPTY_RESOURCE_LIST,
resourceResolver, provider,"sling:redirect", "http://www.example.com/"));
         mappingChildren.add(buildResource(path+"/http/www.example.com.80", EMPTY_RESOURCE_LIST,
resourceResolver, provider,"sling:internalRedirect", "/example"));
         mappingChildren.add(buildResource(path+"/http/any_example.com.80", EMPTY_RESOURCE_LIST,
resourceResolver, provider,"sling:match", ".+\\.example\\.com\\.80", "sling:redirect", "http://www.example.com/"));
         mappingChildren.add(buildResource(path+"/http/localhost_any", localHostAnyList, resourceResolver,
provider,"sling:match", "localhost\\.\\d*", "sling:internalRedirect", "/content"));
-        
+
         Resource etcMapResource = buildResource(path+"/http", mappingChildren);
         Mockito.when(provider.getResource(Mockito.any(ResourceResolver.class), Mockito.eq(path))).thenReturn(etcMapResource);
         return etcMapResource;
@@ -265,10 +280,10 @@ public class MockedResourceResolverImplT
             Mockito.when(provider.listChildren(resource)).thenReturn(children.iterator());
             if ( resourceResolver != null) {
                 Mockito.when(provider.getResource(Mockito.eq(resourceResolver), Mockito.eq(fullpath))).thenReturn(resource);
-                Mockito.when(provider.getResource(Mockito.eq(resourceResolver), Mockito.any(HttpServletRequest.class),
Mockito.eq(fullpath))).thenReturn(resource);                
+                Mockito.when(provider.getResource(Mockito.eq(resourceResolver), Mockito.any(HttpServletRequest.class),
Mockito.eq(fullpath))).thenReturn(resource);
             } else {
                 Mockito.when(provider.getResource(Mockito.any(ResourceResolver.class), Mockito.eq(fullpath))).thenReturn(resource);
-                Mockito.when(provider.getResource(Mockito.any(ResourceResolver.class), Mockito.any(HttpServletRequest.class),
Mockito.eq(fullpath))).thenReturn(resource);                
+                Mockito.when(provider.getResource(Mockito.any(ResourceResolver.class), Mockito.any(HttpServletRequest.class),
Mockito.eq(fullpath))).thenReturn(resource);
             }
         }
         if ( properties != null ) {
@@ -279,10 +294,10 @@ public class MockedResourceResolverImplT
             }
             Mockito.when(resource.adaptTo(Mockito.eq(ValueMap.class))).thenReturn(vm);
         }
-        
+
         return resource;
     }
-        
+
 
     /**
      * extract the name from a path.
@@ -408,7 +423,7 @@ public class MockedResourceResolverImplT
         Resource resource = resourceResolver.getResource("/single/test.with/extra.dots/inthepath");
         Assert.assertEquals(singleResource, resource);
     }
-    
+
 
     /**
      * Test search paths
@@ -439,7 +454,7 @@ public class MockedResourceResolverImplT
         Resource resource = resourceResolver.getResource("/factory/test");
         Assert.assertEquals(factoryResource, resource);
     }
-    
+
 
     /**
      * Basic test of mapping functionality, at the moment needs more

Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java?rev=1510413&r1=1510412&r2=1510413&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
Mon Aug  5 10:08:50 2013
@@ -53,7 +53,7 @@ public class ResourceResolverImplTest {
     private ResourceResolverFactoryImpl resFac;
 
     @Before public void setup() {
-        resFac = new ResourceResolverFactoryImpl(new ResourceResolverFactoryActivator());
+        resFac = new ResourceResolverFactoryImpl(new ResourceResolverFactoryActivator(),
/* TODO: using Bundle */ null, null);
         resResolver = new ResourceResolverImpl(resFac, new ResourceResolverContext(false,
null, null));
     }
 
@@ -345,7 +345,7 @@ public class ResourceResolverImplTest {
         // the resource resolver
         final List<ResourceResolver> resolvers = new ArrayList<ResourceResolver>();
         final PathBasedResourceResolverImpl resolver = new PathBasedResourceResolverImpl(
-                new ResourceResolverFactoryImpl(new ResourceResolverFactoryActivator()) {
+                new ResourceResolverFactoryImpl(new ResourceResolverFactoryActivator(), /*
TODO: using Bundle */ null, null) {
 
                     @Override
                     public ResourceResolver getAdministrativeResourceResolver(
@@ -381,7 +381,7 @@ public class ResourceResolverImplTest {
 
         final List<ResourceResolver> resolvers = new ArrayList<ResourceResolver>();
         final PathBasedResourceResolverImpl resolver = new PathBasedResourceResolverImpl(
-                new ResourceResolverFactoryImpl(new ResourceResolverFactoryActivator()) {
+                new ResourceResolverFactoryImpl(new ResourceResolverFactoryActivator(), /*
TODO: using Bundle */ null, null) {
 
                     @Override
                     public ResourceResolver getAdministrativeResourceResolver(

Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverMangleNamespacesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverMangleNamespacesTest.java?rev=1510413&r1=1510412&r2=1510413&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverMangleNamespacesTest.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverMangleNamespacesTest.java
Mon Aug  5 10:08:50 2013
@@ -35,20 +35,20 @@ import org.mockito.MockitoAnnotations;
 /** Test ResourceResolverImpl.mangleNamespaces methods */
 public class ResourceResolverMangleNamespacesTest {
     private ResourceResolverImpl rr;
-    
+
     @Mock
     private Session mockedSession;
-    
+
     private Session activeSession;
-    
+
     public static final String NS_PREFIX = "testNS";
     public static final String NS_URL = "http://example.com/namespaces/testNS";
-    
-    @Before 
+
+    @Before
     public void setup() throws RepositoryException {
         MockitoAnnotations.initMocks(this);
         activeSession = mockedSession;
-        
+
         // Setup a ResourceResolverImpl with namespace mangling and unmangling
         final ResourceResolverFactoryActivator act = new ResourceResolverFactoryActivator()
{
             @Override
@@ -56,9 +56,9 @@ public class ResourceResolverMangleNames
                 return true;
             }
         };
-        
+
         Mockito.when(mockedSession.getNamespacePrefix(NS_PREFIX)).thenReturn(NS_URL);
-        
+
         final RootResourceProviderEntry rrpe = new RootResourceProviderEntry() {
             @Override
             @SuppressWarnings("unchecked")
@@ -69,66 +69,66 @@ public class ResourceResolverMangleNames
                 return super.adaptTo(ctx, type);
             }
         };
-        
-        final ResourceResolverFactoryImpl fac = new ResourceResolverFactoryImpl(act) {
+
+        final ResourceResolverFactoryImpl fac = new ResourceResolverFactoryImpl(act, null,
null) {
             @Override
             public RootResourceProviderEntry getRootProviderEntry() {
                 return rrpe;
             }
         };
-        
+
         rr = new ResourceResolverImpl(fac, new ResourceResolverContext(false, null, null));
     }
-    
-    @Test 
+
+    @Test
     public void testUrlWithPath() {
         assertEquals("http://example.com/some/path", rr.map("http://example.com/some/path"));
     }
-    
-    @Test 
+
+    @Test
     public void testMangleHttp() {
         assertEquals("http://example.com/path/_with_colon", rr.map("http://example.com/path/with:colon"));
     }
-    
-    @Test 
+
+    @Test
     public void testUnmangleHttp() {
         final Resource r = rr.resolve(null, "http://example.com/path/_with_mangling");
         assertEquals("/http://example.com/path/with:mangling", r.getPath());
     }
-    
-    @Test 
+
+    @Test
     public void testUnmangleNoSession() {
         activeSession = null;
         final Resource r = rr.resolve(null, "http://example.com/path/_with_mangling");
         assertEquals("/http://example.com/path/_with_mangling", r.getPath());
     }
-    
-    @Test 
+
+    @Test
     public void testManglePath() {
         assertEquals("/example.com/path/_with_colon", rr.map("/example.com/path/with:colon"));
     }
-    
-    @Test 
+
+    @Test
     public void testUnmanglePath() {
         final Resource r = rr.resolve(null, "/example.com/path/_with_mangling");
         assertEquals("/example.com/path/with:mangling", r.getPath());
     }
-    
-    @Test 
+
+    @Test
     public void testUrlNoPath() {
         assertEquals("http://withSlash.com/", rr.map("http://withSlash.com/"));
         assertEquals("http://noSlash.com", rr.map("http://noSlash.com"));
         assertEquals("http://nosuffix", rr.map("http://nosuffix"));
     }
-    
-    @Test 
+
+    @Test
     public void testWeirdCases() {
         assertEquals("http://foo", rr.map("http://foo"));
         assertEquals("http://", rr.map("http://"));
         assertEquals("http:/", rr.map("http:/"));
         assertEquals("http:", rr.map("http:"));
         assertEquals("http", rr.map("http"));
-        
+
         assertEquals("gopher://foo", rr.map("gopher://foo"));
         assertEquals("gopher://", rr.map("gopher://"));
         assertEquals("gopher:/", rr.map("gopher:/"));



Mime
View raw message