From 3199728024cc706cd85411438b18a09c260f54ac Mon Sep 17 00:00:00 2001 From: Tadgh Date: Thu, 3 Nov 2022 13:26:28 -0700 Subject: [PATCH] 4234 consent in conjunction with versionedapiconverterinterceptor fails (#4236) * Add constant for interceptor * add test, changelog --- .../java/ca/uhn/fhir/context/FhirContext.java | 1 - .../server/VersionedApiConverterInterceptor.java | 4 ++++ .../6_2_0/4234-consent-with-convert.yaml | 6 ++++++ ...ConsentInterceptorResourceProviderR4Test.java | 16 ++++++++++++++++ .../interceptor/auth/AuthorizationConstants.java | 1 + 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4234-consent-with-convert.yaml diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java index 3e48b0dc0ee..ecd8073b0eb 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java @@ -24,7 +24,6 @@ import ca.uhn.fhir.rest.client.api.IBasicClient; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.IRestfulClient; import ca.uhn.fhir.rest.client.api.IRestfulClientFactory; -import ca.uhn.fhir.tls.TlsAuthentication; import ca.uhn.fhir.util.FhirTerser; import ca.uhn.fhir.util.ReflectionUtil; import ca.uhn.fhir.util.VersionUtil; diff --git a/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/server/VersionedApiConverterInterceptor.java b/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/server/VersionedApiConverterInterceptor.java index b1b29b126ab..a8cf61d1d26 100644 --- a/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/server/VersionedApiConverterInterceptor.java +++ b/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/server/VersionedApiConverterInterceptor.java @@ -23,6 +23,7 @@ package ca.uhn.hapi.converters.server; import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; +import ca.uhn.fhir.interceptor.api.Interceptor; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.server.RequestDetails; @@ -30,6 +31,7 @@ import ca.uhn.fhir.rest.api.server.ResponseDetails; import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter; +import ca.uhn.fhir.rest.server.interceptor.auth.AuthorizationConstants; import org.hl7.fhir.converter.NullVersionConverterAdvisor10_30; import org.hl7.fhir.converter.NullVersionConverterAdvisor10_40; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30; @@ -54,6 +56,8 @@ import static org.apache.commons.lang3.StringUtils.*; * Versioned API features. *

*/ + +@Interceptor(order = AuthorizationConstants.ORDER_CONVERTER_INTERCEPTOR) public class VersionedApiConverterInterceptor extends InterceptorAdapter { private final FhirContext myCtxDstu2; private final FhirContext myCtxDstu2Hl7Org; diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4234-consent-with-convert.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4234-consent-with-convert.yaml new file mode 100644 index 00000000000..94e8f53584e --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4234-consent-with-convert.yaml @@ -0,0 +1,6 @@ +--- +type: fix +issue: 4234 +jira: SMILE-4765 +title: "Fixed a bug which caused a failure when combining a Consent Interceptor with version conversion via the `Accept` header." + diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ConsentInterceptorResourceProviderR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ConsentInterceptorResourceProviderR4Test.java index 9abba0bdf60..257b4aeb873 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ConsentInterceptorResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ConsentInterceptorResourceProviderR4Test.java @@ -24,6 +24,7 @@ import ca.uhn.fhir.rest.server.interceptor.consent.IConsentService; import ca.uhn.fhir.util.BundleUtil; import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.util.UrlUtil; +import ca.uhn.hapi.converters.server.VersionedApiConverterInterceptor; import com.google.common.base.Charsets; import com.google.common.collect.Lists; import org.apache.commons.collections4.ListUtils; @@ -282,6 +283,21 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid }); } + @Test + public void testConsentWorksWithVersionedApiConverterInterceptor() { + myConsentInterceptor = new ConsentInterceptor(new IConsentService() { + }); + ourRestServer.getInterceptorService().registerInterceptor(myConsentInterceptor); + ourRestServer.getInterceptorService().registerInterceptor(new VersionedApiConverterInterceptor()); + + myClient.create().resource(new Patient().setGender(Enumerations.AdministrativeGender.MALE).addName(new HumanName().setFamily("1"))).execute(); + Bundle response = myClient.search().forResource(Patient.class).count(1).accept("application/fhir+json; fhirVersion=3.0").returnBundle(Bundle.class).execute(); + + assertEquals(1, response.getEntry().size()); + assertNull(response.getTotalElement().getValue()); + + } + @Test public void testHistoryAndBlockSome() { create50Observations(); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/AuthorizationConstants.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/AuthorizationConstants.java index f138a14568e..51c1e7c2567 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/AuthorizationConstants.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/AuthorizationConstants.java @@ -24,6 +24,7 @@ public class AuthorizationConstants { public static final int ORDER_CONSENT_INTERCEPTOR = 100; public static final int ORDER_AUTH_INTERCEPTOR = 200; + public static final int ORDER_CONVERTER_INTERCEPTOR = 300; private AuthorizationConstants() { super();