Author: pauls
Date: Mon Jul 10 15:49:58 2017
New Revision: 1801485

URL: http://svn.apache.org/viewvc?rev=1801485&view=rev
Log:
SLING-6981: Adjust ResourceResolverFactoryImpl and 
CommonsResourceResolverFactoryImpl to reflect SLING-6963 - Patch provided by 
Angela Schreiber.

Modified:
    sling/trunk/bundles/resourceresolver/pom.xml
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java

Modified: sling/trunk/bundles/resourceresolver/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/pom.xml?rev=1801485&r1=1801484&r2=1801485&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/pom.xml (original)
+++ sling/trunk/bundles/resourceresolver/pom.xml Mon Jul 10 15:49:58 2017
@@ -114,7 +114,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.serviceusermapper</artifactId>
-            <version>1.0.0</version>
+            <version>1.3.3-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>

Modified: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java?rev=1801485&r1=1801484&r2=1801485&view=diff
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
 (original)
+++ 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
 Mon Jul 10 15:49:58 2017
@@ -46,6 +46,7 @@ import org.apache.sling.resourceresolver
 import org.apache.sling.resourceresolver.impl.mapping.MapEntriesHandler;
 import org.apache.sling.resourceresolver.impl.mapping.Mapping;
 import 
org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker;
+import org.apache.sling.serviceusermapping.ServiceUserMapper;
 import org.apache.sling.spi.resource.provider.ResourceProvider;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -471,23 +472,29 @@ public class CommonResourceResolverFacto
     public Map<String, Object> getServiceUserAuthenticationInfo(final String 
subServiceName)
     throws LoginException {
         // get an administrative resource resolver
-        // Ensure a mapped user name: If no user is defined for a bundle
+        // Ensure a mapped user name or principal names: If no user/principal 
name(s)
+        // is/are 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 Bundle bundle = this.activator.getBundleContext().getBundle();
-        final String userName = 
this.activator.getServiceUserMapper().getServiceUserID(bundle, subServiceName);
-        if (userName == null) {
-            throw new LoginException("Cannot derive user name for bundle "
-                + bundle + " and sub service " + subServiceName);
+
+        ServiceUserMapper mapper = this.activator.getServiceUserMapper();
+        final Iterable<String> principalNames = 
mapper.getServicePrincipalNames(bundle, subServiceName);
+        final String userName = (principalNames == null) ? 
mapper.getServiceUserID(bundle, subServiceName) : null;
+        if (principalNames == null && userName == null) {
+            throw new LoginException("Cannot derive user name or principal 
names for bundle "
+                            + bundle + " and sub service " + subServiceName);
         }
 
         final Map<String, Object> authenticationInfo = new HashMap<>();
         // ensure proper user name and service bundle
         authenticationInfo.put(ResourceResolverFactory.SUBSERVICE, 
subServiceName);
-        authenticationInfo.put(ResourceResolverFactory.USER, userName);
         authenticationInfo.put(ResourceProvider.AUTH_SERVICE_BUNDLE, bundle);
+        if (userName != null) {
+            authenticationInfo.put(ResourceResolverFactory.USER, userName);
+        }
 
         return authenticationInfo;
     }

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=1801485&r1=1801484&r2=1801485&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 Jul 10 15:49:58 2017
@@ -74,19 +74,23 @@ public class ResourceResolverFactoryImpl
             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
+        // Ensure a mapped user or principal name(s): If no user/principal 
names is/are
+        // 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 bundle "
-                + this.usingBundle + " and sub service " + subServiceName);
+        final Iterable<String> principalNames = 
this.serviceUserMapper.getServicePrincipalNames(this.usingBundle, 
subServiceName);
+        if (principalNames == null) {
+            final String userName = 
this.serviceUserMapper.getServiceUserID(this.usingBundle, subServiceName);
+            if (userName == null) {
+                throw new LoginException("Cannot derive user name for bundle "
+                        + this.usingBundle + " and sub service " + 
subServiceName);
+            } else {
+                // ensure proper user name
+                authenticationInfo.put(ResourceResolverFactory.USER, userName);
+            }
         }
-
-        // ensure proper user name and service bundle
-        authenticationInfo.put(ResourceResolverFactory.USER, userName);
+        // ensure proper service bundle
         authenticationInfo.put(ResourceProvider.AUTH_SERVICE_BUNDLE, 
this.usingBundle);
 
         return commonFactory.getResourceResolverInternal(authenticationInfo, 
false);


Reply via email to