[java-identity-provider] 11/11: Fix duplicate locale bug in Mapper parsing.

Rod Widdowson rdw at steadingsoftware.com
Tue Jun 11 09:38:29 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=227ca82dec79a8d70f3936c5ba8ea1d68360d7d4

commit 227ca82dec79a8d70f3936c5ba8ea1d68360d7d4
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Jun 11 13:31:48 2019 +0100

    Fix duplicate locale bug in Mapper parsing.
    
    If the default locale is also mentioned in the definition
    we can only add the associated text once (first in wins).
    
    Adjust the tests to take account of this.
---
 .../idp/attribute/transcoding/TranscodingRule.java   | 19 +++++++++++++++----
 .../resolver/spring/AttributeMapperTest.java         | 20 ++++++++++++++------
 .../resolver/spring/mapperTest-attributes.xml        |  2 +-
 3 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/TranscodingRule.java b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/TranscodingRule.java
index 8a8a944..a6258b1 100644
--- a/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/TranscodingRule.java
+++ b/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/transcoding/TranscodingRule.java
@@ -20,6 +20,7 @@ package net.shibboleth.idp.attribute.transcoding;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
@@ -177,6 +178,7 @@ public class TranscodingRule {
     private void processDisplayNames() {
         
         final ImmutableMap.Builder<Locale,String> builder = ImmutableMap.builder();
+        final HashSet<Locale> inserted = new HashSet<Locale>();
         
         for (final Map.Entry<String,Object> entry : rule.entrySet()) {
             if (entry.getValue() instanceof String
@@ -184,10 +186,14 @@ public class TranscodingRule {
                 
                 final String lang = StringSupport.trimOrNull(
                         entry.getKey().substring(AttributeTranscoderRegistry.PROP_DISPLAY_NAME.length()));
+                Locale locale = null;
                 if (lang == null) {
-                    builder.put(Locale.getDefault(), (String) entry.getValue());
+                    locale = Locale.getDefault();
                 } else if (lang.startsWith(".")) {
-                    builder.put(Locale.forLanguageTag(lang.substring(1)), (String) entry.getValue());
+                    locale = Locale.forLanguageTag(lang.substring(1));
+                }
+                if (locale != null && inserted.add(locale)) {
+                    builder.put(locale, (String) entry.getValue());
                 }
             }
         }
@@ -202,6 +208,7 @@ public class TranscodingRule {
     private void processDescriptions() {
         
         final ImmutableMap.Builder<Locale,String> builder = ImmutableMap.builder();
+        final HashSet<Locale> inserted = new HashSet<Locale>();
         
         for (final Map.Entry<String,Object> entry : rule.entrySet()) {
             if (entry.getValue() instanceof String
@@ -209,10 +216,14 @@ public class TranscodingRule {
                 
                 final String lang = StringSupport.trimOrNull(
                         entry.getKey().substring(AttributeTranscoderRegistry.PROP_DESCRIPTION.length()));
+                Locale locale = null;
                 if (lang == null) {
-                    builder.put(Locale.getDefault(), (String) entry.getValue());
+                    locale = Locale.getDefault();
                 } else if (lang.startsWith(".")) {
-                    builder.put(Locale.forLanguageTag(lang.substring(1)), (String) entry.getValue());
+                    locale = Locale.forLanguageTag(lang.substring(1));
+                }
+                if (locale != null && inserted.add(locale)) {
+                    builder.put(locale, (String) entry.getValue());
                 }
             }
         }
diff --git a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeMapperTest.java b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeMapperTest.java
index 44c8170..47db056 100644
--- a/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeMapperTest.java
+++ b/idp-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeMapperTest.java
@@ -103,22 +103,30 @@ public class AttributeMapperTest extends OpenSAMLInitBaseTestCase {
             assertEquals(rule.get(SAML2ScopedStringAttributeTranscoder.PROP_SCOPE_DELIMITER, String.class), "#");
 
             Map<Locale,String> names = rule.getDisplayNames();
-            assertEquals(names.size(), 2);
-            assertEquals(names.get(Locale.getDefault()), "Color");
+            if (Locale.UK.equals(Locale.getDefault())) {
+                assertEquals(names.size(), 1);
+            } else {
+                assertEquals(names.size(), 2);
+                assertEquals(names.get(Locale.getDefault()), "Color");
+            }
             assertEquals(names.get(Locale.UK), "Colour");
             
             Map<Locale,String> descs = rule.getDescriptions();
             assertEquals(descs.size(), 1);
-            assertEquals(descs.get(Locale.CANADA_FRENCH), "Le Color, eh?");
+            assertEquals(descs.get(Locale.CANADA_FRENCH), "Le Color");
             
             names = serviceableComponent.getComponent().getDisplayNames(idpattr);
-            assertEquals(names.size(), 2);
-            assertEquals(names.get(Locale.getDefault()), "Color");
+            if (Locale.UK.equals(Locale.getDefault())) {
+                assertEquals(names.size(), 1);
+            } else {
+                assertEquals(names.size(), 2);
+                assertEquals(names.get(Locale.getDefault()), "Color");
+            }
             assertEquals(names.get(Locale.UK), "Colour");
             
             descs = serviceableComponent.getComponent().getDescriptions(idpattr);
             assertEquals(descs.size(), 1);
-            assertEquals(descs.get(Locale.CANADA_FRENCH), "Le Color, eh?");
+            assertEquals(descs.get(Locale.CANADA_FRENCH), "Le Color");
             
         } finally {
             serviceableComponent.unpinComponent();
diff --git a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/mapperTest-attributes.xml b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/mapperTest-attributes.xml
index 8c52376..2c4c435 100644
--- a/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/mapperTest-attributes.xml
+++ b/idp-attribute-resolver-spring/src/test/resources/net/shibboleth/idp/attribute/resolver/spring/mapperTest-attributes.xml
@@ -47,7 +47,7 @@
         
         <DisplayName>Color</DisplayName>
         <DisplayName xml:lang="en-GB">Colour</DisplayName>
-        <DisplayDescription xml:lang="fr-CA">Le Color, eh?</DisplayDescription>
+        <DisplayDescription xml:lang="fr-CA">Le Color</DisplayDescription>
     </AttributeDefinition>
     
     <AttributeDefinition xsi:type="SAML2NameID" id="eduPersonTID" 

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


More information about the commits mailing list