[java-identity-provider] 07/11: IDP-1464 Introduces a processed UI class for Organization

Rod Widdowson rdw at steadingsoftware.com
Tue Jun 11 09:38:25 EDT 2019


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

rdw pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=cecc1b02b8d6d23d32f675b3412a22309c60cd2e

commit cecc1b02b8d6d23d32f675b3412a22309c60cd2e
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Jun 10 17:13:32 2019 +0100

    IDP-1464 Introduces a processed UI class for Organization
    
    https://issues.shibboleth.net/jira/browse/IDP-1464
    
    This means make the Name, DisplayName and URL available
    as a Map<Locale, String>
---
 .../idp/saml/metadata/OrganizationUIInfo.java      | 131 +++++++++++++++++++++
 .../idp/saml/metadata/OrganizationUIInfoTest.java  |  47 ++++++++
 .../src/test/resources/OrganizationUIInfo.xml      |  10 ++
 3 files changed, 188 insertions(+)

diff --git a/idp-saml-api/src/main/java/net/shibboleth/idp/saml/metadata/OrganizationUIInfo.java b/idp-saml-api/src/main/java/net/shibboleth/idp/saml/metadata/OrganizationUIInfo.java
new file mode 100644
index 0000000..07ed5f2
--- /dev/null
+++ b/idp-saml-api/src/main/java/net/shibboleth/idp/saml/metadata/OrganizationUIInfo.java
@@ -0,0 +1,131 @@
+/*
+ * 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.idp.saml.metadata;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import javax.annotation.Nonnull;
+
+import org.opensaml.saml.saml2.metadata.LocalizedName;
+import org.opensaml.saml.saml2.metadata.LocalizedURI;
+import org.opensaml.saml.saml2.metadata.Organization;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
+
+/**
+ * Class to contain a processed form of the {@link Organization} suitable for display purposes. */
+public class OrganizationUIInfo {
+    
+    /** logger. */
+    private static final Logger LOG = LoggerFactory.getLogger(OrganizationUIInfo.class);
+    
+    /** The Organization Names as a map from locale to actual value.*/ 
+    @Nonnull @Unmodifiable private final Map<Locale, String> organizationNames;
+    
+    /** The Organization Display Names as a map from locale to actual value.*/ 
+    @Nonnull @Unmodifiable private final Map<Locale, String> displayNames;
+       
+    /** The Organization URLs as a map from locale to actual value.*/ 
+    @Nonnull @Unmodifiable private final Map<Locale, String> urls;
+    
+    /** Warning check against a non localized String. */
+    private final Predicate<LocalizedName> nullLanguageString = new Predicate<>() {
+        public boolean test(final LocalizedName u) {
+            if (u.getXMLLang() == null) {
+                LOG.warn("String with value {} has no language associated, ignoring", u.getValue());
+                return false;
+            }
+            return true;
+        }
+    };
+    
+    /** Warning check against a non localized URL. */
+    private final Predicate<LocalizedURI> nullLanguageURL = new Predicate<>() {
+        public boolean test(final LocalizedURI u) {
+            if (u.getXMLLang() == null) {
+                LOG.warn("URI with value {} has no language associated, ignoring", u.getValue());
+                return false;
+            }
+            return true;
+        }
+    };
+    
+    /**
+     * Constructor.
+     *
+     * @param organization The OpenSaml Organization to convert.
+     */
+    public OrganizationUIInfo(@Nonnull final Organization organization) {
+        
+        organizationNames = organization.
+                getOrganizationNames().
+                stream().
+                filter(nullLanguageString).
+                collect(Collectors.toUnmodifiableMap(
+                        serviceName -> Locale.forLanguageTag(serviceName.getXMLLang()), 
+                        serviceName -> serviceName.getValue()));
+        displayNames = organization.
+                getDisplayNames().
+                stream().
+                filter(nullLanguageString).
+                collect(Collectors.toUnmodifiableMap(
+                        description -> Locale.forLanguageTag(description.getXMLLang()), 
+                        description -> description.getValue()));
+        
+        urls = organization.
+                getURLs().
+                stream().
+                filter(nullLanguageURL).
+                collect(Collectors.toUnmodifiableMap(
+                        url -> Locale.forLanguageTag(url.getXMLLang()), 
+                        dn -> dn.getValue()));
+    }
+
+    /** 
+     * Get the Organization Names as a map from locale to actual value.
+     * 
+     * @return the display names
+     */
+    @Nonnull @Unmodifiable public Map<Locale, String> getOrganizationNames() {
+        return organizationNames; 
+    }
+    
+    /**
+     * Return the Organization Display Names as a map from locale to actual value.
+     *
+     * @return the descriptions names (if any)
+     */
+    @Nonnull @Unmodifiable public Map<Locale, String> getOrganizationDisplayNames() {
+        return displayNames;
+    }
+
+    /**
+     * Return the Organization URLs as a map from locale to actual value.
+     *
+     * @return the descriptions names (if any)
+     */
+    @Nonnull @Unmodifiable public Map<Locale, String> getOrganizationUrls() {
+        return urls;
+    }
+
+}
diff --git a/idp-saml-api/src/test/java/net/shibboleth/idp/saml/metadata/OrganizationUIInfoTest.java b/idp-saml-api/src/test/java/net/shibboleth/idp/saml/metadata/OrganizationUIInfoTest.java
new file mode 100644
index 0000000..111217b
--- /dev/null
+++ b/idp-saml-api/src/test/java/net/shibboleth/idp/saml/metadata/OrganizationUIInfoTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.idp.saml.metadata;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.Locale;
+
+import org.opensaml.core.xml.XMLObjectBaseTestCase;
+import org.opensaml.core.xml.io.UnmarshallingException;
+import org.opensaml.saml.saml2.metadata.Organization;
+import org.testng.annotations.Test;
+
+import net.shibboleth.utilities.java.support.xml.XMLParserException;
+
+/**
+ * test for the {@link OrganizationUIInfo}.
+ */
+public class OrganizationUIInfoTest extends XMLObjectBaseTestCase {
+    
+    @Test public void test() throws XMLParserException, UnmarshallingException {
+    
+        final Organization acs = unmarshallElement("/OrganizationUIInfo.xml", true);
+        final OrganizationUIInfo info = new OrganizationUIInfo(acs); 
+        
+        assertEquals(info.getOrganizationNames().size(), 2);
+        assertEquals(info.getOrganizationNames().get(Locale.forLanguageTag("en")), "org");
+        assertEquals(info.getOrganizationDisplayNames().size(), 1);
+        assertEquals(info.getOrganizationUrls().size(), 1);
+        
+    }
+}
diff --git a/idp-saml-api/src/test/resources/OrganizationUIInfo.xml b/idp-saml-api/src/test/resources/OrganizationUIInfo.xml
new file mode 100644
index 0000000..79a0ee9
--- /dev/null
+++ b/idp-saml-api/src/test/resources/OrganizationUIInfo.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Organization xmlns="urn:oasis:names:tc:SAML:2.0:metadata"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="urn:oasis:names:tc:SAML:2.0:metadata
+http://docs.oasis-open.org/security/saml/v2.0/saml-schema-metadata-2.0.xsd" >
+	<OrganizationName xml:lang="en">org</OrganizationName>
+	<OrganizationName xml:lang="fr">gro</OrganizationName>
+	<OrganizationDisplayName xml:lang="en">odn</OrganizationDisplayName>
+	<OrganizationURL xml:lang="en">url</OrganizationURL>
+</Organization>

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


More information about the commits mailing list