You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2018/01/10 13:36:26 UTC

[sling-org-apache-sling-serviceusermapper] 01/02: Exposing the Mapping POJO and the getActiveMappings method

This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git

commit 61a7a11ff503dee607a0ea7590f0a56d6def8f5e
Author: Dan Klco <da...@gmail.com>
AuthorDate: Tue Jan 9 20:47:04 2018 -0800

    Exposing the Mapping POJO and the getActiveMappings method
---
 pom.xml                                            | 23 +++++++
 .../serviceusermapping/{impl => }/Mapping.java     | 14 ++---
 .../serviceusermapping/ServiceUserMapper.java      | 71 +++++++++++++---------
 .../impl/MappingConfigAmendment.java               |  1 +
 .../impl/MappingInventoryPrinter.java              |  1 +
 .../impl/ServiceUserMappedBundleFilter.java        |  1 +
 .../impl/ServiceUserMapperImpl.java                |  3 +-
 .../sling/serviceusermapping/package-info.java     |  2 +-
 .../sling/serviceusermapping/impl/MappingTest.java |  2 +
 .../impl/ServiceUserMappedBundleFilterTest.java    |  2 +
 10 files changed, 83 insertions(+), 37 deletions(-)

diff --git a/pom.xml b/pom.xml
index a2cece3..c69423d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -135,4 +135,27 @@
         </dependency>
     </dependencies>
 
+	<profiles>
+		<profile>
+			<id>autoInstallBundle</id>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.apache.sling</groupId>
+						<artifactId>maven-sling-plugin</artifactId>
+						<version>2.1.0</version>
+						<executions>
+							<execution>
+								<id>install-bundle</id>
+								<goals>
+									<goal>install</goal>
+								</goals>
+							</execution>
+						</executions>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
+
 </project>
diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java b/src/main/java/org/apache/sling/serviceusermapping/Mapping.java
similarity index 93%
rename from src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java
rename to src/main/java/org/apache/sling/serviceusermapping/Mapping.java
index 9dfc7c3..87608c0 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/Mapping.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.serviceusermapping.impl;
+package org.apache.sling.serviceusermapping;
 
 import java.util.LinkedHashSet;
 import java.util.Set;
@@ -25,13 +25,13 @@ import java.util.Set;
  * The <code>Mapping</code> class defines the mapping of a service's name and
  * optional service information to a user name and optionally to a set of principal names.
  */
-class Mapping implements Comparable<Mapping> {
+public class Mapping implements Comparable<Mapping> {
 
 
     /**
      * The name of the osgi property holding the service name.
      */
-    static String SERVICENAME = ".serviceName";
+    public static String SERVICENAME = ".serviceName";
 
     private final String serviceName;
 
@@ -54,7 +54,7 @@ class Mapping implements Comparable<Mapping> {
      * @throws IllegalArgumentException if {@code spec} does not match the
      *             expected pattern.
      */
-    Mapping(final String spec) {
+    public Mapping(final String spec) {
 
         final int colon = spec.indexOf(':');
         final int equals = spec.indexOf('=');
@@ -85,7 +85,7 @@ class Mapping implements Comparable<Mapping> {
         }
     }
 
-    static Set<String> extractPrincipalNames(String s) {
+    public static Set<String> extractPrincipalNames(String s) {
         String[] sArr = s.substring(1, s.length() - 1).split(",");
         Set<String> set = new LinkedHashSet<>();
         for (String name : sArr) {
@@ -108,7 +108,7 @@ class Mapping implements Comparable<Mapping> {
      *            {@code null}.
      * @return The user name if this mapping matches and the configuration doesn't specify a set of principal names; {@code null} otherwise.
      */
-    String map(final String serviceName, final String subServiceName) {
+    public String map(final String serviceName, final String subServiceName) {
         if (this.serviceName.equals(serviceName) && equals(this.subServiceName, subServiceName)) {
             return userName;
         }
@@ -130,7 +130,7 @@ class Mapping implements Comparable<Mapping> {
      * does specify a set of principal names (intstead of a single user name); {@code null}
      * otherwise.
      */
-    Iterable<String> mapPrincipals(final String serviceName, final String subServiceName) {
+    public Iterable<String> mapPrincipals(final String serviceName, final String subServiceName) {
         if (this.serviceName.equals(serviceName) && equals(this.subServiceName, subServiceName)) {
             return principalNames;
         }
diff --git a/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapper.java b/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapper.java
index 8431d7e..303c2d6 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapper.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapper.java
@@ -18,6 +18,8 @@
  */
 package org.apache.sling.serviceusermapping;
 
+import java.util.List;
+
 import org.osgi.annotation.versioning.ProviderType;
 import org.osgi.framework.Bundle;
 
@@ -57,33 +59,46 @@ import org.osgi.framework.Bundle;
 @ProviderType
 public interface ServiceUserMapper {
 
-    /**
-     * Returns the ID of a user to access the data store on behalf of the
-     * service.
-     *
-     * @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 user to use to provide access to the resources for
-     *         the service. This may be {@code null} if no particular user can
-     *         be derived for the service identified by the bundle and the
-     *         optional {@code serviceInfo}.
-     */
-    String getServiceUserID(Bundle bundle, String subServiceName);
+	/**
+	 * Returns the ID of a user to access the data store on behalf of the
+	 * service.
+	 *
+	 * @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 user to use to provide access to the resources for
+	 *         the service. This may be {@code null} if no particular user can
+	 *         be derived for the service identified by the bundle and the
+	 *         optional {@code serviceInfo}.
+	 */
+	String getServiceUserID(Bundle bundle, String subServiceName);
+
+	/**
+	 * Returns the principal names to access the data store on behalf of the
+	 * service.
+	 *
+	 * @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 principal names to use to provide access to the resources for
+	 *         the service. This may be {@code null} if no mapping has been
+	 *         defined for the service identified by the bundle and the optional
+	 *         {@code serviceInfo} or if no principal names have been specified
+	 *         with the mapping. In this case
+	 *         {@link #getServiceUserID(Bundle, String)} should be used instead.
+	 */
+	Iterable<String> getServicePrincipalNames(Bundle bundle, String subServiceName);
 
-    /**
-     * Returns the principal names to access the data store on behalf of the
-     * service.
-     *
-     * @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 principal names to use to provide access to the resources for
-     *         the service. This may be {@code null} if no mapping has been defined
-     *         for the service identified by the bundle and the optional {@code serviceInfo}
-     *         or if no principal names have been specified with the mapping.
-     *         In this case {@link #getServiceUserID(Bundle, String)} should be used instead.
-     */
-    Iterable<String> getServicePrincipalNames(Bundle bundle, String subServiceName);
+	/**
+	 * Returns a list of all of the active mappings in the Service User Mapper.
+	 * 
+	 * @return A list of the currently active mapped Service users
+	 */
+	List<Mapping> getActiveMappings();
 }
diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/MappingConfigAmendment.java b/src/main/java/org/apache/sling/serviceusermapping/impl/MappingConfigAmendment.java
index 60a425d..7db359a 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/impl/MappingConfigAmendment.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/impl/MappingConfigAmendment.java
@@ -20,6 +20,7 @@ package org.apache.sling.serviceusermapping.impl;
 
 import java.util.ArrayList;
 
+import org.apache.sling.serviceusermapping.Mapping;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.ConfigurationPolicy;
diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/MappingInventoryPrinter.java b/src/main/java/org/apache/sling/serviceusermapping/impl/MappingInventoryPrinter.java
index 8f32898..821a72c 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/impl/MappingInventoryPrinter.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/impl/MappingInventoryPrinter.java
@@ -30,6 +30,7 @@ import java.util.TreeMap;
 import org.apache.felix.inventory.Format;
 import org.apache.felix.inventory.InventoryPrinter;
 import org.apache.felix.utils.json.JSONWriter;
+import org.apache.sling.serviceusermapping.Mapping;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
 
diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilter.java b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilter.java
index a8b0719..bdf794c 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilter.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilter.java
@@ -23,6 +23,7 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
 
+import org.apache.sling.serviceusermapping.Mapping;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceEvent;
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 a963b95..7fb23e4 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java
@@ -35,6 +35,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
+import org.apache.sling.serviceusermapping.Mapping;
 import org.apache.sling.serviceusermapping.ServicePrincipalsValidator;
 import org.apache.sling.serviceusermapping.ServiceUserMapped;
 import org.apache.sling.serviceusermapping.ServiceUserMapper;
@@ -500,7 +501,7 @@ public class ServiceUserMapperImpl implements ServiceUserMapper {
         return bundle.getSymbolicName();
     }
 
-    List<Mapping> getActiveMappings() {
+    public List<Mapping> getActiveMappings() {
         return Collections.unmodifiableList(Arrays.asList(activeMappings));
     }
 
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 1ee3078..547a6af 100644
--- a/src/main/java/org/apache/sling/serviceusermapping/package-info.java
+++ b/src/main/java/org/apache/sling/serviceusermapping/package-info.java
@@ -17,6 +17,6 @@
  * under the License.
  */
 
-@org.osgi.annotation.versioning.Version("1.3.0")
+@org.osgi.annotation.versioning.Version("1.4.0")
 package org.apache.sling.serviceusermapping;
 
diff --git a/src/test/java/org/apache/sling/serviceusermapping/impl/MappingTest.java b/src/test/java/org/apache/sling/serviceusermapping/impl/MappingTest.java
index 2ade43e..423de1b 100644
--- a/src/test/java/org/apache/sling/serviceusermapping/impl/MappingTest.java
+++ b/src/test/java/org/apache/sling/serviceusermapping/impl/MappingTest.java
@@ -23,6 +23,8 @@ import java.util.Arrays;
 import java.util.Set;
 
 import junit.framework.TestCase;
+
+import org.apache.sling.serviceusermapping.Mapping;
 import org.junit.Test;
 
 public class MappingTest {
diff --git a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilterTest.java b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilterTest.java
index 9f12426..e95ef7e 100644
--- a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilterTest.java
+++ b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilterTest.java
@@ -21,6 +21,8 @@ package org.apache.sling.serviceusermapping.impl;
 
 
 import junit.framework.TestCase;
+
+import org.apache.sling.serviceusermapping.Mapping;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.