Skip to content

Commit

Permalink
Refactor querying method in OktaOAuthAuthenticationService
Browse files Browse the repository at this point in the history
The code simplifies the process of querying application repository by replacing usage of `picSureApp` with `applicationRepo.getUniqueResultByColumn("name", "pic-sure")`. It also injected a StudyAccessService in the class and commented out the setting of privileges to `fenceOpenAccessRole` without providing a replacement.
  • Loading branch information
Gcolon021 committed Feb 15, 2024
1 parent 9042f27 commit 6fe8e91
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import edu.harvard.hms.dbmi.avillach.auth.data.repository.PrivilegeRepository;
import edu.harvard.hms.dbmi.avillach.auth.data.repository.RoleRepository;
import edu.harvard.hms.dbmi.avillach.auth.data.repository.UserRepository;
import edu.harvard.hms.dbmi.avillach.auth.rest.StudyAccessService;
import edu.harvard.hms.dbmi.avillach.auth.rest.UserService;
import edu.harvard.hms.dbmi.avillach.auth.utils.AuthUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -47,16 +48,13 @@ public class OktaOAuthAuthenticationService {
@Inject
private ApplicationRepository applicationRepo;

@Inject
private StudyAccessService studyAccessService;

private static final String parentAccessionField = "\\\\_Parent Study Accession with Subject ID\\\\";

private Application picSureApp;

OktaOAuthAuthenticationService() {
if (this.applicationRepo != null) {
picSureApp = applicationRepo.getUniqueResultByColumn("name", "PICSURE");
} else {
logger.error("ApplicationRepository is null");
}
}

/**
Expand Down Expand Up @@ -154,7 +152,7 @@ private User loadUser(JsonNode introspectResponse) {
if (!user.getRoles().contains(fenceOpenAccessRole)) {
logger.info("Adding fence_open_access role to user: " + user.getUuid());
Set<Role> roles = user.getRoles();
fenceOpenAccessRole.setPrivileges(addNhanesPrivileges(fenceOpenAccessRole.getPrivileges()));
// fenceOpenAccessRole.setPrivileges(addNhanesPrivileges(fenceOpenAccessRole.getPrivileges()));
roles.add(fenceOpenAccessRole);
userRepository.changeRole(user, roles);
}
Expand All @@ -181,14 +179,14 @@ private Set<Privilege> addNhanesPrivileges(Set<Privilege> privileges) {
if (nhanesPriv == null) {
nhanesPriv = new Privilege();
nhanesPriv.setQueryTemplate(queryTemplateText);
nhanesPriv.setName("NHANES");
nhanesPriv.setDescription("NHANES Privilege");
nhanesPriv.setApplication(applicationRepo.getUniqueResultByColumn("name", "pic-sure"));
nhanesPriv.setQueryScope("[\"\\\\_consents\\\\\",\"_\"]");
} else {
nhanesPriv.setQueryTemplate(queryTemplateText);
}

nhanesPriv.setName("NHANES");
nhanesPriv.setDescription("NHANES Privilege");
nhanesPriv.setApplication(picSureApp);
nhanesPriv.setQueryScope("[\"\\\\_consents\\\\\",\"_\"]");
privileges.add(nhanesPriv);
privilegeRepository.persist(nhanesPriv);
return privileges;
Expand Down

0 comments on commit 6fe8e91

Please sign in to comment.