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 43524f5

Browse files
committedMay 15, 2024·
Refactor FENCEAuthenticationService to use ProjectMetaData
The FENCEAuthenticationService has been refactored to use the ProjectMetaData instead of Map for project metadata. Objects have been replaced with their explicit ProjectMetaData objects, making the code easier to understand and modify in future. Removed unused project maps for improved efficiency.
1 parent f38e6fc commit 43524f5

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed
 

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

+13-19
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ public class FENCEAuthenticationService {
7373
private Application picSureApp;
7474
private Connection fenceConnection;
7575

76-
//read the fence_mapping.json into this object to improve lookup speeds
77-
private static Map<String, Map> _projectMap;
78-
private static Map<String, Map> fenceMappingByAuthZ;
79-
8076
private static final String parentAccessionField = "\\\\_Parent Study Accession with Subject ID\\\\";
8177
private static final String topmedAccessionField = "\\\\_Topmed Study Accession with Subject ID\\\\";
8278

@@ -155,7 +151,7 @@ private JsonNode getFENCEAccessToken(String callback_url, String fence_code) {
155151
}
156152

157153
// Get access_token from FENCE, based on the provided `code`
158-
public Response getFENCEProfile(String callback_url, Map<String, String> authRequest) throws IOException {
154+
public Response getFENCEProfile(String callback_url, Map<String, String> authRequest) {
159155
logger.debug("getFENCEProfile() starting...");
160156
String fence_code = authRequest.get("code");
161157

@@ -405,20 +401,19 @@ private Set<Privilege> addFENCEPrivileges(User u, Role r) {
405401
logger.info("addFENCEPrivileges() project name: "+project_name+" consent group: "+consent_group);
406402

407403
// Look up the metadata by consent group.
408-
Map projectMetadata = getFENCEMappingforProjectAndConsent(project_name, consent_group);
409-
410-
if(projectMetadata == null || projectMetadata.isEmpty()) {
404+
ProjectMetaData projectMetadata = getFENCEMappingforProjectAndConsent(project_name, consent_group);
405+
if(projectMetadata == null) {
411406
//no privileges means no access to this project. just return existing set of privs.
412-
logger.warn("No metadata available for project " + project_name + "." + consent_group);
407+
logger.warn("No metadata available for project {}.{}", project_name, consent_group);
413408
return privs;
414409
}
415410

416411
logger.info("addPrivileges() This is a new privilege");
417412

418-
String dataType = (String) projectMetadata.get("data_type");
419-
Boolean isHarmonized = "Y".equals(projectMetadata.get("is_harmonized"));
420-
String concept_path = (String) projectMetadata.get("top_level_path");
421-
String projectAlias = (String) projectMetadata.get("abbreviated_name");
413+
String dataType = projectMetadata.getData_type();
414+
Boolean isHarmonized = "Y".equals(projectMetadata.getIs_harmonized());
415+
String concept_path = projectMetadata.getTop_level_path();
416+
String projectAlias = projectMetadata.getAbbreviated_name();
422417

423418
//we need to add escape sequence back in to the path for parsing later (also need to double escape the regex)
424419
//
@@ -1145,16 +1140,15 @@ private AccessRule upsertConsentGate(String gateName, String rule, boolean is_pr
11451140
return gate;
11461141
}
11471142

1148-
private Map getFENCEMappingforProjectAndConsent(String projectId, String consent_group) {
1149-
1150-
String consentVal = (consent_group != null && consent_group != "") ? projectId + "." + consent_group : projectId;
1143+
private ProjectMetaData getFENCEMappingforProjectAndConsent(String projectId, String consent_group) {
1144+
String consentVal = (consent_group != null && !consent_group.isEmpty()) ? projectId + "." + consent_group : projectId;
11511145
logger.info("getFENCEMappingforProjectAndConsent() looking up {}", consentVal);
11521146

1153-
Object projectMetadata = fenceMappingUtility.getFENCEMapping().get(consentVal);
1147+
ProjectMetaData projectMetadata = fenceMappingUtility.getFENCEMapping().get(consentVal);
11541148
if( projectMetadata instanceof Map) {
1155-
return (Map)projectMetadata;
1149+
return projectMetadata;
11561150
} else if (projectMetadata != null) {
1157-
logger.info("getFENCEMappingforProjectAndConsent() Obj instance of " + projectMetadata.getClass().getCanonicalName());
1151+
logger.info("getFENCEMappingforProjectAndConsent() Obj instance of {}", projectMetadata.getClass().getCanonicalName());
11581152
}
11591153
return null;
11601154
}

0 commit comments

Comments
 (0)
Please sign in to comment.