feat(oidc): Adding support for extracting single string groups claim (#4419)

This commit is contained in:
John Joyce 2022-03-15 17:41:19 -07:00 committed by GitHub
parent 86f240769f
commit 11f809abd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -245,8 +245,22 @@ public class OidcCallbackLogic extends DefaultCallbackLogic<Result, PlayWebConte
if (profile.containsAttribute(groupsClaimName)) {
try {
final List<CorpGroupSnapshot> groupSnapshots = new ArrayList<>();
// We found some groups. Note that we assume it is an array of strings!
final Collection<String> groupNames = (Collection<String>) profile.getAttribute(groupsClaimName, Collection.class);
final Collection<String> groupNames;
final Object groupAttribute = profile.getAttribute(groupsClaimName);
if (groupAttribute instanceof Collection) {
// List of group names
groupNames = (Collection<String>) profile.getAttribute(groupsClaimName, Collection.class);
} else if (groupAttribute instanceof String) {
// Single group name
groupNames = Collections.singleton(profile.getAttribute(groupsClaimName, String.class));
} else {
log.error(String.format("Failed to parse OIDC group claim with name %s. Unknown type %s provided.",
groupsClaimName,
groupAttribute.getClass()));
// Return empty list. Do not throw.
return Collections.emptyList();
}
for (String groupName : groupNames) {
// Create a basic CorpGroupSnapshot from the information.
try {