Skip to content

Commit

Permalink
Improve user metadata handling in OktaOAuthAuthenticationService
Browse files Browse the repository at this point in the history
Refactor OktaOAuthAuthenticationService.java to enhance handling of user metadata during login process. The old deserialization method of metadata is replaced with a more efficient one, enabling descriptive logging. A JsonProcessingException is now handled by throwing a runtime exception.
  • Loading branch information
Gcolon021 committed Jan 31, 2024
1 parent 601e652 commit d09881a
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.harvard.hms.dbmi.avillach.auth.service.auth;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.harvard.dbmi.avillach.util.HttpClientUtil;
Expand Down Expand Up @@ -133,9 +134,10 @@ private User loadUser(JsonNode introspectResponse) {
// Add metadata to the user upon logging in if it doesn't exist
if (StringUtils.isBlank(user.getGeneralMetadata())) {
ObjectNode objectNode = generateUserMetadata(introspectResponse, user);
logger.info("Adding metadata to user: " + user.getUuid() + " ___ " + objectNode.asText());
String userMetadata = JAXRSConfiguration.objectMapper.writeValueAsString(objectNode);
logger.info("Adding metadata to user: " + user.getUuid() + " ___ " + userMetadata);
// Set the general metadata to the objectNode
user.setGeneralMetadata(objectNode.asText());
user.setGeneralMetadata(userMetadata);
}

userRepository.persist(user);
Expand All @@ -144,6 +146,8 @@ private User loadUser(JsonNode introspectResponse) {
} catch (NoResultException ex) {
logger.info("LOGIN FAILED ___ USER NOT FOUND ___ " + userEmail + " ___");
return null;
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

Expand All @@ -166,6 +170,7 @@ private ObjectNode generateUserMetadata(JsonNode introspectResponse, User user)
authzNode.put("user_id", user.getUuid().toString());
authzNode.put("username", user.getEmail());
tagsNode.put("email", user.getEmail());

return objectNode;
}

Expand Down

0 comments on commit d09881a

Please sign in to comment.