From 8c0f1dd2df31230eb8e3341b1cb69dc0b9ea9a0a Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Thu, 19 Dec 2024 13:50:31 -0500 Subject: [PATCH] Hotfix to catch MisconfiguredUserException --- .../usds/simplereport/service/ApiUserService.java | 12 ++++++++---- .../simplereport/service/DbOrgRoleClaimsService.java | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/gov/cdc/usds/simplereport/service/ApiUserService.java b/backend/src/main/java/gov/cdc/usds/simplereport/service/ApiUserService.java index 24d82d63eb..43db5a26e7 100644 --- a/backend/src/main/java/gov/cdc/usds/simplereport/service/ApiUserService.java +++ b/backend/src/main/java/gov/cdc/usds/simplereport/service/ApiUserService.java @@ -730,10 +730,14 @@ private UserInfo consolidateUser(ApiUser apiUser, PartialOktaUser oktaUser) { OrganizationRoles orgRoles = getOrganizationRoles(Optional.ofNullable(oktaClaims), apiUser, isSiteAdmin); - _dbOrgRoleClaimsService.checkOrgRoleClaimsEquality( - List.of(oktaClaims), - List.of(_dbOrgRoleClaimsService.getOrganizationRoleClaims(apiUser)), - apiUser.getLoginEmail()); + try { + _dbOrgRoleClaimsService.checkOrgRoleClaimsEquality( + List.of(oktaClaims), + List.of(_dbOrgRoleClaimsService.getOrganizationRoleClaims(apiUser)), + apiUser.getLoginEmail()); + } catch (MisconfiguredUserException e) { + log.error("Misconfigured organizations in DB for User ID: {}", apiUser.getInternalId()); + } return new UserInfo(apiUser, Optional.of(orgRoles), isSiteAdmin, userStatus); } diff --git a/backend/src/main/java/gov/cdc/usds/simplereport/service/DbOrgRoleClaimsService.java b/backend/src/main/java/gov/cdc/usds/simplereport/service/DbOrgRoleClaimsService.java index 3a3f33cc69..788b07b837 100644 --- a/backend/src/main/java/gov/cdc/usds/simplereport/service/DbOrgRoleClaimsService.java +++ b/backend/src/main/java/gov/cdc/usds/simplereport/service/DbOrgRoleClaimsService.java @@ -47,7 +47,10 @@ public List getOrganizationRoleClaims(String username) { public OrganizationRoleClaims getOrganizationRoleClaims(ApiUser user) { Set orgs = user.getOrganizations(); if (orgs.size() != 1) { - log.error("Misconfigured organizations in DB for User ID: {}", user.getInternalId()); + log.error( + "Misconfigured organizations in DB for User ID: {}. Number of organizations for user was: {}", + user.getInternalId(), + orgs.size()); throw new MisconfiguredUserException(); } Set roles = user.getRoles();