Search in sources :

Example 11 with OrganizationPrincipal

use of gov.cms.dpc.api.auth.OrganizationPrincipal in project dpc-app by CMSgov.

the class EndpointResourceUnitTest method testCreateEndpointWithManagingOrganizationMismatch.

@Test
public void testCreateEndpointWithManagingOrganizationMismatch() {
    UUID orgId = UUID.randomUUID();
    Organization organization = new Organization();
    organization.setId(orgId.toString());
    OrganizationPrincipal organizationPrincipal = new OrganizationPrincipal(organization);
    Endpoint endpoint = new Endpoint();
    endpoint.setManagingOrganization(new Reference("Organization/" + UUID.randomUUID()));
    assertThrows(WebApplicationException.class, () -> resource.createEndpoint(organizationPrincipal, endpoint));
}
Also used : OrganizationPrincipal(gov.cms.dpc.api.auth.OrganizationPrincipal) Organization(org.hl7.fhir.dstu3.model.Organization) Endpoint(org.hl7.fhir.dstu3.model.Endpoint) Reference(org.hl7.fhir.dstu3.model.Reference) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 12 with OrganizationPrincipal

use of gov.cms.dpc.api.auth.OrganizationPrincipal in project dpc-app by CMSgov.

the class PractitionerResourceUnitTest method testSubmitProvider.

@Test
public void testSubmitProvider() {
    UUID orgId = UUID.randomUUID();
    Organization organization = new Organization();
    organization.setId(orgId.toString());
    OrganizationPrincipal organizationPrincipal = new OrganizationPrincipal(organization);
    Practitioner practitioner = new Practitioner();
    ICreateTyped createExec = Mockito.mock(ICreateTyped.class);
    Mockito.when(attributionClient.create().resource(practitioner).encodedJson()).thenReturn(createExec);
    MethodOutcome outcome = new MethodOutcome();
    outcome.setResource(practitioner);
    Mockito.when(createExec.execute()).thenReturn(outcome);
    Response response = resource.submitProvider(organizationPrincipal, practitioner);
    Practitioner result = (Practitioner) response.getEntity();
    assertEquals(practitioner, result);
    assertEquals("Organization ID", practitioner.getMeta().getTag(DPCIdentifierSystem.DPC.getSystem(), orgId.toString()).getDisplay());
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) Response(javax.ws.rs.core.Response) OrganizationPrincipal(gov.cms.dpc.api.auth.OrganizationPrincipal) Organization(org.hl7.fhir.dstu3.model.Organization) ICreateTyped(ca.uhn.fhir.rest.gclient.ICreateTyped) UUID(java.util.UUID) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) Test(org.junit.jupiter.api.Test)

Example 13 with OrganizationPrincipal

use of gov.cms.dpc.api.auth.OrganizationPrincipal in project dpc-app by CMSgov.

the class ListClientTokens method execute.

@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception {
    final Organization organization = extractOrganization(parameters);
    final CollectionResponse<TokenEntity> organizationTokens = this.resource.getOrganizationTokens(new OrganizationPrincipal(organization));
    this.mapper.writeValue(output, organizationTokens);
}
Also used : OrganizationPrincipal(gov.cms.dpc.api.auth.OrganizationPrincipal) Organization(org.hl7.fhir.dstu3.model.Organization) TasksCommon.extractOrganization(gov.cms.dpc.api.tasks.TasksCommon.extractOrganization) TokenEntity(gov.cms.dpc.api.entities.TokenEntity)

Example 14 with OrganizationPrincipal

use of gov.cms.dpc.api.auth.OrganizationPrincipal in project dpc-app by CMSgov.

the class ListPublicKeys method execute.

@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception {
    final Organization organization = extractOrganization(parameters);
    final CollectionResponse<PublicKeyEntity> publicKeys = this.resource.getPublicKeys(new OrganizationPrincipal(organization));
    this.mapper.writeValue(output, publicKeys);
}
Also used : OrganizationPrincipal(gov.cms.dpc.api.auth.OrganizationPrincipal) Organization(org.hl7.fhir.dstu3.model.Organization) TasksCommon.extractOrganization(gov.cms.dpc.api.tasks.TasksCommon.extractOrganization) PublicKeyEntity(gov.cms.dpc.api.entities.PublicKeyEntity)

Example 15 with OrganizationPrincipal

use of gov.cms.dpc.api.auth.OrganizationPrincipal in project dpc-app by CMSgov.

the class DeleteToken method execute.

@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) {
    final Organization organization = extractOrganization(parameters);
    final ImmutableCollection<String> tokenCollection = parameters.get("token");
    if (tokenCollection.isEmpty()) {
        throw new WebApplicationException("Must have token", Response.Status.BAD_REQUEST);
    }
    final String tokenID = tokenCollection.asList().get(0);
    this.resource.deleteOrganizationToken(new OrganizationPrincipal(organization), UUID.fromString(tokenID));
}
Also used : OrganizationPrincipal(gov.cms.dpc.api.auth.OrganizationPrincipal) Organization(org.hl7.fhir.dstu3.model.Organization) TasksCommon.extractOrganization(gov.cms.dpc.api.tasks.TasksCommon.extractOrganization) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

OrganizationPrincipal (gov.cms.dpc.api.auth.OrganizationPrincipal)23 UUID (java.util.UUID)15 Test (org.junit.jupiter.api.Test)15 Organization (org.hl7.fhir.dstu3.model.Organization)11 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)6 ICreateTyped (ca.uhn.fhir.rest.gclient.ICreateTyped)6 Response (javax.ws.rs.core.Response)5 TasksCommon.extractOrganization (gov.cms.dpc.api.tasks.TasksCommon.extractOrganization)4 PublicKeyEntity (gov.cms.dpc.api.entities.PublicKeyEntity)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 TokenEntity (gov.cms.dpc.api.entities.TokenEntity)2 Endpoint (org.hl7.fhir.dstu3.model.Endpoint)2 FhirContext (ca.uhn.fhir.context.FhirContext)1 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Macaroon (com.github.nitram509.jmacaroons.Macaroon)1 DPCAuthCredentials (gov.cms.dpc.api.auth.DPCAuthCredentials)1 StaticAuthFilter (gov.cms.dpc.api.auth.staticauth.StaticAuthFilter)1 StaticAuthenticator (gov.cms.dpc.api.auth.staticauth.StaticAuthenticator)1 ChecksumConverterProvider (gov.cms.dpc.api.converters.ChecksumConverterProvider)1