Use pac4j attribute extraction API Delegate attribute extraction to BasicUserProfile.extractAttributeValues, which is available in pac4j 6.5.9 and preserves the existing handling of strings, arrays, lists, and missing attributes. Remove the duplicate helper and its obsolete TODOs. Release-Notes: skip Change-Id: I4139cfecb6ae6381215f4456586289103afe7c2a
diff --git a/src/main/java/com/googlesource/gerrit/plugins/saml/SamlWebFilter.java b/src/main/java/com/googlesource/gerrit/plugins/saml/SamlWebFilter.java index b4b1c7b..8250a29 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/saml/SamlWebFilter.java +++ b/src/main/java/com/googlesource/gerrit/plugins/saml/SamlWebFilter.java
@@ -29,8 +29,6 @@ import com.google.inject.ProvisionException; import com.google.inject.Singleton; import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; import java.util.List; @@ -254,28 +252,13 @@ } private static String getAttribute(SAML2Profile user, String attrName) { - // TODO(davido): Replace with the invocation from upstream method. - List<String> names = extractAttributeValues(user, attrName); + List<String> names = user.extractAttributeValues(attrName); if (names != null && !names.isEmpty()) { return names.get(0); } return null; } - // TODO(davido): Remove if getAttribute() uses the upstream method. - private static List<String> extractAttributeValues(SAML2Profile user, String attrName) { - final Object value = user.getAttribute(attrName); - if (value instanceof String) { - return Collections.singletonList((String) value); - } else if (value instanceof String[]) { - return Arrays.asList((String[]) value); - } else if (value instanceof List) { - return (List<String>) value; - } else { - return null; - } - } - private static String getAttributeOrElseId(SAML2Profile user, String attrName) { String value = getAttribute(user, attrName); if (value != null) {