Skip to content

Commit

Permalink
Improve logging in OktaOAuthAuthenticationService
Browse files Browse the repository at this point in the history
Extended the logging capability in OktaOAuthAuthenticationService for user roles and metadata. This assists in diagnosing login issues by logging whether a user is assigned the fence_open_access role and whether their metadata is being added or already exists.
  • Loading branch information
Gcolon021 committed Jan 25, 2024
1 parent 353925e commit 098a0dd
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,19 @@ private User loadUser(JsonNode introspectResponse) {

// All users that login through OKTA should have the fence_open_access role, or they will not be able to interact with the UI
Role fenceOpenAccessRole = roleRepository.getUniqueResultByColumn("name", FENCEAuthenticationService.fence_open_access_role_name);

// print user roles for debugging
logger.info("User roles: " + user.getRoles().toString());

if (!user.getRoles().contains(fenceOpenAccessRole)) {
logger.info("Adding fence_open_access role to user: " + user.getUuid());
user.getRoles().add(fenceOpenAccessRole);
userRepository.persist(user);
}

// Add metadata to the user upon logging in if it doesn't exist
if (user.getGeneralMetadata() != null && user.getGeneralMetadata().isEmpty()) {
if (user.getGeneralMetadata().isEmpty()) {
logger.info("Adding metadata to user: " + user.getUuid());
// JsonNode is immutable, so we need to convert it to a ObjectNode
ObjectNode objectNode = JAXRSConfiguration.objectMapper.createObjectNode();
objectNode.set("email", introspectResponse.get("sub"));
Expand All @@ -143,6 +149,8 @@ private User loadUser(JsonNode introspectResponse) {
user.setGeneralMetadata(objectNode.asText());

userRepository.persist(user);
} else {
logger.info("User already has metadata: " + user.getUuid());
}

return user;
Expand Down

0 comments on commit 098a0dd

Please sign in to comment.