From e407930c31a30689d25368998f315b1efd37ad60 Mon Sep 17 00:00:00 2001 From: Matthew Storer Date: Fri, 22 Mar 2024 10:42:02 -0700 Subject: [PATCH] improved logging --- .../sds/SupplementalDataStoreAuthProfile.java | 11 ++++- ...ntalDataStoreAuthorizationInterceptor.java | 13 +++--- ...pplementalDataStoreLinkingInterceptor.java | 45 ++++++++++++++++--- .../edu/ohsu/cmp/ecp/util/IIdTypeUtil.java | 32 +++++++++++++ .../ohsu/cmp/ecp/util/RequestDetailsUtil.java | 13 ++++++ 5 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 src/main/java/edu/ohsu/cmp/ecp/util/IIdTypeUtil.java create mode 100644 src/main/java/edu/ohsu/cmp/ecp/util/RequestDetailsUtil.java diff --git a/src/main/java/edu/ohsu/cmp/ecp/sds/SupplementalDataStoreAuthProfile.java b/src/main/java/edu/ohsu/cmp/ecp/sds/SupplementalDataStoreAuthProfile.java index 647fab0..6e94c71 100644 --- a/src/main/java/edu/ohsu/cmp/ecp/sds/SupplementalDataStoreAuthProfile.java +++ b/src/main/java/edu/ohsu/cmp/ecp/sds/SupplementalDataStoreAuthProfile.java @@ -1,5 +1,6 @@ package edu.ohsu.cmp.ecp.sds; +import edu.ohsu.cmp.ecp.util.IIdTypeUtil; import org.hl7.fhir.instance.model.api.IIdType; import edu.ohsu.cmp.ecp.sds.SupplementalDataStoreAuth.AuthorizationProfile; @@ -14,7 +15,15 @@ public SupplementalDataStoreAuthProfile(IIdType authorizedUserId, IIdType target this.targetPatientId = targetPatientId; } - public static AuthorizationProfile forPatient( IIdType userAndPatientId ) { + @Override + public String toString() { + return "SupplementalDataStoreAuthProfile{" + + "authorizedUserId=" + IIdTypeUtil.toString(authorizedUserId) + + ", targetPatientId=" + IIdTypeUtil.toString(targetPatientId) + + '}'; + } + + public static AuthorizationProfile forPatient(IIdType userAndPatientId ) { return new SupplementalDataStoreAuthProfile( userAndPatientId, userAndPatientId ) ; } diff --git a/src/main/java/edu/ohsu/cmp/ecp/sds/SupplementalDataStoreAuthorizationInterceptor.java b/src/main/java/edu/ohsu/cmp/ecp/sds/SupplementalDataStoreAuthorizationInterceptor.java index c152be9..9bdc3d0 100644 --- a/src/main/java/edu/ohsu/cmp/ecp/sds/SupplementalDataStoreAuthorizationInterceptor.java +++ b/src/main/java/edu/ohsu/cmp/ecp/sds/SupplementalDataStoreAuthorizationInterceptor.java @@ -6,6 +6,7 @@ import javax.inject.Inject; +import edu.ohsu.cmp.ecp.util.RequestDetailsUtil; import org.hl7.fhir.instance.model.api.IIdType; import org.springframework.stereotype.Component; @@ -31,14 +32,16 @@ public class SupplementalDataStoreAuthorizationInterceptor extends Authorization @Override public List buildRuleList(RequestDetails theRequestDetails) { IAuthRuleBuilder ruleBuilder = new RuleBuilder(); - + ourLog.info("in buildRuleList() with theRequestDetails=" + RequestDetailsUtil.toString(theRequestDetails)); + ruleBuilder = ruleBuilder .allow( "capability statement" ) .metadata() .andThen() - ; + ; Permissions permissions = getPermissions(theRequestDetails); + ourLog.info("permissions=" + permissions); if ( null == permissions ) { /* return early, no details of the authorization are available */ @@ -80,7 +83,7 @@ private IAuthRuleBuilder buildRuleListForPermissions( IAuthRuleBuilder ruleBuild .resourcesOfType("Linkage") .withAnyId() .andThen() - ; + ; return ruleBuilder ; } @@ -120,7 +123,7 @@ private IAuthRuleBuilder buildRuleListForPermissions( IAuthRuleBuilder ruleBuild .resourcesOfType("Linkage") .withFilter( "item=" + localPatientId.getIdPart() ) .andThen() - ; + ; /* permit access to all sds-foreign records for specific patient in each partition */ for (IIdType nonLocalPatientId : readAndWriteSpecificPatients.patientId().nonLocalUserIds() ) { @@ -144,7 +147,7 @@ private IAuthRuleBuilder buildRuleListForPermissions( IAuthRuleBuilder ruleBuild .resourcesOfType("Linkage") .withFilter( "item=" + nonLocalPatientId.getIdPart() ) .andThen() - ; + ; } return ruleBuilder; diff --git a/src/main/java/edu/ohsu/cmp/ecp/sds/SupplementalDataStoreLinkingInterceptor.java b/src/main/java/edu/ohsu/cmp/ecp/sds/SupplementalDataStoreLinkingInterceptor.java index d14f6fb..7aa7821 100644 --- a/src/main/java/edu/ohsu/cmp/ecp/sds/SupplementalDataStoreLinkingInterceptor.java +++ b/src/main/java/edu/ohsu/cmp/ecp/sds/SupplementalDataStoreLinkingInterceptor.java @@ -2,12 +2,11 @@ import static java.util.stream.Collectors.joining; -import java.util.Collection; -import java.util.Optional; -import java.util.Set; +import java.util.*; import javax.inject.Inject; +import edu.ohsu.cmp.ecp.util.IIdTypeUtil; import org.hl7.fhir.instance.model.api.IBaseReference; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; @@ -58,6 +57,16 @@ public UserIdentity( Optional basisNonLocalUserId, IIdType localUserId, nonLocalUserIds.forEach( this::requireMatchingIdType ); } + @Override + public String toString() { + return "UserIdentity{" + + "userResourceType='" + userResourceType + '\'' + + ", basisNonLocalUserId=" + IIdTypeUtil.toString(basisNonLocalUserId) + + ", localUserId=" + IIdTypeUtil.toString(localUserId) + + ", nonLocalUserIds=" + IIdTypeUtil.toString(nonLocalUserIds) + + '}'; + } + public String userResourceType() { return userResourceType; } @@ -87,18 +96,27 @@ public static final class Permissions { private final Optional readAllPatients ; private final Optional readAndWriteSpecificPatient ; - public Permissions( ReadAllPatients readAllPatients ) { + public Permissions(ReadAllPatients readAllPatients) { this.readAllPatients = Optional.of(readAllPatients); authorizedNonLocalUserId = readAllPatients.authorizedNonLocalUserId() ; this.readAndWriteSpecificPatient = Optional.empty(); } - public Permissions( ReadAndWriteSpecificPatient readAndWriteSpecificPatient) { + public Permissions(ReadAndWriteSpecificPatient readAndWriteSpecificPatient) { this.readAllPatients = Optional.empty(); this.readAndWriteSpecificPatient = Optional.of( readAndWriteSpecificPatient ); authorizedNonLocalUserId = readAndWriteSpecificPatient.authorizedNonLocalUserId() ; } + @Override + public String toString() { + return "Permissions{" + + "authorizedNonLocalUserId=" + IIdTypeUtil.toString(authorizedNonLocalUserId) + + ", readAllPatients=" + readAllPatients + + ", readAndWriteSpecificPatient=" + readAndWriteSpecificPatient + + '}'; + } + public IIdType authorizedNonLocalUserId() { return authorizedNonLocalUserId ; } @@ -117,6 +135,13 @@ public ReadAllPatients(IIdType authorizedNonLocalUserId) { this.authorizedNonLocalUserId = authorizedNonLocalUserId; } + @Override + public String toString() { + return "ReadAllPatients{" + + "authorizedNonLocalUserId=" + IIdTypeUtil.toString(authorizedNonLocalUserId) + + '}'; + } + public IIdType authorizedNonLocalUserId() { return authorizedNonLocalUserId ; } @@ -132,6 +157,14 @@ public ReadAndWriteSpecificPatient(IIdType authorizedNonLocalUserId, UserIdentit this.patientId = patientId; } + @Override + public String toString() { + return "ReadAndWriteSpecificPatient{" + + "authorizedNonLocalUserId=" + IIdTypeUtil.toString(authorizedNonLocalUserId) + + ", patientId=" + patientId + + '}'; + } + public IIdType authorizedNonLocalUserId() { return authorizedNonLocalUserId ; } @@ -158,6 +191,8 @@ public void identifyPermissions(RequestDetails theRequestDetails) { if ( null == authProfile ) return ; + ourLog.info("authProfile=" + authProfile); + IIdType authorizedNonLocalUserId = authProfile.getAuthorizedUserId(); /* diff --git a/src/main/java/edu/ohsu/cmp/ecp/util/IIdTypeUtil.java b/src/main/java/edu/ohsu/cmp/ecp/util/IIdTypeUtil.java new file mode 100644 index 0000000..6e1aa29 --- /dev/null +++ b/src/main/java/edu/ohsu/cmp/ecp/util/IIdTypeUtil.java @@ -0,0 +1,32 @@ +package edu.ohsu.cmp.ecp.util; + +import org.apache.commons.lang3.StringUtils; +import org.hl7.fhir.instance.model.api.IIdType; + +import java.util.*; + +public class IIdTypeUtil { + + public static String toString(Optional optional) { + return optional.map(IIdTypeUtil::toString).orElse(""); + } + + public static String toString(Collection collection) { + if (collection == null || collection.isEmpty()) { + return "[]"; + } + List list = new ArrayList<>(); + for (IIdType iIdType : collection) { + list.add(toString(iIdType)); + } + return "[" + StringUtils.join(list, ", ") + "]"; + } + + public static String toString(IIdType idType) { + if (idType == null) return "null"; + + return "IIdType{" + + "value='" + idType.getValue() + '\'' + + '}'; + } +} diff --git a/src/main/java/edu/ohsu/cmp/ecp/util/RequestDetailsUtil.java b/src/main/java/edu/ohsu/cmp/ecp/util/RequestDetailsUtil.java new file mode 100644 index 0000000..26b4734 --- /dev/null +++ b/src/main/java/edu/ohsu/cmp/ecp/util/RequestDetailsUtil.java @@ -0,0 +1,13 @@ +package edu.ohsu.cmp.ecp.util; + +import ca.uhn.fhir.rest.api.server.RequestDetails; + +public class RequestDetailsUtil { + public static String toString(RequestDetails requestDetails) { + if (requestDetails == null) return "null"; + return "RequestDetails{" + + "completeUrl='" + requestDetails.getCompleteUrl() + '\'' + + ", tenantId='" + requestDetails.getTenantId() + '\'' + + '}'; + } +}