Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 57df8c5

Browse files
committedMay 20, 2024·
Enhance logging and modify role assignment process in FENCEAuthenticationService
1 parent cd7013f commit 57df8c5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed
 

‎pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/service/auth/FENCEAuthenticationService.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ public Response getFENCEProfile(String callback_url, Map<String, String> authReq
236236
project_access_set.add(newRoleName);
237237
}
238238

239+
// Project access set is now a set of role names that should be assigned to the user
240+
logger.info("getFENCEProfile() project access set: {}", project_access_set);
241+
242+
// current user roles
243+
logger.info("getFENCEProfile() current user roles: {}", current_user.getRoles());
244+
239245
// Step 1: Remove roles that are not in the project_access_set
240246
Set<Role> rolesToRemove = new HashSet<>();
241247
// Also, track the roles that are assigned to the user and in the project_access_set
@@ -271,11 +277,13 @@ public Response getFENCEProfile(String callback_url, Map<String, String> authReq
271277
// Given our reduced list of roles that should be assigned, we can determine which of those roles are not in the database
272278
// This also tells use which roles are in the database
273279
Set<String> rolesThatExist = roleRepo.getRoleNamesByNames(project_access_set);
274-
275280
if (!rolesThatExist.isEmpty()) {
276281
// Assign the roles that exist in the database to the user
277282
logger.info("getFENCEProfile() assigning roles that exist in the database: {}", rolesThatExist);
278-
roleRepo.getRolesByNames(rolesThatExist).forEach(role -> current_user.getRoles().add(role));
283+
for (Role role : roleRepo.getRolesByNames(rolesThatExist)) {
284+
current_user.getRoles().add(role);
285+
}
286+
279287
} else {
280288
logger.info("getFENCEProfile() none of the following roles exist in the database: {}", project_access_set);
281289
}
@@ -313,7 +321,7 @@ public Response getFENCEProfile(String callback_url, Map<String, String> authReq
313321
}
314322

315323
try {
316-
userRepo.changeRole(current_user, current_user.getRoles());
324+
current_user = userRepo.changeRole(current_user, current_user.getRoles());
317325
logger.debug("upsertRole() updated user, who now has {} roles.", current_user.getRoles().size());
318326
} catch (Exception ex) {
319327
logger.error("upsertRole() Could not add roles to user, because {}", ex.getMessage());

0 commit comments

Comments
 (0)