Permissions for operations

This commit is contained in:
James Agnew 2018-07-12 18:40:15 -04:00
parent 03e7b018a6
commit e6ca408f67
4 changed files with 62 additions and 5 deletions

View File

@ -48,7 +48,7 @@ public class FhirResourceDaoR4UpdateTest extends BaseJpaR4Test {
p.getPhotoFirstRep().setCreationElement(new DateTimeType("2011")); // non-indexed field
IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless();
assertEquals(2, QueryCountHolder.getGrandTotal().getInsert());
assertEquals(3, QueryCountHolder.getGrandTotal().getInsert());
runInTransaction(()->{
assertEquals(1, myResourceTableDao.count());
assertEquals(1, myResourceHistoryTableDao.count());
@ -60,7 +60,7 @@ public class FhirResourceDaoR4UpdateTest extends BaseJpaR4Test {
p.getPhotoFirstRep().setCreationElement(new DateTimeType("2012")); // non-indexed field
myPatientDao.update(p).getId().toUnqualifiedVersionless();
assertEquals(2, QueryCountHolder.getGrandTotal().getInsert());
assertEquals(1, QueryCountHolder.getGrandTotal().getInsert());
runInTransaction(()->{
assertEquals(1, myResourceTableDao.count());
assertEquals(2, myResourceHistoryTableDao.count());

View File

@ -186,7 +186,7 @@ public class TerminologyLoaderSvcIntegrationDstu3Test extends BaseJpaDstu3Test {
assertTrue(propertyValue.isPresent());
assertEquals(IHapiTerminologyLoaderSvc.LOINC_URI, propertyValue.get().getSystem());
assertEquals("LP19258-0", propertyValue.get().getCode());
assertEquals("Qn", propertyValue.get().getDisplay());
assertEquals("Large unstained cells/100 leukocytes", propertyValue.get().getDisplay());
}

View File

@ -122,7 +122,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
myOtherOperatiopnType = RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE;
}
myReturnParams = new ArrayList<OperationMethodBinding.ReturnType>();
myReturnParams = new ArrayList<>();
if (theReturnParams != null) {
for (OperationParam next : theReturnParams) {
ReturnType type = new ReturnType();

View File

@ -1587,6 +1587,46 @@ public class AuthorizationInterceptorR4Test {
assertFalse(ourHitMethod);
}
@Test
public void testOperationTypeLevelDifferentBodyType() throws Exception {
ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) {
@Override
public List<IAuthRule> buildRuleList(RequestDetails theRequestDetails) {
return new RuleBuilder()
.allow("RULE 1").operation().named("process-message").onType(MessageHeader.class).andThen()
.build();
}
});
HttpPost httpPost;
HttpResponse status;
String response;
Bundle input = new Bundle();
input.setType(Bundle.BundleType.MESSAGE);
String inputString = ourCtx.newJsonParser().encodeResourceToString(input);
// With body
ourHitMethod = false;
httpPost = new HttpPost("http://localhost:" + ourPort + "/MessageHeader/$process-message");
httpPost.setEntity(new StringEntity(inputString, ContentType.create(Constants.CT_FHIR_JSON_NEW, Charsets.UTF_8)));
status = ourClient.execute(httpPost);
response = extractResponseAndClose(status);
ourLog.info(response);
assertEquals(200, status.getStatusLine().getStatusCode());
assertTrue(ourHitMethod);
// With body
ourHitMethod = false;
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/MessageHeader/$process-message");
status = ourClient.execute(httpGet);
response = extractResponseAndClose(status);
ourLog.info(response);
assertEquals(200, status.getStatusLine().getStatusCode());
assertTrue(ourHitMethod);
}
@Test
public void testOperationWithTester() throws Exception {
ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) {
@ -2946,12 +2986,13 @@ public class AuthorizationInterceptorR4Test {
DummyEncounterResourceProvider encProv = new DummyEncounterResourceProvider();
DummyCarePlanResourceProvider cpProv = new DummyCarePlanResourceProvider();
DummyDiagnosticReportResourceProvider drProv = new DummyDiagnosticReportResourceProvider();
DummyMessageHeaderResourceProvider mshProv = new DummyMessageHeaderResourceProvider();
PlainProvider plainProvider = new PlainProvider();
ServletHandler proxyHandler = new ServletHandler();
ourServlet = new RestfulServer(ourCtx);
ourServlet.setFhirContext(ourCtx);
ourServlet.setResourceProviders(patProvider, obsProv, encProv, cpProv, orgProv, drProv);
ourServlet.setResourceProviders(patProvider, obsProv, encProv, cpProv, orgProv, drProv, mshProv);
ourServlet.setPlainProviders(plainProvider);
ourServlet.setPagingProvider(new FifoMemoryPagingProvider(100));
ServletHolder servletHolder = new ServletHolder(ourServlet);
@ -3027,6 +3068,22 @@ public class AuthorizationInterceptorR4Test {
}
public static class DummyMessageHeaderResourceProvider implements IResourceProvider {
@Override
public Class<? extends IBaseResource> getResourceType() {
return MessageHeader.class;
}
@Operation(name = "process-message", idempotent = true)
public Parameters operation0(@OperationParam(name="content") Bundle theInput) {
ourHitMethod = true;
return (Parameters) new Parameters().setId("1");
}
}
public static class DummyDiagnosticReportResourceProvider implements IResourceProvider {