From 749a3a18710928677f2f49a9a0ae3b821170daae Mon Sep 17 00:00:00 2001 From: Ethan Cartwright Date: Thu, 21 Dec 2023 09:44:30 -0500 Subject: [PATCH] address PR comments --- .../app/auth/sso/oidc/OidcCallbackLogic.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/datahub-frontend/app/auth/sso/oidc/OidcCallbackLogic.java b/datahub-frontend/app/auth/sso/oidc/OidcCallbackLogic.java index 8f535374c6365..4fbf1d60f095b 100644 --- a/datahub-frontend/app/auth/sso/oidc/OidcCallbackLogic.java +++ b/datahub-frontend/app/auth/sso/oidc/OidcCallbackLogic.java @@ -10,6 +10,9 @@ import auth.sso.SsoManager; import client.AuthServiceClient; import com.datahub.authentication.Authentication; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import com.linkedin.common.AuditStamp; import com.linkedin.common.CorpGroupUrnArray; import com.linkedin.common.CorpuserUrnArray; @@ -66,9 +69,6 @@ import org.pac4j.core.util.Pac4jConstants; import org.pac4j.play.PlayWebContext; import play.mvc.Result; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; /** @@ -304,16 +304,19 @@ private CorpUserSnapshot extractUser(CorpuserUrn urn, CommonProfile profile) { return corpUserSnapshot; } - public static List getGroupsClaimNames (OidcConfigs configs) { - List groupsClaimNames = new ArrayList<>(); + public static List getGroupsClaimNames(OidcConfigs configs) { + List groupsClaimNames; String rawGroupClaimsNames = configs.getGroupsClaimName(); - if (rawGroupClaimsNames.startsWith("[") && rawGroupClaimsNames.endsWith("]")){ - Type listType = new TypeToken>(){}.getType(); - groupsClaimNames = new Gson().fromJson(rawGroupClaimsNames, listType); - } else { - groupsClaimNames = new ArrayList(Arrays.asList(rawGroupClaimsNames.split(","))) - .stream().map(String::trim).collect(Collectors.toList()); + ObjectMapper objectMapper = new ObjectMapper(); + + try { + groupsClaimNames = objectMapper.readValue(rawGroupClaimsNames, new TypeReference>(){}); + } catch (JsonProcessingException e) { + groupsClaimNames = Arrays.stream(rawGroupClaimsNames.split(",")) + .map(String::trim) + .collect(Collectors.toList()); } + return groupsClaimNames; }