|
20 | 20 |
|
21 | 21 | import com.fasterxml.jackson.core.JsonProcessingException;
|
22 | 22 | import com.fasterxml.jackson.databind.node.ObjectNode;
|
| 23 | +import edu.harvard.hms.dbmi.avillach.auth.utils.FenceMappingUtility; |
23 | 24 | import org.apache.commons.lang3.StringUtils;
|
24 | 25 | import org.apache.http.Header;
|
25 | 26 | import org.apache.http.entity.StringEntity;
|
@@ -66,6 +67,9 @@ public class FENCEAuthenticationService {
|
66 | 67 | @Inject
|
67 | 68 | AuthUtils authUtil;
|
68 | 69 |
|
| 70 | + @Inject |
| 71 | + private FenceMappingUtility fenceMappingUtility; |
| 72 | + |
69 | 73 | private Application picSureApp;
|
70 | 74 | private Connection fenceConnection;
|
71 | 75 |
|
@@ -242,7 +246,7 @@ public Response getFENCEProfile(String callback_url, Map<String, String> authReq
|
242 | 246 |
|
243 | 247 | private void createAndUpsertRole(String access_role_name, User current_user) throws IOException {
|
244 | 248 | logger.debug("createAndUpsertRole() starting...");
|
245 |
| - Map projectMetadata = getFenceMappingByAuthZ().get(access_role_name); |
| 249 | + Map projectMetadata = fenceMappingUtility.getFenceMappingByAuthZ().get(access_role_name); |
246 | 250 |
|
247 | 251 | if (projectMetadata == null) {
|
248 | 252 | logger.error("getFENCEProfile() -> createAndUpsertRole could not find study in FENCE mapping SKIPPING: {}", access_role_name);
|
@@ -1127,77 +1131,13 @@ private Map getFENCEMappingforProjectAndConsent(String projectId, String consent
|
1127 | 1131 | String consentVal = (consent_group != null && consent_group != "") ? projectId + "." + consent_group : projectId;
|
1128 | 1132 | logger.info("getFENCEMappingforProjectAndConsent() looking up {}", consentVal);
|
1129 | 1133 |
|
1130 |
| - Object projectMetadata = getFENCEMapping().get(consentVal); |
| 1134 | + Object projectMetadata = fenceMappingUtility.getFENCEMapping().get(consentVal); |
1131 | 1135 | if( projectMetadata instanceof Map) {
|
1132 | 1136 | return (Map)projectMetadata;
|
1133 | 1137 | } else if (projectMetadata != null) {
|
1134 | 1138 | logger.info("getFENCEMappingforProjectAndConsent() Obj instance of " + projectMetadata.getClass().getCanonicalName());
|
1135 | 1139 | }
|
1136 | 1140 | return null;
|
1137 | 1141 | }
|
1138 |
| - |
1139 |
| - public Map<String, Map> getFENCEMapping(){ |
1140 |
| - if(_projectMap == null || _projectMap.isEmpty()) { |
1141 |
| - try { |
1142 |
| - List<Map> projects = loadBioDataCatalystFenceMappingData(); |
1143 |
| - _projectMap = new HashMap<String, Map>(projects.size()); |
1144 |
| - for(Map project : projects) { |
1145 |
| - String consentVal = (project.get("consent_group_code") != null && project.get("consent_group_code") != "") ? |
1146 |
| - "" + project.get("study_identifier") + "." + project.get("consent_group_code") : |
1147 |
| - "" + project.get("study_identifier"); |
1148 |
| - logger.debug("adding study " + consentVal); |
1149 |
| - _projectMap.put(consentVal, project); |
1150 |
| - } |
1151 |
| - |
1152 |
| - } catch (Exception e) { |
1153 |
| - logger.error("getFENCEMapping: Non-fatal error parsing fence_mapping.json: "+JAXRSConfiguration.templatePath, e); |
1154 |
| - return new HashMap<String,Map>(); |
1155 |
| - } |
1156 |
| - } |
1157 |
| - |
1158 |
| - return _projectMap; |
1159 |
| - } |
1160 |
| - |
1161 |
| - |
1162 |
| - /** |
1163 |
| - * This method is used to improve the performance for looking up the FENCE project metadata by the authZ value. |
1164 |
| - * |
1165 |
| - * @return Map<String, Map> - a map of FENCE project metadata by the authZ value |
1166 |
| - * @throws IOException - if there is an issue parsing or finding the fence_mapping.json file |
1167 |
| - */ |
1168 |
| - private Map<String, Map> getFenceMappingByAuthZ() throws IOException { |
1169 |
| - if (fenceMappingByAuthZ == null || fenceMappingByAuthZ.isEmpty()) { |
1170 |
| - List<Map> projects = loadBioDataCatalystFenceMappingData(); |
1171 |
| - fenceMappingByAuthZ = new HashMap<>(projects.size()); |
1172 |
| - if (projects.size() == 1 && projects.get(0).isEmpty()) { |
1173 |
| - logger.error("getFENCEMapping: FENCE mapping data is empty"); |
1174 |
| - throw new IOException("FENCE mapping data is empty"); |
1175 |
| - } |
1176 |
| - |
1177 |
| - for (Map project : projects) { |
1178 |
| - fenceMappingByAuthZ.put(project.get("authZ").toString().replace("\\/", "/"), project); |
1179 |
| - } |
1180 |
| - } |
1181 |
| - |
1182 |
| - return fenceMappingByAuthZ; |
1183 |
| - } |
1184 |
| - |
1185 |
| - private List<Map> loadBioDataCatalystFenceMappingData() { |
1186 |
| - Map fenceMapping = null; |
1187 |
| - List<Map> projects = null; |
1188 |
| - try { |
1189 |
| - fenceMapping = JAXRSConfiguration.objectMapper.readValue( |
1190 |
| - new File(String.join(File.separator, |
1191 |
| - new String[] {JAXRSConfiguration.templatePath ,"fence_mapping.json"})) |
1192 |
| - , Map.class); |
1193 |
| - |
1194 |
| - projects = (List<Map>) fenceMapping.get("bio_data_catalyst"); |
1195 |
| - logger.debug("getFENCEMapping: found FENCE mapping with {} entries", projects.size()); |
1196 |
| - } catch (Exception e) { |
1197 |
| - logger.error("loadFenceMappingData: Non-fatal error parsing fence_mapping.json: {}", JAXRSConfiguration.templatePath, e); |
1198 |
| - return Collections.singletonList(new HashMap()); |
1199 |
| - } |
1200 |
| - return projects; |
1201 |
| - } |
1202 | 1142 |
|
1203 | 1143 | }
|
0 commit comments