Skip to content

Commit

Permalink
Update role name assignment logic and reduce error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcolon021 committed May 27, 2024
1 parent 6702417 commit daa8bd8
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ private Role createRole(String roleName, String roleDescription) {

Role r = null;
// Create the Role in the repository, if it does not exist. Otherwise, add it.
Role existing_role = roleRepo.getUniqueResultByColumn("name", roleName);
Role existing_role = roleRepo.getUniqueResultByColumn("name", newRoleName);
if (existing_role != null) {
// Role already exists
logger.info("upsertRole() role already exists");
r = existing_role;
} else {
// This is a new Role
r = new Role();
r.setName(roleName);
r.setName(newRoleName);
r.setDescription(roleDescription);
// Since this is a new Role, we need to ensure that the
// corresponding Privilege (with gates) and AccessRule is added.
Expand All @@ -300,13 +300,12 @@ private Role createRole(String roleName, String roleDescription) {
return r;
}

private String extractIdp(User current_user) {
private static String extractIdp(User current_user) {
try {
final ObjectNode node;
node = new ObjectMapper().readValue(current_user.getGeneralMetadata(), ObjectNode.class);
return node.get("idp").asText();
} catch (JsonProcessingException e) {
logger.warn("Error parsing idp value from medatada", e);
return "";
}
}
Expand Down Expand Up @@ -1083,6 +1082,7 @@ private String extractProject(String roleName) {
if (projectMatcher.find()) {
project = projectMatcher.group(1).trim();
} else {
logger.info("extractProject() Could not extract project from role name: {}", roleName);
String[] parts = roleName.split("_", 1);
if (parts.length > 0) {
project = parts[1];
Expand All @@ -1091,7 +1091,7 @@ private String extractProject(String roleName) {
return project;
}

private String extractConsentGroup(String roleName) {
private static String extractConsentGroup(String roleName) {
String consentPattern = "FENCE_.*?_c(\\d+)$";
if (roleName.startsWith("MANUAL_")) {
consentPattern = "MANUAL_.*?_c(\\d+)$";
Expand Down

0 comments on commit daa8bd8

Please sign in to comment.