incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1520522 - in /sling/trunk/bundles: extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/ extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/impl/ extensions/serviceusermapper/src/test/j...
Date Fri, 06 Sep 2013 09:36:50 GMT
Author: cziegeler
Date: Fri Sep  6 09:36:50 2013
New Revision: 1520522

URL: http://svn.apache.org/r1520522
Log:
SLING-2944 :  Replace administrative login by service-based login

Modified:
    sling/trunk/bundles/extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapper.java
    sling/trunk/bundles/extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
    sling/trunk/bundles/extensions/serviceusermapper/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java

Modified: sling/trunk/bundles/extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapper.java?rev=1520522&r1=1520521&r2=1520522&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapper.java
(original)
+++ sling/trunk/bundles/extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapper.java
Fri Sep  6 09:36:50 2013
@@ -59,39 +59,6 @@ import aQute.bnd.annotation.ProviderType
 public interface ServiceUserMapper {
 
     /**
-     * The name of the Bundle manifest header providing the name of the service
-     * provided by the bundle. If this header is missing or empty, the bundle's
-     * symbolic name is used instead to name the service.
-     */
-    String BUNDLE_HEADER_SERVICE_NAME = "Sling-Service";
-
-    /**
-     * Returns the ID of the service represented by the given {@code bundle} and
-     * the {@code subServiceName}.
-     * <p>
-     * The service ID consists of a name derived from the bundle and the
-     * {@code serviceInfo} value if not {@code null} or empty:
-     *
-     * <pre>
-     * serviceID = serviceName [ ":" subServiceName ] .
-     * serviceName = Sling-Service manifest header or bundle symbolic name .
-     * </pre>
-     * <p>
-     * The service name for a bundle is taken from the
-     * {@value #BUNDLE_HEADER_SERVICE_NAME} manifest header of the bundle. If
-     * there is no such header or the value is empty, the bundle's symbolic name
-     * is used.
-     *
-     * @param bundle The bundle implementing the service request access to
-     *            resources.
-     * @param subServiceName Name of the sub service. This parameter is optional and
-     *            may be an empty string or {@code null}.
-     * @return The ID of the service represented by the bundle along with the
-     *         additional service information.
-     */
-    String getServiceID(Bundle bundle, String subServiceName);
-
-    /**
      * Returns the ID of a user to access the data store on behalf of the
      * service.
      *

Modified: sling/trunk/bundles/extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java?rev=1520522&r1=1520521&r2=1520522&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
(original)
+++ sling/trunk/bundles/extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
Fri Sep  6 09:36:50 2013
@@ -35,10 +35,9 @@ import org.slf4j.LoggerFactory;
 
 @Component(
         metatype = true,
-        ds = true,
         label = "Apache Sling Service User Mapper Service",
         description = "Configuration for the service mapping service names to names of users.")
-@Service()
+@Service(value=ServiceUserMapper.class)
 public class ServiceUserMapperImpl implements ServiceUserMapper {
 
     @Property(
@@ -70,7 +69,7 @@ public class ServiceUserMapperImpl imple
 
     @Activate
     @Modified
-    void configure(Map<String, Object> config) {
+    void configure(final Map<String, Object> config) {
         final String[] props = PropertiesUtil.toStringArray(config.get(PROP_SERVICE2USER_MAPPING),
             PROP_SERVICE2USER_MAPPING_DEFAULT);
 
@@ -90,13 +89,11 @@ public class ServiceUserMapperImpl imple
         this.defaultUser = PropertiesUtil.toString(config.get(PROP_DEFAULT_USER), PROP_DEFAULT_USER_DEFAULT);
     }
 
-    public String getServiceID(Bundle bundle, String subServiceName) {
-        final String serviceName = getServiceName(bundle);
-        return (subServiceName == null || subServiceName.length() == 0) ? serviceName : serviceName
+ ":" + subServiceName;
-    }
-
-    public String getServiceUserID(Bundle bundle, String subServiceName) {
-        final String serviceName = getServiceName(bundle);
+    /**
+     * @see org.apache.sling.serviceusermapping.ServiceUserMapper#getServiceUserID(org.osgi.framework.Bundle,
java.lang.String)
+     */
+    public String getServiceUserID(final Bundle bundle, final String subServiceName) {
+        final String serviceName = bundle.getSymbolicName();
 
         // try with serviceInfo first
         for (Mapping mapping : this.serviceUserMappings) {
@@ -117,13 +114,4 @@ public class ServiceUserMapperImpl imple
         // finally, fall back to default user
         return this.defaultUser;
     }
-
-    private String getServiceName(final Bundle bundle) {
-        final String name = (String) bundle.getHeaders().get(BUNDLE_HEADER_SERVICE_NAME);
-        if (name != null && name.trim().length() > 0) {
-            return name.trim();
-        }
-
-        return bundle.getSymbolicName();
-    }
 }

Modified: sling/trunk/bundles/extensions/serviceusermapper/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/serviceusermapper/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java?rev=1520522&r1=1520521&r2=1520522&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/serviceusermapper/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
(original)
+++ sling/trunk/bundles/extensions/serviceusermapper/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
Fri Sep  6 09:36:50 2013
@@ -25,7 +25,6 @@ import java.util.Map;
 import junit.framework.TestCase;
 
 import org.apache.sling.commons.testing.osgi.MockBundle;
-import org.apache.sling.serviceusermapping.ServiceUserMapper;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
 
@@ -34,8 +33,6 @@ public class ServiceUserMapperImplTest {
 
     private static final String BUNDLE_SYMBOLIC2 = "bundle2";
 
-    private static final String SRV = "srv";
-
     private static final String SUB = "sub";
 
     private static final String NONE = "none";
@@ -49,74 +46,44 @@ public class ServiceUserMapperImplTest {
     private static final String ANOTHER_SUB = "another_sub";
 
     private static final Bundle BUNDLE1 = new MockBundle(10) {
+        @Override
         public String getSymbolicName() {
             return BUNDLE_SYMBOLIC1;
         };
 
+        @Override
         public java.util.Dictionary<?, ?> getHeaders() {
             return new Hashtable<String, Object>();
         };
 
+        @Override
         public java.util.Dictionary<?, ?> getHeaders(String locale) {
             return getHeaders();
         };
     };
 
     private static final Bundle BUNDLE2 = new MockBundle(10) {
+        @Override
         public String getSymbolicName() {
             return BUNDLE_SYMBOLIC2;
         };
 
-        @SuppressWarnings("serial")
-        public java.util.Dictionary<?, ?> getHeaders() {
-            return new Hashtable<String, Object>() {
-                {
-                    put(ServiceUserMapper.BUNDLE_HEADER_SERVICE_NAME, SRV);
-                }
-            };
-        };
-
+        @Override
         public java.util.Dictionary<?, ?> getHeaders(String locale) {
             return getHeaders();
         };
     };
 
     @Test
-    public void test_getServiceID() {
-        @SuppressWarnings("serial")
-        Map<String, Object> config = new HashMap<String, Object>() {
-            {
-                put("user.mapping", new String[] {
-                    BUNDLE_SYMBOLIC1 + "=" + SAMPLE, //
-                    SRV + "=" + ANOTHER, //
-                    BUNDLE_SYMBOLIC1 + ":" + SUB + "=" + SAMPLE_SUB, //
-                    SRV + ":" + SUB + "=" + ANOTHER_SUB //
-                });
-                put("user.default", NONE);
-            }
-        };
-
-        final ServiceUserMapperImpl sum = new ServiceUserMapperImpl();
-        sum.configure(config);
-
-        TestCase.assertEquals(BUNDLE_SYMBOLIC1, sum.getServiceID(BUNDLE1, null));
-        TestCase.assertEquals(SRV, sum.getServiceID(BUNDLE2, null));
-        TestCase.assertEquals(BUNDLE_SYMBOLIC1, sum.getServiceID(BUNDLE1, ""));
-        TestCase.assertEquals(SRV, sum.getServiceID(BUNDLE2, ""));
-        TestCase.assertEquals(BUNDLE_SYMBOLIC1 + ":" + SUB, sum.getServiceID(BUNDLE1, SUB));
-        TestCase.assertEquals(SRV + ":" + SUB, sum.getServiceID(BUNDLE2, SUB));
-    }
-
-    @Test
     public void test_getServiceUserID() {
         @SuppressWarnings("serial")
         Map<String, Object> config = new HashMap<String, Object>() {
             {
                 put("user.mapping", new String[] {
                     BUNDLE_SYMBOLIC1 + "=" + SAMPLE, //
-                    SRV + "=" + ANOTHER, //
+                    BUNDLE_SYMBOLIC2 + "=" + ANOTHER, //
                     BUNDLE_SYMBOLIC1 + ":" + SUB + "=" + SAMPLE_SUB, //
-                    SRV + ":" + SUB + "=" + ANOTHER_SUB //
+                    BUNDLE_SYMBOLIC2 + ":" + SUB + "=" + ANOTHER_SUB //
                 });
                 put("user.default", NONE);
             }

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=1520522&r1=1520521&r2=1520522&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
Fri Sep  6 09:36:50 2013
@@ -79,7 +79,7 @@ public class ResourceResolverFactoryImpl
 
     public ResourceResolver getServiceResourceResolver(Map<String, Object> authenticationInfo)
throws LoginException {
 
-        // clean authenticaiton from password and get service info
+        // clean authentication from password and get service info
         final String subServiceName;
         if (authenticationInfo != null) {
             authenticationInfo.remove(PASSWORD);
@@ -98,7 +98,7 @@ public class ResourceResolverFactoryImpl
         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));
+                + this.usingBundle.getSymbolicName() + ":" + subServiceName);
         }
 
         // ensure proper user name and service bundle



Mime
View raw message