[java-identity-provider] 05/11: IDP-1464 Introduce a processed UI class for ACS
Rod Widdowson
rdw at steadingsoftware.com
Tue Jun 11 09:38:23 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=2534f5517e75b09895a4eae100bcc3376d8059f1
commit 2534f5517e75b09895a4eae100bcc3376d8059f1
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Jun 10 14:44:58 2019 +0100
IDP-1464 Introduce a processed UI class for ACS
https://issues.shibboleth.net/jira/browse/IDP-1464
This means making the ServiceName and ServiceDescription
available as a Map<Locale,String>
---
.../shibboleth/idp/saml/metadata/ACSUIInfo.java | 98 ++++++++++++++++++++++
.../idp/saml/metadata/ACSUIInfoTest.java | 46 ++++++++++
idp-saml-api/src/test/resources/ACSUIInfo.xml | 8 ++
3 files changed, 152 insertions(+)
diff --git a/idp-saml-api/src/main/java/net/shibboleth/idp/saml/metadata/ACSUIInfo.java b/idp-saml-api/src/main/java/net/shibboleth/idp/saml/metadata/ACSUIInfo.java
new file mode 100644
index 0000000..d263ad4
--- /dev/null
+++ b/idp-saml-api/src/main/java/net/shibboleth/idp/saml/metadata/ACSUIInfo.java
@@ -0,0 +1,98 @@
+/*
+ * 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.AttributeConsumingService;
+import org.opensaml.saml.saml2.metadata.LocalizedName;
+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 AttributeConsumingService} suitable for display purposes. */
+public class ACSUIInfo {
+
+ /** logger. */
+ private static final Logger LOG = LoggerFactory.getLogger(ACSUIInfo.class);
+
+ /** The Service Names as a map from locale to actual value.*/
+ @Nonnull @Unmodifiable private final Map<Locale, String> serviceNames;
+
+ /** The Service Descriptions as a map from locale to actual value.*/
+ @Nonnull @Unmodifiable private final Map<Locale, String> serviceDescriptions;
+
+ /** 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;
+ }
+ };
+
+ /**
+ * Constructor.
+ *
+ * @param acs The OpenSaml AssertionConsumingService to convert.
+ */
+ public ACSUIInfo(@Nonnull final AttributeConsumingService acs) {
+
+ serviceNames = acs.getNames().
+ stream().
+ filter(nullLanguageString).
+ collect(Collectors.toUnmodifiableMap(
+ serviceName -> Locale.forLanguageTag(serviceName.getXMLLang()),
+ serviceName -> serviceName.getValue()));
+ serviceDescriptions = acs.
+ getDescriptions().
+ stream().
+ filter(nullLanguageString).
+ collect(Collectors.toUnmodifiableMap(
+ description -> Locale.forLanguageTag(description.getXMLLang()),
+ description -> description.getValue()));
+ }
+
+ /**
+ * Get the Display Names as a map from locale to actual value.
+ *
+ * @return the display names
+ */
+ @Nonnull @Unmodifiable public Map<Locale, String> getServiceNames() {
+ return serviceNames;
+ }
+
+ /**
+ * Return the descriptions as a map from locale to actual value.
+ *
+ * @return the descriptions names (if any)
+ */
+ @Nonnull @Unmodifiable public Map<Locale, String> getServiceDescriptions() {
+ return serviceDescriptions;
+ }
+
+}
diff --git a/idp-saml-api/src/test/java/net/shibboleth/idp/saml/metadata/ACSUIInfoTest.java b/idp-saml-api/src/test/java/net/shibboleth/idp/saml/metadata/ACSUIInfoTest.java
new file mode 100644
index 0000000..79a99f9
--- /dev/null
+++ b/idp-saml-api/src/test/java/net/shibboleth/idp/saml/metadata/ACSUIInfoTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.AttributeConsumingService;
+import org.testng.annotations.Test;
+
+import net.shibboleth.utilities.java.support.xml.XMLParserException;
+
+/**
+ * test for the {@link ACSUIInfo}.
+ */
+public class ACSUIInfoTest extends XMLObjectBaseTestCase {
+
+ @Test public void test() throws XMLParserException, UnmarshallingException {
+
+ final AttributeConsumingService acs = unmarshallElement("/ACSUIInfo.xml", true);
+ final ACSUIInfo info = new ACSUIInfo(acs);
+
+ assertEquals(info.getServiceNames().size(), 2);
+ assertEquals(info.getServiceNames().get(Locale.forLanguageTag("en")), "ServiceName");
+ assertEquals(info.getServiceDescriptions().size(), 1);
+
+ }
+}
diff --git a/idp-saml-api/src/test/resources/ACSUIInfo.xml b/idp-saml-api/src/test/resources/ACSUIInfo.xml
new file mode 100644
index 0000000..e03aa8b
--- /dev/null
+++ b/idp-saml-api/src/test/resources/ACSUIInfo.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<AttributeConsumingService 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">
+ <ServiceName xml:lang="fr">Nom D'un Chien</ServiceName>
+ <ServiceName xml:lang="en">ServiceName</ServiceName>
+ <ServiceDescription xml:lang="de">ServiceDesc</ServiceDescription>
+</AttributeConsumingService>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list