[java-metadata-aggregator] branch master updated: MDA-156 add identifier strategy for interfederation use cases

Ian Young ian at iay.org.uk
Fri Dec 11 09:10:10 EST 2015


This is an automated email from the git hooks/post-receive script.

iay pushed a commit to branch master
in repository java-metadata-aggregator.

The following commit(s) were added to refs/heads/master by this push:
       new  9cc4c69   MDA-156 add identifier strategy for interfederation use cases
9cc4c69 is described below

commit 9cc4c69e0aaef65326468091b6cc0282f422014e
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Fri Dec 11 14:03:03 2015 +0000

    MDA-156 add identifier strategy for interfederation use cases
---
 ...bstractCompositeItemIdentificationStrategy.java |   2 +-
 ...trationAuthorityItemIdentificationStrategy.java | 135 +++++++++++++++++++++
 ...ionAuthorityItemIdentificationStrategyTest.java | 109 +++++++++++++++++
 3 files changed, 245 insertions(+), 1 deletion(-)

diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/AbstractCompositeItemIdentificationStrategy.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/AbstractCompositeItemIdentificationStrategy.java
index 311125a..394229f 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/AbstractCompositeItemIdentificationStrategy.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/AbstractCompositeItemIdentificationStrategy.java
@@ -91,7 +91,7 @@ public abstract class AbstractCompositeItemIdentificationStrategy implements Ite
         
         final String extra = getExtraIdentifier(item);
         if (extra != null) {
-            res.append("( ");
+            res.append(" (");
             res.append(extra);
             res.append(")");
         }
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdrpi/RegistrationAuthorityItemIdentificationStrategy.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdrpi/RegistrationAuthorityItemIdentificationStrategy.java
new file mode 100644
index 0000000..7347a3c
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdrpi/RegistrationAuthorityItemIdentificationStrategy.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development, 
+ * Inc. (UCAID) under one or more contributor license agreements.  See the 
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID 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 net.shibboleth.metadata.dom.saml.mdrpi;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.ThreadSafe;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+import net.shibboleth.metadata.FirstItemIdItemIdentificationStrategy;
+import net.shibboleth.metadata.Item;
+
+/**
+ * Item identification strategy for interfederation use cases.
+ * 
+ * The basic identifier is taken from {@link FirstItemIdItemIdentificationStrategy}.
+ * 
+ * The extra identifier is based on a {@link RegistrationAuthority} if one of
+ * those is present.  The extra identifier is omitted if it is present in a
+ * specified blacklist, and it can be mapped to a simpler value for display if
+ * desired.
+ */
+ at ThreadSafe
+public class RegistrationAuthorityItemIdentificationStrategy extends FirstItemIdItemIdentificationStrategy {
+
+    /**
+     * Set of registration authorities to be ignored.
+     */
+    @Nonnull private Set<String> ignoredRegistrationAuthorities = Collections.emptySet();
+    
+    /**
+     * Replacement display names for registration authorities.
+     */
+    @Nonnull private Map<String, String> registrationAuthorityDisplayNames = Collections.emptyMap();
+    
+    /**
+     * Returns the set of registration authorities we are ignoring.
+     * 
+     * @return {@link Set} of registration authority names.
+     */
+    @Nonnull public Collection<String> getIgnoredRegistrationAuthorities() {
+        return ignoredRegistrationAuthorities;
+    }
+
+    /**
+     * Set the set of registration authorities we are ignoring.
+     * 
+     * @param registrars {@link Set} of registration authority names to ignore.
+     */
+    public void setIgnoredRegistrationAuthorities(@Nullable final Collection<String> registrars) {
+        if (registrars == null || registrars.isEmpty()) {
+            ignoredRegistrationAuthorities = Collections.emptySet();
+        } else {
+            ignoredRegistrationAuthorities = ImmutableSet.copyOf(registrars);
+        }
+    }
+
+    /**
+     * Returns the map of display names for registration authorities.
+     * 
+     * @return {@link Map} of display names for authorities.
+     */
+    public Map<String, String> getRegistrationAuthorityDisplayNames() {
+        return registrationAuthorityDisplayNames;
+    }
+
+    /**
+     * Sets the map of display names for registration authorities.
+     * 
+     * @param names {@link Map} of display names for registration authorities.
+     */
+    public void setRegistrationAuthorityDisplayNames(@Nullable final Map<String, String> names) {
+        if (names == null || names.isEmpty()) {
+            registrationAuthorityDisplayNames = Collections.emptyMap();
+        } else {
+            registrationAuthorityDisplayNames = ImmutableMap.copyOf(names);
+        }
+    }
+    
+    /**
+     * Derive a display name for an entity's registration authority, if it has one.
+     * 
+     * @param item {@link Item} to derive an identifier for.
+     * 
+     * @return registration authority name, or <code>null</code>.
+     */
+    @Override
+    @Nullable protected String getExtraIdentifier(@Nonnull final Item<?> item) {
+        final List<RegistrationAuthority> regAuths = item.getItemMetadata().get(RegistrationAuthority.class);
+        
+        // nothing to return if there isn't a registration authority
+        if (regAuths.isEmpty()) {
+            return null;
+        }
+        
+        final String regAuth = regAuths.get(0).getRegistrationAuthority();
+        
+        // nothing to return if it's an ignored authority
+        if (ignoredRegistrationAuthorities.contains(regAuth)) {
+            return null;
+        }
+        
+        // handle mapping it to a simpler form if that's available
+        final String displayName = registrationAuthorityDisplayNames.get(regAuth);
+        if (displayName != null) {
+            return displayName;
+        } else {
+            return regAuth;
+        }
+    }
+
+}
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdrpi/RegistrationAuthorityItemIdentificationStrategyTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdrpi/RegistrationAuthorityItemIdentificationStrategyTest.java
new file mode 100644
index 0000000..0253db2
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdrpi/RegistrationAuthorityItemIdentificationStrategyTest.java
@@ -0,0 +1,109 @@
+
+package net.shibboleth.metadata.dom.saml.mdrpi;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.ItemId;
+import net.shibboleth.metadata.MockItem;
+
+public class RegistrationAuthorityItemIdentificationStrategyTest {
+
+    private RegistrationAuthorityItemIdentificationStrategy makeStrat() {
+        final RegistrationAuthorityItemIdentificationStrategy strat = new RegistrationAuthorityItemIdentificationStrategy();
+        strat.setNoItemIdIdentifier("mu");
+        return strat;
+    }
+    
+    @Test
+    public void base_unidentified() {
+        final RegistrationAuthorityItemIdentificationStrategy strat = new RegistrationAuthorityItemIdentificationStrategy();
+        Assert.assertEquals(strat.getNoItemIdIdentifier(), "unidentified");
+        final Item<String> item = new MockItem("item");
+        final String res = strat.getItemIdentifier(item);
+        Assert.assertEquals(res, "unidentified");
+    }
+    
+    @Test
+    public void base_setNoItemIdIdentifier() {
+        final RegistrationAuthorityItemIdentificationStrategy strat = makeStrat();
+        strat.setNoItemIdIdentifier("mu2");
+        Assert.assertEquals(strat.getNoItemIdIdentifier(), "mu2");
+        final Item<String> item = new MockItem("item");
+        final String res = strat.getItemIdentifier(item);
+        Assert.assertEquals(res, "mu2");
+    }
+    
+    @Test
+    public void base_oneIdentifier() {
+        final RegistrationAuthorityItemIdentificationStrategy strat = makeStrat();
+        final Item<String> item = new MockItem("item");
+        item.getItemMetadata().put(new ItemId("id"));
+        final String res = strat.getItemIdentifier(item);
+        Assert.assertEquals(res, "id");
+    }
+
+    @Test
+    public void base_twoIdentifiers() {
+        final RegistrationAuthorityItemIdentificationStrategy strat = makeStrat();
+        final Item<String> item = new MockItem("item");
+        item.getItemMetadata().put(new ItemId("first"));
+        item.getItemMetadata().put(new ItemId("second"));
+        final String res = strat.getItemIdentifier(item);
+        Assert.assertEquals(res, "first");
+    }
+
+    @Test
+    public void getItemIdentifier() {
+        final RegistrationAuthorityItemIdentificationStrategy strat = makeStrat();
+        
+        final Item<String> item2 = new MockItem("item 2");
+        Assert.assertEquals(strat.getItemIdentifier(item2), "mu");
+        item2.getItemMetadata().put(new ItemId("item-id"));
+        Assert.assertEquals(strat.getItemIdentifier(item2), "item-id");
+    }
+    
+    @Test
+    public void withRegistrationAuthority() throws Exception {
+        final RegistrationAuthorityItemIdentificationStrategy strat = makeStrat();
+        final Item<String> item = new MockItem("present");
+        item.getItemMetadata().put(new ItemId("uk002232"));
+        item.getItemMetadata().put(new RegistrationAuthority("http://ukfederation.org.uk"));
+        Assert.assertEquals(strat.getItemIdentifier(item), "uk002232 (http://ukfederation.org.uk)");
+    }
+
+    @Test
+    public void ignoredAuthority() throws Exception {
+        final RegistrationAuthorityItemIdentificationStrategy strat = makeStrat();
+        final Item<String> item = new MockItem("present");
+        item.getItemMetadata().put(new ItemId("uk002232"));
+        item.getItemMetadata().put(new RegistrationAuthority("http://ukfederation.org.uk"));
+
+        final Set<String> auths = new HashSet<>();
+        auths.add("http://ukfederation.org.uk");
+        strat.setIgnoredRegistrationAuthorities(auths);
+        
+        Assert.assertEquals(strat.getItemIdentifier(item), "uk002232");
+    }
+    
+    @Test
+    public void mappedAuthority() throws Exception {
+        final RegistrationAuthorityItemIdentificationStrategy strat = makeStrat();
+        final Map<String, String> nameMap = new HashMap<>();
+        nameMap.put("http://ukfederation.org.uk", "UKf");
+        strat.setRegistrationAuthorityDisplayNames(nameMap);
+        
+        final Item<String> item = new MockItem("present");
+        item.getItemMetadata().put(new ItemId("uk002232"));
+        item.getItemMetadata().put(new RegistrationAuthority("http://ukfederation.org.uk"));
+        
+        Assert.assertEquals(strat.getItemIdentifier(item), "uk002232 (UKf)");
+    }
+    
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list