You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:13:50 UTC
[sling-org-apache-sling-serviceusermapper] annotated tag
org.apache.sling.serviceusermapper-1.1.0 created (now aad19e7)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a change to annotated tag org.apache.sling.serviceusermapper-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git.
at aad19e7 (tag)
tagging 33ec2ee93a95d395ed86bec88a4abbbc932a316a (commit)
by Antonio Sanso
on Wed Feb 25 09:47:59 2015 +0000
- Log -----------------------------------------------------------------
org.apache.sling.serviceusermapper-1.1.0
-----------------------------------------------------------------------
This annotated tag includes the following new commits:
new e689b69 Working on a prototype to deprecate loginAdministrative
new c5e0963 change api: use ServiceFactory approach and service bundle is actually the using bundle
new 7d98561 Switch back to using a regular ServiceUserName service tacking the service bundle as an argument.
new 1b03026 Implement support for service based ResourceResolver and Session access
new 3ecf9df Implement support for service based ResourceResolver and Session access
new f39b2fc SLING-2944 Implement Service User Mapper
new 0a5259b SLING-2944 : Replace administrative login by service-based login
new e9b4e3e Update to parent pom 18
new 145bf95 SLING-3286 - Remove plugin version overrides from poms
new e1a1537 Add svn info
new ce124d6 [maven-release-plugin] prepare release org.apache.sling.serviceusermapper-1.0.0
new b1c7389 [maven-release-plugin] prepare for next development iteration
new e40493e Update to parent pom v19
new 90f2a66 SLING-3578 : Support mapping amendments
new fe71e7f [maven-release-plugin] prepare release org.apache.sling.serviceusermapper-1.0.2
new 0394164 [maven-release-plugin] prepare for next development iteration
new dad1f70 SLING-3465 : Wrong description for "user.mapping" property of ServiceUserMapperImpl. Apply patch from Tobias Bocanegra and also fix the copied info in the new MappingConfigAmendment
new a8f6248 SLING-3757 : cannot add more than 1 service user with the OSGI console
new 3c2449b [maven-release-plugin] prepare release org.apache.sling.serviceusermapper-1.0.4
new d6a1293 [maven-release-plugin] prepare for next development iteration
new fdec4ca Updated to parent version 20
new a151b5a Update to Sling Parent POM 22 with baselining enabled
new 3d65ad7 SLING-3854 - Add configuration option to restrict service user mapper to system users
new eb2a1ce SLING-4312: Register an osgi service for each available service user
new 84260c0 SLING-4312: revert revision 1661081 due to a compile error on java 1.6
new 79cfa85 [maven-release-plugin] prepare release org.apache.sling.serviceusermapper-1.1.0
new 33ec2ee [maven-release-plugin] copy for tag org.apache.sling.serviceusermapper-1.1.0
The 27 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
--
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].
[sling-org-apache-sling-serviceusermapper] 06/08: SLING-4312:
revert revision 1661081 due to a compile error on java 1.6
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.serviceusermapper-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git
commit 84260c0a1ccaeb881411d3d30e517ecc8f2b2348
Author: Marius Petria <mp...@apache.org>
AuthorDate: Fri Feb 20 12:41:40 2015 +0000
SLING-4312: revert revision 1661081 due to a compile error on java 1.6
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/serviceusermapper@1661109 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 4 +-
.../serviceusermapping/ServiceUserMapping.java | 41 --------
.../sling/serviceusermapping/impl/Mapping.java | 45 +-------
.../impl/ServiceUserMapperImpl.java | 55 +---------
.../impl/ServiceUserMappingBundleFilter.java | 94 -----------------
.../impl/ServiceUserMapperImplTest.java | 114 +--------------------
6 files changed, 7 insertions(+), 346 deletions(-)
diff --git a/pom.xml b/pom.xml
index 7327f9d..f6dd450 100644
--- a/pom.xml
+++ b/pom.xml
@@ -97,8 +97,6 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
- <version>4.3.0</version>
- <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
@@ -128,7 +126,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.testing</artifactId>
- <version>2.0.16</version>
+ <version>2.0.6</version>
<scope>test</scope>
<exclusions>
<!-- slf4j simple implementation logs INFO + higher to stdout (we don't want that behaviour) -->
diff --git a/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapping.java b/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapping.java
deleted file mode 100644
index f841ddd..0000000
--- a/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapping.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.apache.sling.serviceusermapping;
-
-import aQute.bnd.annotation.ProviderType;
-
-/**
- * The <code>ServiceUserMapping</code> service can be used to retrieve an already registered service user mapping.
- * A service reference targeting a service user mapping will be satisfied only when <code>ServiceUserMapper.getServiceUserID</code>
- * will return the registered user ID in that bundle.
- * For example setting the reference target to "(subServiceName=mySubService)"
- * ensures that your component only starts when the subService is available. Trying to reference a sub service from a bundle
- * for which it was not registered for will not work.
- */
-@ProviderType
-public interface ServiceUserMapping {
-
- /**
- * The name of the osgi property holding the service name.
- */
- static String SERVICENAME = "serviceName";
-
-
- /**
- * The name of the osgi property holding the sub service name.
- */
- static String SUBSERVICENAME = "subServiceName";
-
-
- /**
- * Returns the service name for this mapping.
- *
- * @return The service name for this mapping.
- */
- String getServiceName();
-
- /**
- * Returns the sub service name for this mapping.
- *
- * @return The sub service name for this mapping. This can be {@code null} if no sub service name is configured for this mapping.
- */
- String getSubServiceName();
-}
diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java b/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java
index 4ff0fc1..07ca263 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java
@@ -18,14 +18,11 @@
*/
package org.apache.sling.serviceusermapping.impl;
-import org.apache.sling.serviceusermapping.ServiceUserMapping;
-
/**
* The <code>Mapping</code> class defines the mapping of a service's name and
* optional service information to a user name.
*/
-class Mapping implements ServiceUserMapping, Comparable<Mapping> {
-
+class Mapping {
private final String serviceName;
@@ -96,44 +93,4 @@ class Mapping implements ServiceUserMapping, Comparable<Mapping> {
return "Mapping [serviceName=" + serviceName + ", subServiceName="
+ subServiceName + ", userName=" + userName + "]";
}
-
- public String getServiceName() {
- return serviceName;
- }
-
- public String getSubServiceName() {
- return subServiceName;
- }
-
-
- public int compareTo(Mapping o) {
- if (o == null) {
- return -1;
- }
-
- int result = compare(this.serviceName, o.serviceName);
- if (result == 0) {
- result = compare(this.subServiceName, o.subServiceName);
- if (result == 0) {
- result = compare(this.userName, o.userName);
- }
- }
- return result;
- }
-
- private int compare(String str1, String str2) {
- if (str1 == str2) {
- return 0;
- }
-
- if (str1 == null) {
- return -1;
- }
-
- if (str2 == null) {
- return 1;
- }
-
- return str1.hashCode() - str2.hashCode();
- }
}
diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
index 86acf39..914a642 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
@@ -19,19 +19,11 @@
package org.apache.sling.serviceusermapping.impl;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
-import java.util.Dictionary;
import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
-import java.util.SortedMap;
-import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.TreeSet;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -46,12 +38,8 @@ import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.serviceusermapping.ServiceUserMapper;
import org.apache.sling.serviceusermapping.ServiceUserValidator;
-import org.apache.sling.serviceusermapping.ServiceUserMapping;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.framework.hooks.service.ListenerHook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -107,14 +95,9 @@ public class ServiceUserMapperImpl implements ServiceUserMapper {
private Vector <ServiceUserValidator> validators = new Vector<ServiceUserValidator>();
- private SortedMap<Mapping, ServiceRegistration> activeMappingRegistrations = new TreeMap<Mapping, ServiceRegistration>();
-
- private BundleContext bundleContext;
-
@Activate
@Modified
- void configure(BundleContext bundleContext, final Map<String, Object> config) {
- this.bundleContext = bundleContext;
+ void configure(final Map<String, Object> config) {
final String[] props = PropertiesUtil.toStringArray(config.get(PROP_SERVICE2USER_MAPPING),
PROP_SERVICE2USER_MAPPING_DEFAULT);
@@ -202,43 +185,7 @@ public class ServiceUserMapperImpl implements ServiceUserMapper {
mappings.add(m);
}
}
-
-
activeMappings = mappings.toArray(new Mapping[mappings.size()]);
-
- registerServiceMappings(mappings);
-
- }
-
-
- void registerServiceMappings(List<Mapping> newMappings) {
-
- SortedSet<Mapping> orderedActiveMappings = new TreeSet<Mapping>(newMappings);
-
-
- Iterator<Map.Entry<Mapping, ServiceRegistration>> it = activeMappingRegistrations.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry<Mapping, ServiceRegistration> registrationEntry = it.next();
-
- if (!orderedActiveMappings.contains(registrationEntry.getKey())) {
- registrationEntry.getValue().unregister();
- it.remove();
- }
- }
-
- if (bundleContext == null) {
- return;
- }
-
- for (Mapping mapping: orderedActiveMappings) {
- if (!activeMappingRegistrations.containsKey(mapping)) {
- Dictionary<String, Object> properties = new Hashtable<String, Object>();
- properties.put(ServiceUserMapping.SUBSERVICENAME, mapping.getSubServiceName() == null ? "" : mapping.getSubServiceName());
- properties.put(ServiceUserMapping.SERVICENAME, mapping.getServiceName());
- ServiceRegistration registration = bundleContext.registerService(ServiceUserMapping.class.getName(), mapping, properties);
- activeMappingRegistrations.put(mapping, registration);
- }
- }
}
private String internalGetUserId(String serviceName, String subServiceName) {
diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappingBundleFilter.java b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappingBundleFilter.java
deleted file mode 100644
index 4300ee7..0000000
--- a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappingBundleFilter.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.serviceusermapping.impl;
-
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
-import org.apache.sling.serviceusermapping.ServiceUserMapping;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.hooks.service.EventListenerHook;
-import org.osgi.framework.hooks.service.FindHook;
-import org.osgi.framework.hooks.service.ListenerHook;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-
-@Component
-@Service(value = {EventListenerHook.class, FindHook.class} )
-/**
- * The <code>ServiceUserMappingBundleFilter</code> only allows the bundle for which the service mapping is available to see it.
- */
-public class ServiceUserMappingBundleFilter implements EventListenerHook, FindHook {
-
- public void event(ServiceEvent serviceEvent, Map map) {
-
- ServiceReference serviceReference = serviceEvent.getServiceReference();
- if (isServiceMappingReference(serviceReference)) {
- Object serviceName = serviceReference.getProperty(ServiceUserMapping.SERVICENAME);
-
- if (serviceName != null && serviceName instanceof String) {
- Iterator<Map.Entry<BundleContext, Collection<ListenerHook.ListenerInfo>>> it = map.entrySet().iterator();
- while (it.hasNext()) {
- BundleContext ctx = it.next().getKey();
-
- String bundleName = ctx.getBundle().getSymbolicName();
- if (!serviceName.equals(bundleName)) {
- it.remove();
- }
- }
- }
- }
- }
-
- public void find(BundleContext bundleContext, String name, String filter, boolean allServices,
- Collection references) {
- String bundleName = bundleContext.getBundle().getSymbolicName();
-
- Iterator<ServiceReference> it = references.iterator();
- while (it.hasNext()) {
- ServiceReference serviceReference = it.next();
- if (isServiceMappingReference(serviceReference)) {
- Object serviceName = serviceReference.getProperty(ServiceUserMapping.SERVICENAME);
-
- if (serviceName != null && !serviceName.equals(bundleName)) {
- it.remove();
- }
- }
- }
- }
-
- private static boolean isServiceMappingReference(ServiceReference serviceReference) {
- Object objectClass = serviceReference.getProperty(Constants.OBJECTCLASS);
- for (Object o : (Object[]) objectClass) {
- if (ServiceUserMapping.class.getName().equals(o)) {
- return true;
- }
- }
- return false;
- }
-
-
-
-}
diff --git a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
index 0b2243f..ca5ba7f 100644
--- a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
+++ b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
@@ -18,7 +18,6 @@
*/
package org.apache.sling.serviceusermapping.impl;
-import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
@@ -26,15 +25,10 @@ import java.util.Map;
import junit.framework.TestCase;
import org.apache.sling.commons.testing.osgi.MockBundle;
-import org.apache.sling.serviceusermapping.ServiceUserMapping;
import org.apache.sling.serviceusermapping.ServiceUserValidator;
-import org.apache.sling.commons.testing.osgi.MockBundleContext;
import org.junit.Test;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
public class ServiceUserMapperImplTest {
private static final String BUNDLE_SYMBOLIC1 = "bundle1";
@@ -70,7 +64,6 @@ public class ServiceUserMapperImplTest {
};
};
-
private static final Bundle BUNDLE2 = new MockBundle(10) {
@Override
public String getSymbolicName() {
@@ -83,7 +76,6 @@ public class ServiceUserMapperImplTest {
};
};
-
@Test
public void test_getServiceUserID() {
@SuppressWarnings("serial")
@@ -100,7 +92,7 @@ public class ServiceUserMapperImplTest {
};
final ServiceUserMapperImpl sum = new ServiceUserMapperImpl();
- sum.configure(null, config);
+ sum.configure(config);
TestCase.assertEquals(SAMPLE, sum.getServiceUserID(BUNDLE1, null));
TestCase.assertEquals(ANOTHER, sum.getServiceUserID(BUNDLE2, null));
@@ -126,7 +118,7 @@ public class ServiceUserMapperImplTest {
};
final ServiceUserMapperImpl sum = new ServiceUserMapperImpl();
- sum.configure(null, config);
+ sum.configure(config);
ServiceUserValidator serviceUserValidator = new ServiceUserValidator() {
public boolean isValid(String serviceUserId, String serviceName,
@@ -161,7 +153,7 @@ public class ServiceUserMapperImplTest {
};
final ServiceUserMapperImpl sum = new ServiceUserMapperImpl();
- sum.configure(null, config);
+ sum.configure(config);
final MappingConfigAmendment mca1 = new MappingConfigAmendment();
@SuppressWarnings("serial")
final Map<String, Object> mca1Config = new HashMap<String, Object>() {
@@ -203,7 +195,7 @@ public class ServiceUserMapperImplTest {
};
final ServiceUserMapperImpl sum = new ServiceUserMapperImpl();
- sum.configure(null, config);
+ sum.configure(config);
final MappingConfigAmendment mca1 = new MappingConfigAmendment();
@SuppressWarnings("serial")
@@ -229,102 +221,4 @@ public class ServiceUserMapperImplTest {
TestCase.assertEquals(ANOTHER_SUB, sum.getServiceUserID(BUNDLE2, ""));
}
-
-
-
- @Test
- public void test_amendmentServiceUserMapping() {
- @SuppressWarnings("serial")
- Map<String, Object> config = new HashMap<String, Object>() {
- {
- put("user.mapping", new String[] {
- BUNDLE_SYMBOLIC1 + "=" + SAMPLE, //
- BUNDLE_SYMBOLIC1 + ":" + SUB + "=" + SAMPLE_SUB, //
- });
- put("user.default", NONE);
- }
- };
-
- final ServiceUserMapperImpl sum = new ServiceUserMapperImpl();
- final ServiceRegistrationContext bundleContext = new ServiceRegistrationContext();
- sum.configure(bundleContext, config);
-
- TestCase.assertEquals(2, bundleContext.getRegistrations(ServiceUserMapping.class.getName()).size());
-
- final MappingConfigAmendment mca1 = new MappingConfigAmendment();
- @SuppressWarnings("serial")
- final Map<String, Object> mca1Config = new HashMap<String, Object>() {
- {
- put("user.mapping", new String [] {BUNDLE_SYMBOLIC2 + "=" + ANOTHER});
- put(Constants.SERVICE_ID, 1L);
- put(Constants.SERVICE_RANKING, 100);
- }
- };
- mca1.configure(mca1Config);
- sum.bindAmendment(mca1, mca1Config);
-
- TestCase.assertEquals(3, bundleContext.getRegistrations(ServiceUserMapping.class.getName()).size());
-
- final MappingConfigAmendment mca2 = new MappingConfigAmendment();
- @SuppressWarnings("serial")
- final Map<String, Object> mca2Config = new HashMap<String, Object>() {
- {
- put("user.mapping", new String [] {BUNDLE_SYMBOLIC2 + ":" + SUB + "=" + ANOTHER_SUB});
- put(Constants.SERVICE_ID, 2L);
- put(Constants.SERVICE_RANKING, 200);
- }
- };
- mca2.configure(mca2Config);
- sum.bindAmendment(mca2, mca2Config);
-
- TestCase.assertEquals(4, bundleContext.getRegistrations(ServiceUserMapping.class.getName()).size());
-
- sum.unbindAmendment(mca1, mca1Config);
-
- TestCase.assertEquals(3, bundleContext.getRegistrations(ServiceUserMapping.class.getName()).size());
- }
-
-
- private class ServiceRegistrationContext extends MockBundleContext {
-
-
-
- final Map<String, Map<Object, Dictionary>> registrations = new HashMap<String, Map<Object, Dictionary>>();
-
- public ServiceRegistrationContext() {
- super(null);
- }
-
- @Override
- public ServiceRegistration registerService(String string, Object o, Dictionary dictionary) {
- if (!registrations.containsKey(string)) {
- registrations.put(string, new HashMap<Object, Dictionary>());
- }
- final Map<Object, Dictionary> serviceRegistrations = registrations.get(string);
- serviceRegistrations.put(o, dictionary);
-
- final Object registeredObject = o;
-
-
- return new ServiceRegistration() {
- public ServiceReference getReference() {
- return null;
- }
-
- public void setProperties(Dictionary dictionary) {
-
- }
-
- public void unregister() {
- serviceRegistrations.remove(registeredObject);
- }
- };
- }
-
- public Map<Object, Dictionary> getRegistrations(String name) {
- return registrations.get(name);
- }
-
- }
-
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-serviceusermapper] 05/08: SLING-4312:
Register an osgi service for each available service user
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.serviceusermapper-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git
commit eb2a1ce0a0683d4e119a4356bce49a6ff18a0a62
Author: Marius Petria <mp...@apache.org>
AuthorDate: Fri Feb 20 10:08:49 2015 +0000
SLING-4312: Register an osgi service for each available service user
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/serviceusermapper@1661081 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 4 +-
.../serviceusermapping/ServiceUserMapping.java | 41 ++++++++
.../sling/serviceusermapping/impl/Mapping.java | 45 +++++++-
.../impl/ServiceUserMapperImpl.java | 55 +++++++++-
.../impl/ServiceUserMappingBundleFilter.java | 94 +++++++++++++++++
.../impl/ServiceUserMapperImplTest.java | 114 ++++++++++++++++++++-
6 files changed, 346 insertions(+), 7 deletions(-)
diff --git a/pom.xml b/pom.xml
index f6dd450..7327f9d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -97,6 +97,8 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
+ <version>4.3.0</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
@@ -126,7 +128,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.testing</artifactId>
- <version>2.0.6</version>
+ <version>2.0.16</version>
<scope>test</scope>
<exclusions>
<!-- slf4j simple implementation logs INFO + higher to stdout (we don't want that behaviour) -->
diff --git a/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapping.java b/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapping.java
new file mode 100644
index 0000000..f841ddd
--- /dev/null
+++ b/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapping.java
@@ -0,0 +1,41 @@
+package org.apache.sling.serviceusermapping;
+
+import aQute.bnd.annotation.ProviderType;
+
+/**
+ * The <code>ServiceUserMapping</code> service can be used to retrieve an already registered service user mapping.
+ * A service reference targeting a service user mapping will be satisfied only when <code>ServiceUserMapper.getServiceUserID</code>
+ * will return the registered user ID in that bundle.
+ * For example setting the reference target to "(subServiceName=mySubService)"
+ * ensures that your component only starts when the subService is available. Trying to reference a sub service from a bundle
+ * for which it was not registered for will not work.
+ */
+@ProviderType
+public interface ServiceUserMapping {
+
+ /**
+ * The name of the osgi property holding the service name.
+ */
+ static String SERVICENAME = "serviceName";
+
+
+ /**
+ * The name of the osgi property holding the sub service name.
+ */
+ static String SUBSERVICENAME = "subServiceName";
+
+
+ /**
+ * Returns the service name for this mapping.
+ *
+ * @return The service name for this mapping.
+ */
+ String getServiceName();
+
+ /**
+ * Returns the sub service name for this mapping.
+ *
+ * @return The sub service name for this mapping. This can be {@code null} if no sub service name is configured for this mapping.
+ */
+ String getSubServiceName();
+}
diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java b/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java
index 07ca263..4ff0fc1 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java
@@ -18,11 +18,14 @@
*/
package org.apache.sling.serviceusermapping.impl;
+import org.apache.sling.serviceusermapping.ServiceUserMapping;
+
/**
* The <code>Mapping</code> class defines the mapping of a service's name and
* optional service information to a user name.
*/
-class Mapping {
+class Mapping implements ServiceUserMapping, Comparable<Mapping> {
+
private final String serviceName;
@@ -93,4 +96,44 @@ class Mapping {
return "Mapping [serviceName=" + serviceName + ", subServiceName="
+ subServiceName + ", userName=" + userName + "]";
}
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ public String getSubServiceName() {
+ return subServiceName;
+ }
+
+
+ public int compareTo(Mapping o) {
+ if (o == null) {
+ return -1;
+ }
+
+ int result = compare(this.serviceName, o.serviceName);
+ if (result == 0) {
+ result = compare(this.subServiceName, o.subServiceName);
+ if (result == 0) {
+ result = compare(this.userName, o.userName);
+ }
+ }
+ return result;
+ }
+
+ private int compare(String str1, String str2) {
+ if (str1 == str2) {
+ return 0;
+ }
+
+ if (str1 == null) {
+ return -1;
+ }
+
+ if (str2 == null) {
+ return 1;
+ }
+
+ return str1.hashCode() - str2.hashCode();
+ }
}
diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
index 914a642..86acf39 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
@@ -19,11 +19,19 @@
package org.apache.sling.serviceusermapping.impl;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.Dictionary;
import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -38,8 +46,12 @@ import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.serviceusermapping.ServiceUserMapper;
import org.apache.sling.serviceusermapping.ServiceUserValidator;
+import org.apache.sling.serviceusermapping.ServiceUserMapping;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.hooks.service.ListenerHook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -95,9 +107,14 @@ public class ServiceUserMapperImpl implements ServiceUserMapper {
private Vector <ServiceUserValidator> validators = new Vector<ServiceUserValidator>();
+ private SortedMap<Mapping, ServiceRegistration> activeMappingRegistrations = new TreeMap<Mapping, ServiceRegistration>();
+
+ private BundleContext bundleContext;
+
@Activate
@Modified
- void configure(final Map<String, Object> config) {
+ void configure(BundleContext bundleContext, final Map<String, Object> config) {
+ this.bundleContext = bundleContext;
final String[] props = PropertiesUtil.toStringArray(config.get(PROP_SERVICE2USER_MAPPING),
PROP_SERVICE2USER_MAPPING_DEFAULT);
@@ -185,7 +202,43 @@ public class ServiceUserMapperImpl implements ServiceUserMapper {
mappings.add(m);
}
}
+
+
activeMappings = mappings.toArray(new Mapping[mappings.size()]);
+
+ registerServiceMappings(mappings);
+
+ }
+
+
+ void registerServiceMappings(List<Mapping> newMappings) {
+
+ SortedSet<Mapping> orderedActiveMappings = new TreeSet<Mapping>(newMappings);
+
+
+ Iterator<Map.Entry<Mapping, ServiceRegistration>> it = activeMappingRegistrations.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry<Mapping, ServiceRegistration> registrationEntry = it.next();
+
+ if (!orderedActiveMappings.contains(registrationEntry.getKey())) {
+ registrationEntry.getValue().unregister();
+ it.remove();
+ }
+ }
+
+ if (bundleContext == null) {
+ return;
+ }
+
+ for (Mapping mapping: orderedActiveMappings) {
+ if (!activeMappingRegistrations.containsKey(mapping)) {
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(ServiceUserMapping.SUBSERVICENAME, mapping.getSubServiceName() == null ? "" : mapping.getSubServiceName());
+ properties.put(ServiceUserMapping.SERVICENAME, mapping.getServiceName());
+ ServiceRegistration registration = bundleContext.registerService(ServiceUserMapping.class.getName(), mapping, properties);
+ activeMappingRegistrations.put(mapping, registration);
+ }
+ }
}
private String internalGetUserId(String serviceName, String subServiceName) {
diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappingBundleFilter.java b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappingBundleFilter.java
new file mode 100644
index 0000000..4300ee7
--- /dev/null
+++ b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappingBundleFilter.java
@@ -0,0 +1,94 @@
+/*
+ * 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.serviceusermapping.impl;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.serviceusermapping.ServiceUserMapping;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.hooks.service.EventListenerHook;
+import org.osgi.framework.hooks.service.FindHook;
+import org.osgi.framework.hooks.service.ListenerHook;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+@Component
+@Service(value = {EventListenerHook.class, FindHook.class} )
+/**
+ * The <code>ServiceUserMappingBundleFilter</code> only allows the bundle for which the service mapping is available to see it.
+ */
+public class ServiceUserMappingBundleFilter implements EventListenerHook, FindHook {
+
+ public void event(ServiceEvent serviceEvent, Map map) {
+
+ ServiceReference serviceReference = serviceEvent.getServiceReference();
+ if (isServiceMappingReference(serviceReference)) {
+ Object serviceName = serviceReference.getProperty(ServiceUserMapping.SERVICENAME);
+
+ if (serviceName != null && serviceName instanceof String) {
+ Iterator<Map.Entry<BundleContext, Collection<ListenerHook.ListenerInfo>>> it = map.entrySet().iterator();
+ while (it.hasNext()) {
+ BundleContext ctx = it.next().getKey();
+
+ String bundleName = ctx.getBundle().getSymbolicName();
+ if (!serviceName.equals(bundleName)) {
+ it.remove();
+ }
+ }
+ }
+ }
+ }
+
+ public void find(BundleContext bundleContext, String name, String filter, boolean allServices,
+ Collection references) {
+ String bundleName = bundleContext.getBundle().getSymbolicName();
+
+ Iterator<ServiceReference> it = references.iterator();
+ while (it.hasNext()) {
+ ServiceReference serviceReference = it.next();
+ if (isServiceMappingReference(serviceReference)) {
+ Object serviceName = serviceReference.getProperty(ServiceUserMapping.SERVICENAME);
+
+ if (serviceName != null && !serviceName.equals(bundleName)) {
+ it.remove();
+ }
+ }
+ }
+ }
+
+ private static boolean isServiceMappingReference(ServiceReference serviceReference) {
+ Object objectClass = serviceReference.getProperty(Constants.OBJECTCLASS);
+ for (Object o : (Object[]) objectClass) {
+ if (ServiceUserMapping.class.getName().equals(o)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+
+}
diff --git a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
index ca5ba7f..0b2243f 100644
--- a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
+++ b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.sling.serviceusermapping.impl;
+import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
@@ -25,10 +26,15 @@ import java.util.Map;
import junit.framework.TestCase;
import org.apache.sling.commons.testing.osgi.MockBundle;
+import org.apache.sling.serviceusermapping.ServiceUserMapping;
import org.apache.sling.serviceusermapping.ServiceUserValidator;
+import org.apache.sling.commons.testing.osgi.MockBundleContext;
import org.junit.Test;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
public class ServiceUserMapperImplTest {
private static final String BUNDLE_SYMBOLIC1 = "bundle1";
@@ -64,6 +70,7 @@ public class ServiceUserMapperImplTest {
};
};
+
private static final Bundle BUNDLE2 = new MockBundle(10) {
@Override
public String getSymbolicName() {
@@ -76,6 +83,7 @@ public class ServiceUserMapperImplTest {
};
};
+
@Test
public void test_getServiceUserID() {
@SuppressWarnings("serial")
@@ -92,7 +100,7 @@ public class ServiceUserMapperImplTest {
};
final ServiceUserMapperImpl sum = new ServiceUserMapperImpl();
- sum.configure(config);
+ sum.configure(null, config);
TestCase.assertEquals(SAMPLE, sum.getServiceUserID(BUNDLE1, null));
TestCase.assertEquals(ANOTHER, sum.getServiceUserID(BUNDLE2, null));
@@ -118,7 +126,7 @@ public class ServiceUserMapperImplTest {
};
final ServiceUserMapperImpl sum = new ServiceUserMapperImpl();
- sum.configure(config);
+ sum.configure(null, config);
ServiceUserValidator serviceUserValidator = new ServiceUserValidator() {
public boolean isValid(String serviceUserId, String serviceName,
@@ -153,7 +161,7 @@ public class ServiceUserMapperImplTest {
};
final ServiceUserMapperImpl sum = new ServiceUserMapperImpl();
- sum.configure(config);
+ sum.configure(null, config);
final MappingConfigAmendment mca1 = new MappingConfigAmendment();
@SuppressWarnings("serial")
final Map<String, Object> mca1Config = new HashMap<String, Object>() {
@@ -195,7 +203,7 @@ public class ServiceUserMapperImplTest {
};
final ServiceUserMapperImpl sum = new ServiceUserMapperImpl();
- sum.configure(config);
+ sum.configure(null, config);
final MappingConfigAmendment mca1 = new MappingConfigAmendment();
@SuppressWarnings("serial")
@@ -221,4 +229,102 @@ public class ServiceUserMapperImplTest {
TestCase.assertEquals(ANOTHER_SUB, sum.getServiceUserID(BUNDLE2, ""));
}
+
+
+
+ @Test
+ public void test_amendmentServiceUserMapping() {
+ @SuppressWarnings("serial")
+ Map<String, Object> config = new HashMap<String, Object>() {
+ {
+ put("user.mapping", new String[] {
+ BUNDLE_SYMBOLIC1 + "=" + SAMPLE, //
+ BUNDLE_SYMBOLIC1 + ":" + SUB + "=" + SAMPLE_SUB, //
+ });
+ put("user.default", NONE);
+ }
+ };
+
+ final ServiceUserMapperImpl sum = new ServiceUserMapperImpl();
+ final ServiceRegistrationContext bundleContext = new ServiceRegistrationContext();
+ sum.configure(bundleContext, config);
+
+ TestCase.assertEquals(2, bundleContext.getRegistrations(ServiceUserMapping.class.getName()).size());
+
+ final MappingConfigAmendment mca1 = new MappingConfigAmendment();
+ @SuppressWarnings("serial")
+ final Map<String, Object> mca1Config = new HashMap<String, Object>() {
+ {
+ put("user.mapping", new String [] {BUNDLE_SYMBOLIC2 + "=" + ANOTHER});
+ put(Constants.SERVICE_ID, 1L);
+ put(Constants.SERVICE_RANKING, 100);
+ }
+ };
+ mca1.configure(mca1Config);
+ sum.bindAmendment(mca1, mca1Config);
+
+ TestCase.assertEquals(3, bundleContext.getRegistrations(ServiceUserMapping.class.getName()).size());
+
+ final MappingConfigAmendment mca2 = new MappingConfigAmendment();
+ @SuppressWarnings("serial")
+ final Map<String, Object> mca2Config = new HashMap<String, Object>() {
+ {
+ put("user.mapping", new String [] {BUNDLE_SYMBOLIC2 + ":" + SUB + "=" + ANOTHER_SUB});
+ put(Constants.SERVICE_ID, 2L);
+ put(Constants.SERVICE_RANKING, 200);
+ }
+ };
+ mca2.configure(mca2Config);
+ sum.bindAmendment(mca2, mca2Config);
+
+ TestCase.assertEquals(4, bundleContext.getRegistrations(ServiceUserMapping.class.getName()).size());
+
+ sum.unbindAmendment(mca1, mca1Config);
+
+ TestCase.assertEquals(3, bundleContext.getRegistrations(ServiceUserMapping.class.getName()).size());
+ }
+
+
+ private class ServiceRegistrationContext extends MockBundleContext {
+
+
+
+ final Map<String, Map<Object, Dictionary>> registrations = new HashMap<String, Map<Object, Dictionary>>();
+
+ public ServiceRegistrationContext() {
+ super(null);
+ }
+
+ @Override
+ public ServiceRegistration registerService(String string, Object o, Dictionary dictionary) {
+ if (!registrations.containsKey(string)) {
+ registrations.put(string, new HashMap<Object, Dictionary>());
+ }
+ final Map<Object, Dictionary> serviceRegistrations = registrations.get(string);
+ serviceRegistrations.put(o, dictionary);
+
+ final Object registeredObject = o;
+
+
+ return new ServiceRegistration() {
+ public ServiceReference getReference() {
+ return null;
+ }
+
+ public void setProperties(Dictionary dictionary) {
+
+ }
+
+ public void unregister() {
+ serviceRegistrations.remove(registeredObject);
+ }
+ };
+ }
+
+ public Map<Object, Dictionary> getRegistrations(String name) {
+ return registrations.get(name);
+ }
+
+ }
+
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-serviceusermapper] 03/08: Update to Sling
Parent POM 22 with baselining enabled
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.serviceusermapper-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git
commit a151b5a3f39535076702332adc7ad625824c69d1
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Oct 1 06:57:44 2014 +0000
Update to Sling Parent POM 22 with baselining enabled
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/serviceusermapper@1628622 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 4cda083..f6dd450 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>20</version>
+ <version>22</version>
</parent>
<artifactId>org.apache.sling.serviceusermapper</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-serviceusermapper] 07/08:
[maven-release-plugin] prepare release
org.apache.sling.serviceusermapper-1.1.0
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.serviceusermapper-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git
commit 79cfa853569ecf552b7fad5fb10a60b93b27a86c
Author: Antonio Sanso <as...@apache.org>
AuthorDate: Wed Feb 25 09:47:43 2015 +0000
[maven-release-plugin] prepare release org.apache.sling.serviceusermapper-1.1.0
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/serviceusermapper@1662192 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index f6dd450..b62ab17 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
<artifactId>org.apache.sling.serviceusermapper</artifactId>
<packaging>bundle</packaging>
- <version>1.0.5-SNAPSHOT</version>
+ <version>1.1.0</version>
<name>Apache Sling Service User Mapper</name>
<description>
@@ -39,9 +39,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/serviceusermapper</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/serviceusermapper</developerConnection>
- <url>http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/serviceusermapper</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.serviceusermapper-1.1.0</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.serviceusermapper-1.1.0</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.serviceusermapper-1.1.0</url>
</scm>
<build>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-serviceusermapper] 02/08: Updated to parent
version 20
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.serviceusermapper-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git
commit fdec4ca8a0e5a10be2cef170cdd179d89d3ea559
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Aug 1 19:16:26 2014 +0000
Updated to parent version 20
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/serviceusermapper@1615208 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index f6ca29e..4cda083 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>19</version>
+ <version>20</version>
</parent>
<artifactId>org.apache.sling.serviceusermapper</artifactId>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-serviceusermapper] 04/08: SLING-3854 - Add
configuration option to restrict service user mapper to system users
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.serviceusermapper-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git
commit 3d65ad79c9ed6e186e6274565dd3e3318519f406
Author: Antonio Sanso <as...@apache.org>
AuthorDate: Thu Feb 19 10:30:03 2015 +0000
SLING-3854 - Add configuration option to restrict service user mapper to system users
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/serviceusermapper@1660832 13f79535-47bb-0310-9956-ffa450edef68
---
.../serviceusermapping/ServiceUserValidator.java | 35 +++++++
.../impl/ServiceUserMapperImpl.java | 101 +++++++++++++++------
.../sling/serviceusermapping/package-info.java | 2 +-
.../impl/ServiceUserMapperImplTest.java | 38 ++++++++
4 files changed, 149 insertions(+), 27 deletions(-)
diff --git a/src/main/java/org/apache/sling/serviceusermapping/ServiceUserValidator.java b/src/main/java/org/apache/sling/serviceusermapping/ServiceUserValidator.java
new file mode 100644
index 0000000..7930582
--- /dev/null
+++ b/src/main/java/org/apache/sling/serviceusermapping/ServiceUserValidator.java
@@ -0,0 +1,35 @@
+/*
+ * 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.serviceusermapping;
+
+import aQute.bnd.annotation.ConsumerType;
+
+/**
+ * The {@code ServiceUserValidator} allows to implement validation of configured
+ * service user mappings.
+ */
+@ConsumerType
+public interface ServiceUserValidator {
+
+ /**
+ * Validates the configured service user ID.
+ *
+ * @param serviceUserId The ID of the configured service user.
+ * @return {@code true} if the configured service user is valid; {@code false} otherwise.
+ */
+ boolean isValid(String serviceUserId, String serviceName, String subServiceName);
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
index 02e22f6..914a642 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Vector;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -32,9 +33,11 @@ import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.References;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.serviceusermapping.ServiceUserMapper;
+import org.apache.sling.serviceusermapping.ServiceUserValidator;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
@@ -45,11 +48,18 @@ import org.slf4j.LoggerFactory;
label = "Apache Sling Service User Mapper Service",
description = "Configuration for the service mapping service names to names of users.")
@Service(value=ServiceUserMapper.class)
-@Reference(name="amendment",
- referenceInterface=MappingConfigAmendment.class,
- cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE,
- policy=ReferencePolicy.DYNAMIC,
- updated="updateAmendment")
+@References( {
+ @Reference(name="amendment",
+ referenceInterface=MappingConfigAmendment.class,
+ cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE,
+ policy=ReferencePolicy.DYNAMIC,
+ updated="updateAmendment"),
+ @Reference(name = "serviceUserValidator ", referenceInterface = ServiceUserValidator.class,
+ bind = "bindServiceUserValidator", unbind = "unbindServiceUserValidator",
+ cardinality= ReferenceCardinality.OPTIONAL_MULTIPLE, policy= ReferencePolicy.DYNAMIC)
+
+})
+
public class ServiceUserMapperImpl implements ServiceUserMapper {
@Property(
@@ -83,6 +93,8 @@ public class ServiceUserMapperImpl implements ServiceUserMapper {
private Mapping[] activeMappings = new Mapping[0];
+ private Vector <ServiceUserValidator> validators = new Vector<ServiceUserValidator>();
+
@Activate
@Modified
void configure(final Map<String, Object> config) {
@@ -96,7 +108,7 @@ public class ServiceUserMapperImpl implements ServiceUserMapper {
final Mapping mapping = new Mapping(prop.trim());
mappings.add(mapping);
} catch (final IllegalArgumentException iae) {
- log.info("configure: Ignoring '{}': {}", prop, iae.getMessage());
+ log.error("configure: Ignoring '{}': {}", prop, iae.getMessage());
}
}
}
@@ -107,31 +119,32 @@ public class ServiceUserMapperImpl implements ServiceUserMapper {
this.updateMappings();
}
}
+
+ /**
+ * bind the serviceUserValidator
+ * @param serviceUserValidator
+ * @param properties
+ */
+ protected void bindServiceUserValidator(final ServiceUserValidator serviceUserValidator, final Map<String, Object> properties){
+ validators.add(serviceUserValidator);
+ }
+
+ /**
+ * unbind the serviceUserValidator
+ * @param serviceUserValidator
+ * @param properties
+ */
+ protected void unbindServiceUserValidator(final ServiceUserValidator serviceUserValidator, final Map<String, Object> properties){
+ validators.remove(serviceUserValidator);
+ }
/**
* @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.activeMappings) {
- final String user = mapping.map(serviceName, subServiceName);
- if (user != null) {
- return user;
- }
- }
-
- // second round without serviceInfo
- for (Mapping mapping : this.activeMappings) {
- final String user = mapping.map(serviceName, null);
- if (user != null) {
- return user;
- }
- }
-
- // finally, fall back to default user
- return this.defaultUser;
+ final String userId = internalGetUserId(serviceName, subServiceName);
+ return isValidUser(userId, serviceName, subServiceName) ? userId : null;
}
protected void bindAmendment(final MappingConfigAmendment amendment, final Map<String, Object> props) {
@@ -147,7 +160,7 @@ public class ServiceUserMapperImpl implements ServiceUserMapper {
synchronized ( this.amendments ) {
if ( amendments.remove(key) != null ) {
this.updateMappings();
- };
+ }
}
}
@@ -174,5 +187,41 @@ public class ServiceUserMapperImpl implements ServiceUserMapper {
}
activeMappings = mappings.toArray(new Mapping[mappings.size()]);
}
+
+ private String internalGetUserId(String serviceName, String subServiceName) {
+ // try with serviceInfo first
+ for (Mapping mapping : this.activeMappings) {
+ final String userId = mapping.map(serviceName, subServiceName);
+ if (userId != null) {
+ return userId;
+ }
+ }
+
+ // second round without serviceInfo
+ for (Mapping mapping : this.activeMappings) {
+ final String userId = mapping.map(serviceName, null);
+ if (userId != null) {
+ return userId;
+ }
+ }
+
+ // finally, fall back to default user
+ return this.defaultUser;
+ }
+
+ private boolean isValidUser(String userId, String serviceName, String subServiceName) {
+ if (userId == null) {
+ return false;
+ }
+ if (validators != null && validators.size() > 0) {
+ for (ServiceUserValidator validator : validators) {
+ boolean valid = validator.isValid(userId, serviceName, subServiceName);
+ if (!valid) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
}
diff --git a/src/main/java/org/apache/sling/serviceusermapping/package-info.java b/src/main/java/org/apache/sling/serviceusermapping/package-info.java
index 3ebac13..c05c7ae 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/package-info.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/package-info.java
@@ -17,7 +17,7 @@
* under the License.
*/
-@Version("1.0")
+@Version("1.1")
@Export(optional = "provide:=true")
package org.apache.sling.serviceusermapping;
diff --git a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
index 2a98a45..ca5ba7f 100644
--- a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
+++ b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
@@ -25,6 +25,7 @@ import java.util.Map;
import junit.framework.TestCase;
import org.apache.sling.commons.testing.osgi.MockBundle;
+import org.apache.sling.serviceusermapping.ServiceUserValidator;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
@@ -100,6 +101,43 @@ public class ServiceUserMapperImplTest {
TestCase.assertEquals(SAMPLE_SUB, sum.getServiceUserID(BUNDLE1, SUB));
TestCase.assertEquals(ANOTHER_SUB, sum.getServiceUserID(BUNDLE2, SUB));
}
+
+ @Test
+ public void test_getServiceUserID_WithServiceUserValidator() {
+ @SuppressWarnings("serial")
+ Map<String, Object> config = new HashMap<String, Object>() {
+ {
+ put("user.mapping", new String[] {
+ BUNDLE_SYMBOLIC1 + "=" + SAMPLE, //
+ BUNDLE_SYMBOLIC2 + "=" + ANOTHER, //
+ BUNDLE_SYMBOLIC1 + ":" + SUB + "=" + SAMPLE_SUB, //
+ BUNDLE_SYMBOLIC2 + ":" + SUB + "=" + ANOTHER_SUB //
+ });
+ put("user.default", NONE);
+ }
+ };
+
+ final ServiceUserMapperImpl sum = new ServiceUserMapperImpl();
+ sum.configure(config);
+ ServiceUserValidator serviceUserValidator = new ServiceUserValidator() {
+
+ public boolean isValid(String serviceUserId, String serviceName,
+ String subServiceName) {
+ if (SAMPLE.equals(serviceUserId)) {
+ return false;
+ }
+ return true;
+ }
+ };
+ sum.bindServiceUserValidator(serviceUserValidator, null);
+
+ TestCase.assertEquals(null, sum.getServiceUserID(BUNDLE1, null));
+ TestCase.assertEquals(ANOTHER, sum.getServiceUserID(BUNDLE2, null));
+ TestCase.assertEquals(null, sum.getServiceUserID(BUNDLE1, ""));
+ TestCase.assertEquals(ANOTHER, sum.getServiceUserID(BUNDLE2, ""));
+ TestCase.assertEquals(SAMPLE_SUB, sum.getServiceUserID(BUNDLE1, SUB));
+ TestCase.assertEquals(ANOTHER_SUB, sum.getServiceUserID(BUNDLE2, SUB));
+ }
@Test
public void test_amendment() {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-serviceusermapper] 01/08:
[maven-release-plugin] prepare for next development iteration
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.serviceusermapper-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git
commit d6a1293b43630a543e1a7a5b3c8f2ca289d030df
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Jul 10 21:04:47 2014 +0000
[maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/serviceusermapper@1609572 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 99cf77a..f6ca29e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
<artifactId>org.apache.sling.serviceusermapper</artifactId>
<packaging>bundle</packaging>
- <version>1.0.4</version>
+ <version>1.0.5-SNAPSHOT</version>
<name>Apache Sling Service User Mapper</name>
<description>
@@ -39,9 +39,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.serviceusermapper-1.0.4</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.serviceusermapper-1.0.4</developerConnection>
- <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.serviceusermapper-1.0.4</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/serviceusermapper</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/serviceusermapper</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/serviceusermapper</url>
</scm>
<build>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-serviceusermapper] 08/08:
[maven-release-plugin] copy for tag
org.apache.sling.serviceusermapper-1.1.0
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.serviceusermapper-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git
commit 33ec2ee93a95d395ed86bec88a4abbbc932a316a
Author: Antonio Sanso <as...@apache.org>
AuthorDate: Wed Feb 25 09:47:59 2015 +0000
[maven-release-plugin] copy for tag org.apache.sling.serviceusermapper-1.1.0
git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.serviceusermapper-1.1.0@1662193 13f79535-47bb-0310-9956-ffa450edef68
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.