Skip to content

Commit

Permalink
[http] add: check auth
Browse files Browse the repository at this point in the history
  • Loading branch information
nr23730 committed Mar 31, 2021
1 parent 5594b54 commit 9d1ed56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions src/main/java/fhirspark/FhirSpark.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public final class FhirSpark {

private static JsonFhirMapper jsonFhirMapper;
private static JsonHl7v2Mapper jsonHl7v2Mapper;
private static Settings settings;
private static Client client = new Client();
private static ObjectMapper objectMapper = new ObjectMapper(new JsonFactory());

Expand All @@ -57,7 +58,7 @@ public static void main(final String[] args) throws Exception {
settingsYaml = new FileInputStream(args[0]);
}
ConfigurationLoader configLoader = new ConfigurationLoader();
final Settings settings = configLoader.loadConfiguration(settingsYaml, Settings.class);
settings = configLoader.loadConfiguration(settingsYaml, Settings.class);
HgncGeneName.initialize(settings.getHgncPath());
OncoKbDrug.initalize(settings.getOncokbPath());
jsonFhirMapper = new JsonFhirMapper(settings);
Expand Down Expand Up @@ -90,7 +91,7 @@ public static void main(final String[] args) throws Exception {
*/
get("/mtb/:patientId/permission", (req, res) -> {
if (settings.getLoginRequired()
&& (!validateRequest(req, settings) || !validateManipulation(req, settings))) {
&& (!validateRequest(req) || !validateManipulation(req))) {
res.status(HttpStatus.FORBIDDEN_403);
return res;
}
Expand All @@ -102,7 +103,7 @@ public static void main(final String[] args) throws Exception {
});

get("/mtb/:patientId", (req, res) -> {
if (settings.getLoginRequired() && !validateRequest(req, settings)) {
if (settings.getLoginRequired() && !validateRequest(req)) {
res.status(HttpStatus.FORBIDDEN_403);
return res;
}
Expand All @@ -117,7 +118,7 @@ public static void main(final String[] args) throws Exception {

put("/mtb/:patientId", (req, res) -> {
if (settings.getLoginRequired()
&& (!validateRequest(req, settings) || !validateManipulation(req, settings))) {
&& (!validateRequest(req) || !validateManipulation(req))) {
res.status(HttpStatus.FORBIDDEN_403);
return res;
}
Expand All @@ -138,7 +139,7 @@ public static void main(final String[] args) throws Exception {

delete("/mtb/:patientId", (req, res) -> {
if (settings.getLoginRequired()
&& (!validateRequest(req, settings) || !validateManipulation(req, settings))) {
&& (!validateRequest(req) || !validateManipulation(req))) {
res.status(HttpStatus.FORBIDDEN_403);
return res;
}
Expand Down Expand Up @@ -213,7 +214,7 @@ public static void main(final String[] args) throws Exception {
* @param req Incoming Java Spark Request
* @return Boolean if the session if able to access the data
*/
private static boolean validateRequest(Request req, Settings settings) {
private static boolean validateRequest(Request req) {
String portalDomain = settings.getPortalUrl();
String validatePath = "api/studies/" + settings.getMtbStudy() + "/patients/"
+ req.params(":patientId");
Expand Down Expand Up @@ -242,7 +243,7 @@ private static boolean validateRequest(Request req, Settings settings) {
* @param req Incoming Java Spark Request
* @return Boolean if the session is able to access the data
*/
private static boolean validateManipulation(Request req, Settings settings) {
private static boolean validateManipulation(Request req) {
String requestedPatientId = req.params(":patientId");
String mtbStudy = settings.getMtbStudy();
String userRoles = req.headers("X-USERROLES");
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ specimenSystem: ${FHIRSPARK_SPECIMENSYSTEM:-https://cbioportal.org/specimen/}
diagnosticReportSystem: ${FHIRSPARK_DIAGNOSTICREPORTSYSTEM:-https://cbioportal.org/mtb/}
observationSystem: ${FHIRSPARK_OBSERVATIONSYSTEM:-https://cbioportal.org/therapyrecommendation/}
patientSystem: ${FHIRSPARK_PATIENTSYSTEM:-https://cbioportal.org/patient/}
hgncPath: ${FHIRSPARK_HGNCPATH:-hgnc.csv}
portalUrl: ${FHIRSPARK_PORTALURL:-http://localhost:8080/}
portalUrl: ${FHIRSPARK_PORTALURL:-http://cbioportal/}
mtbStudy: ${FHIRSPARK_MTBSTUDY:-MTB}
loginRequired: ${FHIRSPARK_LOGINREQUIRED:-true}
hgncPath: ${FHIRSPARK_HGNCPATH:-hgnc.csv}
oncokbPath: ${FHIRSPARK_ONCOKBPATH:-drugs.json}
hl7v2config:
- sendv2: ${FHIRSPARK_SENDHL7V2:-true}
- sendv2: ${FHIRSPARK_SENDHL7V2:-false}
server: ${FHIRSPARK_HL7V2SERVER:-localhost}
port: ${FHIRSPARK_HL7V2PORT:-1011}

0 comments on commit 9d1ed56

Please sign in to comment.