Author: sseifert Date: Sat Oct 3 00:57:36 2015 New Revision: 1706516 URL: http://svn.apache.org/viewvc?rev=1706516&view=rev Log: SLING-5088 register default service user mapping for mock bundle
Modified: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java Modified: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java?rev=1706516&r1=1706515&r2=1706516&view=diff ============================================================================== --- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java (original) +++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/ResourceResolverFactoryInitializer.java Sat Oct 3 00:57:36 2015 @@ -113,7 +113,10 @@ class ResourceResolverFactoryInitializer * @param bundleContext Bundle context */ private static void ensureResourceResolverFactoryActivatorDependencies(BundleContext bundleContext) { - registerServiceIfNotPresent(bundleContext, ServiceUserMapper.class, new ServiceUserMapperImpl()); + Dictionary<String, Object> config = new Hashtable<String, Object>(); + config.put("user.mapping", bundleContext.getBundle().getSymbolicName() + "=admin"); + registerServiceIfNotPresent(bundleContext, ServiceUserMapper.class, new ServiceUserMapperImpl(), config); + registerServiceIfNotPresent(bundleContext, ResourceAccessSecurityTracker.class, new ResourceAccessSecurityTracker()); registerServiceIfNotPresent(bundleContext, EventAdmin.class, new MockEventAdmin()); } @@ -140,13 +143,27 @@ class ResourceResolverFactoryInitializer * Registers a service if the service class is found in classpath, * and if no service with this class is already registered. * @param className Service class name + * @param serviceClass Service class + * @param instance Service instance + */ + private static void registerServiceIfNotPresent(BundleContext bundleContext, Class<?> serviceClass, + Object instance) { + registerServiceIfNotPresent(bundleContext, serviceClass, instance, new Hashtable<String, Object>()); + } + /** + * Registers a service if the service class is found in classpath, + * and if no service with this class is already registered. + * @param className Service class name + * @param serviceClass Service class + * @param instance Service instance + * @param config OSGi config */ - private static void registerServiceIfNotPresent(BundleContext bundleContext, Class<?> serviceClass, Object instance) { + private static void registerServiceIfNotPresent(BundleContext bundleContext, Class<?> serviceClass, + Object instance, Dictionary<String, Object> config) { if (bundleContext.getServiceReference(serviceClass.getName()) == null) { - Dictionary<String,Object> properties = new Hashtable<String, Object>(); MockOsgi.injectServices(instance, bundleContext); - MockOsgi.activate(instance, bundleContext, properties); - bundleContext.registerService(serviceClass.getName(), instance, properties); + MockOsgi.activate(instance, bundleContext, config); + bundleContext.registerService(serviceClass.getName(), instance, config); } }