From 17b60c2886692798c06418e2f4d04c63f971be3c Mon Sep 17 00:00:00 2001 From: uhensler <none@none> Date: Fri, 11 Aug 2017 08:18:48 +0200 Subject: [PATCH] OO-2947: Parse all attributes --- .../manager/ShibbolethAttributes.java | 23 ++++--------------- .../manager/ShibbolethAttributesTest.java | 1 + 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/olat/shibboleth/manager/ShibbolethAttributes.java b/src/main/java/org/olat/shibboleth/manager/ShibbolethAttributes.java index cace531e786..0c4446614fa 100644 --- a/src/main/java/org/olat/shibboleth/manager/ShibbolethAttributes.java +++ b/src/main/java/org/olat/shibboleth/manager/ShibbolethAttributes.java @@ -19,6 +19,7 @@ */ package org.olat.shibboleth.manager; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -53,29 +54,15 @@ public class ShibbolethAttributes { private DifferenceChecker differenceChecker; public void init(Map<String, String> attributes) { - Map<String, String> attributesCopy = new HashMap<>(attributes); - - // Get and parse all mapped attributes even when Shibboleth does not - // deliver the attribute. It is to ensure the null values are parsed as - // well as the base for the later synchronization. - for (Entry<String, String> attribute : getUserMappingEntrySet()) { - String attributeName = attribute.getKey(); - String attributeValue = attributesCopy.remove(attributeName); - ShibbolethAttributeHandler handler = getAttributeHandler(attributeName); - String parsedValue = handler.parse(attributeValue); - shibbolethMap.put(attributeName, parsedValue); - } + Collection<String> shibbolethAttributeNames = shibbolethModule.getShibbolethAttributeNames(); + shibbolethMap = new HashMap<>(shibbolethAttributeNames.size()); - // Get and parse the not mapped but delivered attributes to ensure that - // all attributes are available e.g. for the AttributeTranslator. - for (Entry<String, String> attribute : attributesCopy.entrySet()) { - String attributeName = attribute.getKey(); - String attributeValue = attribute.getValue(); + for (String attributeName : shibbolethAttributeNames) { + String attributeValue = attributes.get(attributeName); ShibbolethAttributeHandler handler = getAttributeHandler(attributeName); String parsedValue = handler.parse(attributeValue); shibbolethMap.put(attributeName, parsedValue); } - } private ShibbolethAttributeHandler getAttributeHandler(String attributeName) { diff --git a/src/test/java/org/olat/shibboleth/manager/ShibbolethAttributesTest.java b/src/test/java/org/olat/shibboleth/manager/ShibbolethAttributesTest.java index c8a24bea53a..a2c158d39c2 100644 --- a/src/test/java/org/olat/shibboleth/manager/ShibbolethAttributesTest.java +++ b/src/test/java/org/olat/shibboleth/manager/ShibbolethAttributesTest.java @@ -90,6 +90,7 @@ public class ShibbolethAttributesTest { ReflectionTestUtils.setField(sut, "shibbolethModule", shibbolethModuleMock); Map<String, String> shibbolethUserMapping = initUserMapping(); when(shibbolethModuleMock.getUserMapping()).thenReturn(shibbolethUserMapping); + when(shibbolethModuleMock.getShibbolethAttributeNames()).thenReturn(initShibbolethMap().keySet()); when(shibbolethModuleMock.getUIDAttributeName()).thenReturn(SHIB_UID_KEY); when(shibbolethModuleMock.getPreferredLanguageAttributeName()).thenReturn(SHIB_LANG_KEY); -- GitLab