fix(oidc): Tolerate null emails (#3330)

This commit is contained in:
John Joyce 2021-10-05 19:30:51 -07:00 committed by GitHub
parent 61ba3cf578
commit fe589a58b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,7 +109,7 @@ public class OidcCallbackLogic extends DefaultCallbackLogic<Result, PlayWebConte
try { try {
// If just-in-time User Provisioning is enabled, try to create the DataHub user if it does not exist. // If just-in-time User Provisioning is enabled, try to create the DataHub user if it does not exist.
if (oidcConfigs.isJitProvisioningEnabled()) { if (oidcConfigs.isJitProvisioningEnabled()) {
log.debug("Just-in-time provisioning is enabled. Beginning provisioning proces..."); log.debug("Just-in-time provisioning is enabled. Beginning provisioning process...");
CorpUserSnapshot extractedUser = extractUser(corpUserUrn, profile); CorpUserSnapshot extractedUser = extractUser(corpUserUrn, profile);
if (oidcConfigs.isExtractGroupsEnabled()) { if (oidcConfigs.isExtractGroupsEnabled()) {
// Extract groups & provision them. // Extract groups & provision them.
@ -153,8 +153,7 @@ public class OidcCallbackLogic extends DefaultCallbackLogic<Result, PlayWebConte
final Optional<String> mappedUserName = extractRegexGroup( final Optional<String> mappedUserName = extractRegexGroup(
oidcConfigs.getUserNameClaimRegex(), oidcConfigs.getUserNameClaimRegex(),
(String) profile.getAttribute(oidcConfigs.getUserNameClaim()) userNameClaim);
);
return mappedUserName.orElseThrow(() -> return mappedUserName.orElseThrow(() ->
new RuntimeException(String.format("Failed to extract DataHub username from username claim %s using regex %s. Profile: %s", new RuntimeException(String.format("Failed to extract DataHub username from username claim %s using regex %s. Profile: %s",
@ -185,7 +184,7 @@ public class OidcCallbackLogic extends DefaultCallbackLogic<Result, PlayWebConte
userInfo.setFirstName(firstName, SetMode.IGNORE_NULL); userInfo.setFirstName(firstName, SetMode.IGNORE_NULL);
userInfo.setLastName(lastName, SetMode.IGNORE_NULL); userInfo.setLastName(lastName, SetMode.IGNORE_NULL);
userInfo.setFullName(String.format("%s %s", firstName, lastName), SetMode.IGNORE_NULL); userInfo.setFullName(String.format("%s %s", firstName, lastName), SetMode.IGNORE_NULL);
userInfo.setEmail(email); userInfo.setEmail(email, SetMode.IGNORE_NULL);
// If there is a display name, use it. Otherwise fall back to full name. // If there is a display name, use it. Otherwise fall back to full name.
userInfo.setDisplayName(displayName == null ? userInfo.getFullName() : displayName, SetMode.IGNORE_NULL); userInfo.setDisplayName(displayName == null ? userInfo.getFullName() : displayName, SetMode.IGNORE_NULL);