Skip to content

Commit

Permalink
Replace StudyMetaData object with Map in StudyAccessService and FENCE…
Browse files Browse the repository at this point in the history
…AuthenticationService

Reverting change. Attempting to determine if there is a parsing issue.
  • Loading branch information
Gcolon021 committed May 25, 2024
1 parent b7b00ea commit f30b491
Show file tree
Hide file tree
Showing 7 changed files with 4,224 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public Response addStudyAccess(@ApiParam(value="The Study Identifier of the new
return Response.status(Response.Status.BAD_REQUEST).entity("Study identifier cannot be blank").build();
}

StudyMetaData fenceMappingForStudy;
Map fenceMappingForStudy;
try {
Map<String, StudyMetaData> fenceMapping = fenceMappingUtility.getFENCEMapping();
Map<String, Map> fenceMapping = fenceMappingUtility.getFENCEMapping();
if (fenceMapping == null) {
throw new Exception("Fence mapping is null");
}
Expand All @@ -70,8 +70,8 @@ public Response addStudyAccess(@ApiParam(value="The Study Identifier of the new
return Response.status(Response.Status.BAD_REQUEST).entity("Could not find study with the provided identifier").build();
}

String projectId = fenceMappingForStudy.getStudy_identifier();
String consentCode = fenceMappingForStudy.getConsent_group_code();
String projectId = (String) fenceMappingForStudy.get("study_identifier");
String consentCode = (String) fenceMappingForStudy.get("consent_group_code");
String newRoleName = StringUtils.isNotBlank(consentCode) ? MANUAL+projectId+"_"+consentCode : MANUAL+projectId;

logger.debug("addStudyAccess - New manual PSAMA role name: {}", newRoleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,16 @@ private Set<String> getProjectAccessNames(JsonNode fence_user_profile) {
// Loop over the project access names and convert them to database fence role names
while (project_access_names.hasNext()) {
String access_role_name = project_access_names.next();
StudyMetaData studyMetadata = fenceMappingUtility.getFenceMappingByAuthZ().get(access_role_name);
Map studyMetadata = fenceMappingUtility.getFenceMappingByAuthZ().get(access_role_name);

if (studyMetadata == null) {
logger.info("getFENCEProfile() -> Could not find study in FENCE mapping SKIPPING: {}", access_role_name);
continue;
}

String projectId = studyMetadata.getStudy_identifier();
String consentCode = studyMetadata.getConsent_group_code();
String projectId = (String) studyMetadata.get("study_identifier");
String consentCode = (String) studyMetadata.get("consent_group_code");

String newRoleName = StringUtils.isNotBlank(consentCode) ? "FENCE_" + projectId + "_" + consentCode : "FENCE_" + projectId;

project_access_set.add(newRoleName);
Expand Down Expand Up @@ -470,7 +471,7 @@ private Set<Privilege> addFENCEPrivileges(User u, Role r) {
logger.info("addFENCEPrivileges() project name: " + project_name + " consent group: " + consent_group);

// Look up the metadata by consent group.
StudyMetaData studyMetadata = getFENCEMappingforProjectAndConsent(project_name, consent_group);
Map studyMetadata = getFENCEMappingforProjectAndConsent(project_name, consent_group);
if (studyMetadata == null) {
//no privileges means no access to this project. just return existing set of privs.
logger.warn("No metadata available for project {}.{}", project_name, consent_group);
Expand All @@ -479,19 +480,18 @@ private Set<Privilege> addFENCEPrivileges(User u, Role r) {

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

String dataType = studyMetadata.getData_type();
Boolean isHarmonized = "Y".equals(studyMetadata.getIs_harmonized());
String concept_path = studyMetadata.getTop_level_path();
String projectAlias = studyMetadata.getAbbreviated_name();
String dataType = (String) studyMetadata.get("data_type");
Boolean isHarmonized = "Y".equals(studyMetadata.get("is_harmonized"));
String concept_path = (String) studyMetadata.get("top_level_path");
String projectAlias = (String) studyMetadata.get("abbreviated_name");

//we need to add escape sequence back in to the path for parsing later (also need to double escape the regex)
//
// OK... so, we need to do this for the query Template and scopes, but should NOT do this for the rules.
//
// NOTE: I'm leaving this in here for now and removing the escaped values later. TODO: fix me!
if (concept_path != null) {
// This shouldn't be necessary, but it is. The double escape is necessary for the regex to work.
concept_path = concept_path.replace("\\", "\\\\");
// This shouldn't be necessary, but it is. The double escape is necessary for the regex to work.
concept_path = concept_path.replaceAll("\\\\", "\\\\\\\\");
}

Expand Down Expand Up @@ -1163,14 +1163,6 @@ private AccessRule upsertHarmonizedAccessRule(String project_name, String consen
private AccessRule upsertConsentGate(String gateName, String rule, boolean is_present, String description) {
gateName = "GATE_" + gateName + "_" + (is_present ? "PRESENT" : "MISSING");
AccessRule gate = accessruleRepo.getUniqueResultByColumn("name", gateName);

// jws will not parse the json if the rule contains a single backslash
if (!rule.contains("\\\\")) {
//these have to be escaped again so that jaxson can convert it correctly
rule = rule.replaceAll("\\\\", "\\\\\\\\");
logger.debug("upsertConsentGate(): escaped rule {}", rule);
}

if (gate != null) {
logger.info("upsertConsentGate() AccessRule {} already exists.", gateName);
return gate;
Expand All @@ -1192,12 +1184,12 @@ private AccessRule upsertConsentGate(String gateName, String rule, boolean is_pr
return gate;
}

private StudyMetaData getFENCEMappingforProjectAndConsent(String projectId, String consent_group) {
private Map getFENCEMappingforProjectAndConsent(String projectId, String consent_group) {
String consentVal = (consent_group != null && !consent_group.isEmpty()) ? projectId + "." + consent_group : projectId;
logger.info("getFENCEMappingforProjectAndConsent() looking up {}", consentVal);

StudyMetaData studyMetadata = fenceMappingUtility.getFENCEMapping().get(consentVal);
if (studyMetadata != null) {
Map studyMetadata = fenceMappingUtility.getFENCEMapping().get(consentVal);
if (studyMetadata instanceof Map) {
return studyMetadata;
} else {
logger.info("getFENCEMappingforProjectAndConsent() no mapping found for {}", consentVal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import edu.harvard.hms.dbmi.avillach.auth.model.StudyMetaData;
import edu.harvard.hms.dbmi.avillach.auth.model.FenceMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -21,8 +20,8 @@
public class FenceMappingUtility {

private final Logger logger = LoggerFactory.getLogger(this.getClass());
private Map<String, StudyMetaData> fenceMappingByConsent;
private Map<String, StudyMetaData> fenceMappingByAuthZ;
private Map<String, Map> fenceMappingByConsent;
private Map<String, Map> fenceMappingByAuthZ;
private static String templatePath;
private ObjectMapper objectMapper;

Expand All @@ -43,43 +42,43 @@ public void init() {
}

private void initializeFENCEMapping() throws IOException {
ArrayList<StudyMetaData> studies = loadBioDataCatalystFenceMappingData();
ArrayList<Map> studies = loadBioDataCatalystFenceMappingData();
fenceMappingByConsent = new HashMap<>(studies.size());
for (StudyMetaData study : studies) {
String consentVal = (study.getConsent_group_code() != null && !study.getConsent_group_code().isEmpty()) ?
study.getStudy_identifier() + "." + study.getConsent_group_code() :
study.getStudy_identifier();
for (Map study : studies) {
String consentVal = (study.get("consent_group_code") != null && study.get("consent_group_code") != "") ?
"" + study.get("study_identifier") + "." + study.get("consent_group_code") :
"" + study.get("study_identifier");
fenceMappingByConsent.put(consentVal, study);
}
}

private void initializeFenceMappingByAuthZ() throws IOException {
ArrayList<StudyMetaData> studies = loadBioDataCatalystFenceMappingData();
ArrayList<Map> studies = loadBioDataCatalystFenceMappingData();
fenceMappingByAuthZ = new HashMap<>(studies.size());
for (StudyMetaData study : studies) {
fenceMappingByAuthZ.put(study.getAuthZ().replace("\\/", "/"), study);
for (Map study : studies) {
fenceMappingByAuthZ.put(((String) study.get("authZ")).replace("\\/", "/"), study);
}
}

public Map<String, StudyMetaData> getFENCEMapping() {
public Map<String, Map> getFENCEMapping() {
return fenceMappingByConsent;
}

public Map<String, StudyMetaData> getFenceMappingByAuthZ() {
public Map<String, Map> getFenceMappingByAuthZ() {
return fenceMappingByAuthZ;
}

private ArrayList<StudyMetaData> loadBioDataCatalystFenceMappingData() {
FenceMapping fenceMapping;
ArrayList<StudyMetaData> studies;
private ArrayList<Map> loadBioDataCatalystFenceMappingData() {
Map fenceMapping;
ArrayList<Map> studies;
try {
logger.debug("getFENCEMapping: loading FENCE mapping from {}", templatePath);
fenceMapping = objectMapper.readValue(
new File(String.join(File.separator,
new String[]{templatePath, "fence_mapping.json"}))
, FenceMapping.class);
, Map.class);

studies = fenceMapping.getBio_data_catalyst();
studies = (ArrayList<Map>) fenceMapping.get("bio_data_catalyst");
logger.debug("getFENCEMapping: found FENCE mapping with {} entries", studies.size());
} catch (Exception e) {
logger.error("loadFenceMappingData: Non-fatal error parsing fence_mapping.json: {}", templatePath, e);
Expand Down
Loading

0 comments on commit f30b491

Please sign in to comment.