incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1459328 - in /sling/whiteboard/fmeschbe/deprecate_login_administrative: ./ api/src/main/java/org/apache/sling/api/resource/ jcr/api/ jcr/api/src/main/java/org/apache/sling/jcr/api/ jcr/base/ jcr/base/src/main/java/org/apache/sling/jcr/base...
Date Thu, 21 Mar 2013 14:23:22 GMT
Author: fmeschbe
Date: Thu Mar 21 14:23:22 2013
New Revision: 1459328

URL: http://svn.apache.org/r1459328
Log:
Implement support for service based ResourceResolver and Session access

Added:
    sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/src/main/java/org/apache/sling/jcr/base/SlingRepositoryProxy.java
    sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/
      - copied from r1458700, sling/trunk/bundles/jcr/resource/
    sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/RepositoryHolder.java
Modified:
    sling/whiteboard/fmeschbe/deprecate_login_administrative/   (props changed)
    sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProviderFactory.java
    sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolverFactory.java
    sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/api/pom.xml
    sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java
    sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/pom.xml
    sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java
    sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/pom.xml
    sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
    sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
    sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java
    sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/pom.xml
    sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
    sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java
    sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
    sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java

Propchange: sling/whiteboard/fmeschbe/deprecate_login_administrative/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Mar 21 14:23:22 2013
@@ -0,0 +1,3 @@
+.project
+.settings
+target

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProviderFactory.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProviderFactory.java?rev=1459328&r1=1459327&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProviderFactory.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProviderFactory.java Thu Mar 21 14:23:22 2013
@@ -44,6 +44,10 @@ public interface ResourceProviderFactory
      */
     String PROPERTY_REQUIRED = "required";
 
+    String SERVICE_BUNDLE = "sling.service.bundle";
+
+    String SERVICE_INFO = "sling.service.info";
+
     /**
      * Returns a new {@link ResourceProvider} instance with further
      * configuration taken from the given <code>authenticationInfo</code> map.

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolverFactory.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolverFactory.java?rev=1459328&r1=1459327&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolverFactory.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolverFactory.java Thu Mar 21 14:23:22 2013
@@ -104,8 +104,12 @@ public interface ResourceResolverFactory
      * <b><i>NOTE: This method is intended for use by infrastructure bundles to
      * access the repository and provide general services. This method MUST not
      * be used to handle client requests of whatever kinds. To handle client
-     * requests a regular authenticated resource resolver retrieved
-     * through {@link #getResourceResolver(Map)} must be used.</i></b>
+     * requests a regular authenticated resource resolver retrieved through
+     * {@link #getResourceResolver(Map)} must be used.</i></b>
+     * <p>
+     * This method is deprecated. Services running in the Sling system should
+     * use the {@link #getServiceResourceResolver(String serviceInfo)} method
+     * instead.
      *
      * @param authenticationInfo A map of further credential information which
      *            may be used by the implementation to parametrize how the
@@ -116,7 +120,29 @@ public interface ResourceResolverFactory
      * @throws LoginException If an error occurrs creating the new
      *             <code>ResourceResolver</code> with the provided credential
      *             data.
+     * @deprecated as of 2.4 (bundle version 2.4.0) because of inherent security
+     *             issues. Services requiring specific permissions should use
+     *             the {@link #getServiceResourceResolver(String)} instead.
      */
+    @Deprecated
     ResourceResolver getAdministrativeResourceResolver(
             Map<String, Object> authenticationInfo) throws LoginException;
+
+    /**
+     * Returns a new {@link ResourceResolver} instance with privileges assigned
+     * to the service provided by the calling bundle. The {@code serviceInfo}
+     * argument can be used to further specialize on the service account to be
+     * used.
+     *
+     * @param serviceInfo Optional service information to specialize account
+     *            selection for the service. This may be {@code null}.
+     * @return A {@link ResourceResolver} with appropriate permissions to
+     *         execute the service.
+     * @throws LoginException If an error occurrs creating the new
+     *             <code>ResourceResolver</code> for the service represented by
+     *             the calling bundle.
+     * @since 2.4 (bundle version 2.4.0) to replace
+     *        {@link #getAdministrativeResourceResolver(Map)}
+     */
+    ResourceResolver getServiceResourceResolver(String serviceInfo) throws LoginException;
 }

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/api/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/api/pom.xml?rev=1459328&r1=1459327&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/api/pom.xml (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/api/pom.xml Thu Mar 21 14:23:22 2013
@@ -57,7 +57,7 @@
                         </Bundle-Category>
                         <Export-Package>
                             <!-- Export provider API selectively -->
-                            org.apache.sling.jcr.api;version=2.1.0
+                            org.apache.sling.jcr.api;version=2.2
                         </Export-Package>
                     </instructions>
                 </configuration>

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java?rev=1459328&r1=1459327&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java Thu Mar 21 14:23:22 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.jcr.api;
 
+import javax.jcr.LoginException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -39,7 +40,6 @@ import javax.jcr.Session;
  * implementations of the {@link NamespaceMapper} interface <b>before</b>
  * returning <b>any</b> {@link Session} to callers. This includes the methods
  * defined in the {@link Repository} interface.
- *
  */
 public interface SlingRepository extends Repository {
 
@@ -51,19 +51,41 @@ public interface SlingRepository extends
     String getDefaultWorkspace();
 
     /**
-     * Returns a session to the default workspace which has administrative
-     * powers.
+     * Returns a session to the given workspace which has administrative powers.
      * <p>
      * <b><i>NOTE: This method is intended for use by infrastructure bundles to
      * access the repository and provide general services. This method MUST not
      * be used to handle client requests of whatever kinds. To handle client
-     * requests a regular authenticated session retrieved
-     * through {@link #login(javax.jcr.Credentials, String)} or
+     * requests a regular authenticated session retrieved through
+     * {@link #login(javax.jcr.Credentials, String)} or
      * {@link Session#impersonate(javax.jcr.Credentials)} must be used.</i></b>
      *
      * @param workspace The name of the workspace to which to get an
      *            administrative session. If <code>null</code> the
      *            {@link #getDefaultWorkspace()} default workspace is assumed.
+     *
+     * @deprecated as of 2.2 (bundle version 2.2.0) because of inherent security
+     *             issues. Services requiring specific permissions should use
+     *             the {@link #loginService(String, String)} instead.
      */
     Session loginAdministrative(String workspace) throws RepositoryException;
+
+    /**
+     * Returns a sessionto the given workspace with privileges assigned to the
+     * service provided by the calling bundle. The {@code serviceInfo} argument
+     * can be used to further specialize on the service account to be used.
+     *
+     * @param serviceInfo Optional service information to specialize account
+     *            selection for the service. This may be {@code null}.
+     * @param workspace The name of the workspace to which to get an
+     *            administrative session. If <code>null</code> the
+     *            {@link #getDefaultWorkspace()} default workspace is assumed.
+     * @return A Session with appropriate permissions to execute the service.
+     * @throws LoginException If there is no service account defined for the
+     *             calling bundle or the defined service account does not exist.
+     * @throws RepositoryException if an error occurrs.
+     * @since 2.2 (bundle version 2.2.0) to replace
+     *        {@link #loginAdministrative(String)}
+     */
+    Session loginService(String serviceInfo, String workspace) throws LoginException, RepositoryException;
 }

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/pom.xml?rev=1459328&r1=1459327&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/pom.xml (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/pom.xml Thu Mar 21 14:23:22 2013
@@ -58,7 +58,7 @@
                             sling,jcr,jackrabbit
                         </Bundle-Category>
                         <Export-Package>
-                            org.apache.sling.jcr.base;
+                            org.apache.sling.jcr.base;version=1.0,
                             org.apache.sling.jcr.base.util;version=2.1.0
                         </Export-Package>
                         <Private-Package>
@@ -91,7 +91,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.jcr.api</artifactId>
-            <version>2.1.0</version>
+            <version>2.1.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
@@ -117,6 +117,13 @@
             <version>2.0.0</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.serviceusermapper</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        
         <!-- OSGi Libraries -->
         <dependency>
             <groupId>org.osgi</groupId>

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java?rev=1459328&r1=1459327&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java Thu Mar 21 14:23:22 2013
@@ -35,6 +35,10 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.base.util.RepositoryAccessor;
+import org.apache.sling.serviceusermapping.ServiceUserMapper;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.log.LogService;
@@ -100,6 +104,9 @@ public abstract class AbstractSlingRepos
     @Reference
     private LogService log;
 
+    @Reference(referenceInterface = ServiceUserMapper.class)
+    private ServiceReference serviceUserMapper;
+
     private ComponentContext componentContext;
 
     private Repository repository;
@@ -171,6 +178,12 @@ public abstract class AbstractSlingRepos
         return this.login(sc, workspace);
     }
 
+    public final Session loginService(String serviceInfo, String workspace) throws LoginException, RepositoryException {
+        log(LogService.LOG_ERROR,
+            "loginService: Cannot get using Bundle because this SlingRepository service is not a ServiceFactory");
+        throw new LoginException();
+    }
+
     public Session login(Credentials credentials) throws LoginException,
             RepositoryException {
         return this.login(credentials, null);
@@ -438,14 +451,34 @@ public abstract class AbstractSlingRepos
      * @return The OSGi <code>ServiceRegistration</code> object representing
      *         the registered service.
      */
-    protected ServiceRegistration registerService() {
+    protected final ServiceRegistration registerService() {
         @SuppressWarnings("unchecked")
-        Dictionary<String, Object> props = componentContext.getProperties();
-        String[] interfaces = new String[] { SlingRepository.class.getName(),
-            Repository.class.getName() };
+        Dictionary<String, Object> props = getServiceRegistrationProperties();
+        String[] interfaces = getServiceRegistrationInterfaces();
+
+        return componentContext.getBundleContext().registerService(interfaces, new ServiceFactory() {
+            public Object getService(Bundle bundle, ServiceRegistration registration) {
+                final ServiceUserMapper sum = (ServiceUserMapper) bundle.getBundleContext().getService(
+                    AbstractSlingRepository.this.serviceUserMapper);
+                return new SlingRepositoryProxy(AbstractSlingRepository.this, sum);
+            }
+
+            public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
+                bundle.getBundleContext().ungetService(AbstractSlingRepository.this.serviceUserMapper);
+            }
+        }, // was: this
+        props);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected Dictionary<String, Object> getServiceRegistrationProperties() {
+        return componentContext.getProperties();
+    }
 
-        return componentContext.getBundleContext().registerService(interfaces,
-            this, props);
+    protected String[] getServiceRegistrationInterfaces() {
+        return new String[] {
+            SlingRepository.class.getName(), Repository.class.getName()
+        };
     }
 
     /**

Added: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/src/main/java/org/apache/sling/jcr/base/SlingRepositoryProxy.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/src/main/java/org/apache/sling/jcr/base/SlingRepositoryProxy.java?rev=1459328&view=auto
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/src/main/java/org/apache/sling/jcr/base/SlingRepositoryProxy.java (added)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/base/src/main/java/org/apache/sling/jcr/base/SlingRepositoryProxy.java Thu Mar 21 14:23:22 2013
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jcr.base;
+
+import javax.jcr.Credentials;
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.Value;
+
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.serviceusermapping.ServiceUserMapper;
+
+public class SlingRepositoryProxy implements SlingRepository {
+
+    private final SlingRepository delegatee;
+
+    private final ServiceUserMapper serviceUserMapper;
+
+    public SlingRepositoryProxy(final SlingRepository delegatee, final ServiceUserMapper serviceUserMapper) {
+        this.delegatee = delegatee;
+        this.serviceUserMapper = serviceUserMapper;
+    }
+
+    public final Session loginService(String serviceInfo, String workspace) throws LoginException, RepositoryException {
+        final String userName = this.serviceUserMapper.getUserForService(serviceInfo);
+        final SimpleCredentials creds = new SimpleCredentials(userName, new char[0]);
+
+        Session admin = null;
+        try {
+            admin = this.delegatee.loginAdministrative(workspace);
+            return admin.impersonate(creds);
+        } finally {
+            if (admin != null) {
+                admin.logout();
+            }
+        }
+    }
+
+    // ---------- pure delegation
+
+    public String getDefaultWorkspace() {
+        return delegatee.getDefaultWorkspace();
+    }
+
+    public Session loginAdministrative(String workspace) throws RepositoryException {
+        return delegatee.loginAdministrative(workspace);
+    }
+
+    public String[] getDescriptorKeys() {
+        return delegatee.getDescriptorKeys();
+    }
+
+    public boolean isStandardDescriptor(String key) {
+        return delegatee.isStandardDescriptor(key);
+    }
+
+    public boolean isSingleValueDescriptor(String key) {
+        return delegatee.isSingleValueDescriptor(key);
+    }
+
+    public Value getDescriptorValue(String key) {
+        return delegatee.getDescriptorValue(key);
+    }
+
+    public Value[] getDescriptorValues(String key) {
+        return delegatee.getDescriptorValues(key);
+    }
+
+    public String getDescriptor(String key) {
+        return delegatee.getDescriptor(key);
+    }
+
+    public Session login(Credentials credentials, String workspaceName) throws LoginException,
+            NoSuchWorkspaceException, RepositoryException {
+        return delegatee.login(credentials, workspaceName);
+    }
+
+    public Session login(Credentials credentials) throws LoginException, RepositoryException {
+        return delegatee.login(credentials);
+    }
+
+    public Session login(String workspaceName) throws LoginException, NoSuchWorkspaceException, RepositoryException {
+        return delegatee.login(workspaceName);
+    }
+
+    public Session login() throws LoginException, RepositoryException {
+        return delegatee.login();
+    }
+
+}

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/pom.xml?rev=1459328&r1=1458700&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/pom.xml (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/pom.xml Thu Mar 21 14:23:22 2013
@@ -158,7 +158,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.jcr.api</artifactId>
-            <version>2.0.6</version>
+            <version>2.1.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java?rev=1459328&r1=1458700&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java Thu Mar 21 14:23:22 2013
@@ -106,6 +106,13 @@ public class JcrResourceResolverFactoryI
     }
 
     /**
+     * @see org.apache.sling.api.resource.ResourceResolverFactory#getServiceResourceResolver(String)
+     */
+    public ResourceResolver getServiceResourceResolver(String serviceInfo) throws LoginException {
+        return delegatee.getServiceResourceResolver(serviceInfo);
+    }
+
+    /**
      * @see org.apache.sling.api.resource.ResourceResolverFactory#getAdministrativeResourceResolver(java.util.Map)
      */
     public ResourceResolver getAdministrativeResourceResolver(

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java?rev=1459328&r1=1458700&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java Thu Mar 21 14:23:22 2013
@@ -89,14 +89,14 @@ public class JcrResourceProvider
 
     private final Session session;
     private final ClassLoader dynamicClassLoader;
-    private final boolean closeSession;
+    private final RepositoryHolder repositoryHolder;
 
     public JcrResourceProvider(final Session session,
                                final ClassLoader dynamicClassLoader,
-                               final boolean closeSession) {
+                               final RepositoryHolder repositoryHolder) {
         this.session = session;
         this.dynamicClassLoader = dynamicClassLoader;
-        this.closeSession = closeSession;
+        this.repositoryHolder = repositoryHolder;
     }
 
     // ---------- ResourceProvider interface ----------------------------------
@@ -224,9 +224,7 @@ public class JcrResourceProvider
      * @see org.apache.sling.api.resource.DynamicResourceProvider#close()
      */
     public void close() {
-        if ( this.closeSession && !closed) {
-            session.logout();
-        }
+        this.repositoryHolder.release();
         this.closed = true;
     }
 

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java?rev=1459328&r1=1458700&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderFactory.java Thu Mar 21 14:23:22 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 = "ref.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());
     }
 
@@ -126,12 +150,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 +165,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 serviceInfo = (authenticationInfo.get(SERVICE_INFO) instanceof String)
+                                ? (String) authenticationInfo.get(SERVICE_INFO)
+                                : 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(serviceInfo, 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 +230,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 +242,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);
     }
 
     /**

Added: sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/RepositoryHolder.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/RepositoryHolder.java?rev=1459328&view=auto
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/RepositoryHolder.java (added)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/RepositoryHolder.java Thu Mar 21 14:23:22 2013
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jcr.resource.internal.helper.jcr;
+
+import javax.jcr.Session;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+class RepositoryHolder {
+
+    private Session session;
+
+    private BundleContext bundleContext;
+
+    private ServiceReference repositoryReference;
+
+    RepositoryHolder() {
+    }
+
+    public void setSession(final Session session) {
+        this.session = session;
+    }
+
+    public void setRepositoryReference(final BundleContext bundleContext, final ServiceReference repositoryReference) {
+        this.bundleContext = bundleContext;
+        this.repositoryReference = repositoryReference;
+    }
+
+    void release() {
+        if (this.session != null) {
+            this.session.logout();
+            this.session = null;
+        }
+
+        if (this.repositoryReference != null) {
+            this.bundleContext.ungetService(this.repositoryReference);
+        }
+    }
+}

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/pom.xml?rev=1459328&r1=1459327&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/pom.xml (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/pom.xml Thu Mar 21 14:23:22 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/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java?rev=1459328&r1=1459327&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java Thu Mar 21 14:23:22 2013
@@ -45,8 +45,12 @@ 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.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.event.EventAdmin;
@@ -76,10 +80,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 +159,10 @@ public class ResourceResolverFactoryActi
     @Reference
     EventAdmin eventAdmin;
 
+    /** Service User Mapper */
+    @Reference(referenceInterface = ServiceUserMapper.class)
+    private ServiceReference serviceUserMapper;
+
     /** ComponentContext */
     private volatile ComponentContext componentContext;
 
@@ -324,9 +328,6 @@ public class ResourceResolverFactoryActi
             if ( local.factoryRegistration != null ) {
                 local.factoryRegistration.unregister();
             }
-            if ( local.factory != null ) {
-                local.factory.deactivate();
-            }
         }
     }
 
@@ -334,23 +335,40 @@ 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 ServiceUserMapper sum = (ServiceUserMapper) bundle.getBundleContext().getService(
+                            ResourceResolverFactoryActivator.this.serviceUserMapper);
+                        final ResourceResolverFactoryImpl r = new ResourceResolverFactoryImpl(
+                            ResourceResolverFactoryActivator.this, bundle, sum);
+                        r.activate(localContext.getBundleContext());
+                        return r;
+                    }
+
+                    public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
+                        ((ResourceResolverFactoryImpl) service).deactivate();
+                        bundle.getBundleContext().ungetService(ResourceResolverFactoryActivator.this.serviceUserMapper);
+                    }
+                }, serviceProps);
+
             // check if an unregister happened in between
             boolean doUnregister = false;
             synchronized ( this ) {

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java?rev=1459328&r1=1459327&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java Thu Mar 21 14:23:22 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.resourceresolver.impl.console.ResourceResolverWebConsolePlugin;
@@ -31,6 +33,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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -56,16 +60,49 @@ public class ResourceResolverFactoryImpl
     /** The activator */
     private final ResourceResolverFactoryActivator activator;
 
-    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 ------------------------------------
 
+    public ResourceResolver getServiceResourceResolver(String serviceInfo) throws LoginException {
+        final String userName = this.serviceUserMapper.getUserForService(serviceInfo);
+
+        // TODO: What to do if userName is null ????
+        if (userName == null) {
+            throw new LoginException("Cannot derive user name for service "
+                + this.serviceUserMapper.getServiceName(serviceInfo));
+        }
+
+        HashMap<String, Object> props = new HashMap<String, Object>();
+        props.put(ResourceResolverFactory.USER, userName);
+        props.put(ResourceProviderFactory.SERVICE_BUNDLE, this.usingBundle);
+        if (serviceInfo != null) {
+            props.put(ResourceProviderFactory.SERVICE_INFO, serviceInfo);
+        }
+
+        return getResourceResolverInternal(props, false);
+    }
+
     /**
      * @see org.apache.sling.api.resource.ResourceResolverFactory#getAdministrativeResourceResolver(java.util.Map)
      */
     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(ResourceProviderFactory.SERVICE_INFO);
+        }
+
         return getResourceResolverInternal(authenticationInfo, true);
     }
 
@@ -73,6 +110,13 @@ public class ResourceResolverFactoryImpl
      * @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(ResourceProviderFactory.SERVICE_INFO);
+        }
+
         return getResourceResolverInternal(authenticationInfo, false);
     }
 

Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java?rev=1459328&r1=1459327&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java Thu Mar 21 14:23:22 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/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java?rev=1459328&r1=1459327&r2=1459328&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java (original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/ResourceResolverImplTest.java Thu Mar 21 14:23:22 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));
     }
 
@@ -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(



Mime
View raw message