PolRepPolicyProvider implements PolicyProvider { @Override public List<Evaluatable> getPolicies(XacmlRequest xacmlRequest) throws NoPolicyFoundException, PolicyProviderException { try { final String eid = xacmlRequest.getPatientId(); final String eidDomain = xacmlRequest.getHomeCommunityId(); final String mrn = getMrn(eid, eidDomain); final String policyId = toPolicyId(mrn, pidDomain, xacmlRequest.getRecipientSubjectNPI(), xacmlRequest.getIntermediarySubjectNPI()); final PolicyDto policyDto = polRepRestClient .getPoliciesCombinedAsPolicySet(policyId, WILDCARD, UUID .randomUUID().toString(), PolicyCombiningAlgIds.DENY_OVERRIDES); final Evaluatable policySet = PolicyMarshaller .unmarshal(new ByteArrayInputStream(policyDto.getPolicy())); return Arrays.asList(policySet); } catch (final SyntaxException e) { logger.error(xacmlRequest.getMessageId(), e.getMessage(), e); throw new PolicyProviderException(e.getMessage(), e); } catch (final HttpStatusCodeException e) { logger.error(xacmlRequest.getMessageId(), e.getMessage(), e); if (e.getStatusCode().is4xxClientError()) { logger.info(xacmlRequest.getMessageId(), e.getMessage()); throw new NoPolicyFoundException(e.getMessage(), e); } else { throw new PolicyProviderException(e.getMessage(), e); } } } PolRepPolicyProvider(String pidDomain, String pidDomainType,
			Hl7v3Transformer hl7v3Transformer,
			PixManagerRequestXMLToJava requestXMLToJava,
			PixManagerMessageHelper pixManagerMessageHelper,
			PixManagerService pixManagerService,
			PolRepRestClient polRepRestClient); @Override List<Evaluatable> getPolicies(XacmlRequest xacmlRequest);  }
@Test public void testGetPolicies() throws NoPolicyFoundException, PolicyProviderException, Hl7v3TransformerException, JAXBException, IOException { SimplePDPFactory.getSimplePDP(); final String homeCommunityId = "homeCommunityId"; final String intermediarySubjectNPI = "intermediarySubjectNPI"; final String messageId = "messageId"; final String patientId = "patientId"; final String patientUniqueId = "patientUniqueId"; final String purposeOfUse = "purposeOfUse"; final String recipientSubjectNPI = "recipientSubjectNPI"; final String xacml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Policy xmlns=\"urn:oasis:names:tc:xacml:2.0:policy:schema:os\" PolicyId=\"a07478e8-3642-42ff-980e-911e26ec3f47\" RuleCombiningAlgId=\"urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable\"><Description>This is a reference policy for consent2share@outlook.com</Description><Target/><Rule Effect=\"Permit\" RuleId=\"primary-group-rule\"><Target><Resources><Resource><ResourceMatch MatchId=\"urn:oasis:names:tc:xacml:1.0:function:string-regexp-match\"><AttributeValue DataType=\"http: final byte[] bytes = xacml.getBytes("UTF-8"); final XacmlRequest xacmlRequest = new XacmlRequest(); xacmlRequest.setHomeCommunityId(homeCommunityId); xacmlRequest.setIntermediarySubjectNPI(intermediarySubjectNPI); xacmlRequest.setMessageId(messageId); xacmlRequest.setPatientId(patientId); xacmlRequest.setPatientUniqueId(patientUniqueId); xacmlRequest.setPurposeOfUse(purposeOfUse); xacmlRequest.setRecipientSubjectNPI(recipientSubjectNPI); final PolicyDto policyDto = mock(PolicyDto.class); when( polRepRestClient.getPoliciesCombinedAsPolicySet(anyString(), anyString(), anyString(), eq(PolicyCombiningAlgIds.DENY_OVERRIDES))).thenReturn( policyDto); when(policyDto.getPolicy()).thenReturn(bytes); final String hl7Query = "hl7Query"; when( hl7v3Transformer.getPixQueryXml(eq(patientId), anyString(), eq(Hl7v3Transformer.XML_PIX_QUERY))).thenReturn( hl7Query); final PRPAIN201309UV02 req = mock(PRPAIN201309UV02.class); when( requestXMLToJava.getPIXQueryReqObject(hl7Query, PixManagerConstants.ENCODE_STRING)).thenReturn(req); final PRPAIN201310UV02 resp = mock(PRPAIN201310UV02.class); when(pixManagerService.pixManagerPRPAIN201309UV02(req)) .thenReturn(resp); final PixManagerBean pixManagerBean = mock(PixManagerBean.class); when( pixManagerMessageHelper.getQueryMessage(eq(resp), any(PixManagerBean.class))).thenReturn(pixManagerBean); final List<Evaluatable> response = sut.getPolicies(xacmlRequest); assertNotNull(response); assertTrue(response.size() == 1); assertNotNull(response.get(0)); }
@Test public void testGetPolicies_Throws_NoPolicyFoundException() throws NoPolicyFoundException, PolicyProviderException, Hl7v3TransformerException, JAXBException, IOException { thrown.expect(NoPolicyFoundException.class); SimplePDPFactory.getSimplePDP(); final String homeCommunityId = "homeCommunityId"; final String intermediarySubjectNPI = "intermediarySubjectNPI"; final String messageId = "messageId"; final String patientId = "patientId"; final String patientUniqueId = "patientUniqueId"; final String purposeOfUse = "purposeOfUse"; final String recipientSubjectNPI = "recipientSubjectNPI"; final String xacml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Policy xmlns=\"urn:oasis:names:tc:xacml:2.0:policy:schema:os\" PolicyId=\"a07478e8-3642-42ff-980e-911e26ec3f47\" RuleCombiningAlgId=\"urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable\"><Description>This is a reference policy for consent2share@outlook.com</Description><Target/><Rule Effect=\"Permit\" RuleId=\"primary-group-rule\"><Target><Resources><Resource><ResourceMatch MatchId=\"urn:oasis:names:tc:xacml:1.0:function:string-regexp-match\"><AttributeValue DataType=\"http: final byte[] bytes = xacml.getBytes("UTF-8"); final XacmlRequest xacmlRequest = new XacmlRequest(); xacmlRequest.setHomeCommunityId(homeCommunityId); xacmlRequest.setIntermediarySubjectNPI(intermediarySubjectNPI); xacmlRequest.setMessageId(messageId); xacmlRequest.setPatientId(patientId); xacmlRequest.setPatientUniqueId(patientUniqueId); xacmlRequest.setPurposeOfUse(purposeOfUse); xacmlRequest.setRecipientSubjectNPI(recipientSubjectNPI); final PolicyDto policyDto = mock(PolicyDto.class); final HttpStatusCodeException e = new HttpStatusCodeExceptionImpl( HttpStatus.NOT_FOUND); when( polRepRestClient.getPoliciesCombinedAsPolicySet(anyString(), anyString(), anyString(), eq(PolicyCombiningAlgIds.DENY_OVERRIDES))).thenThrow(e); when(policyDto.getPolicy()).thenReturn(bytes); final String hl7Query = "hl7Query"; when( hl7v3Transformer.getPixQueryXml(eq(patientId), anyString(), eq(Hl7v3Transformer.XML_PIX_QUERY))).thenReturn( hl7Query); final PRPAIN201309UV02 req = mock(PRPAIN201309UV02.class); when( requestXMLToJava.getPIXQueryReqObject(hl7Query, PixManagerConstants.ENCODE_STRING)).thenReturn(req); final PRPAIN201310UV02 resp = mock(PRPAIN201310UV02.class); when(pixManagerService.pixManagerPRPAIN201309UV02(req)) .thenReturn(resp); final PixManagerBean pixManagerBean = mock(PixManagerBean.class); when( pixManagerMessageHelper.getQueryMessage(eq(resp), any(PixManagerBean.class))).thenReturn(pixManagerBean); final List<Evaluatable> response = sut.getPolicies(xacmlRequest); assertNotNull(response); assertTrue(response.size() == 1); assertNotNull(response.get(0)); }
@Test public void testGetPolicies_Throws_PolicyProviderException() throws NoPolicyFoundException, PolicyProviderException, Hl7v3TransformerException, JAXBException, IOException { thrown.expect(PolicyProviderException.class); SimplePDPFactory.getSimplePDP(); final String homeCommunityId = "homeCommunityId"; final String intermediarySubjectNPI = "intermediarySubjectNPI"; final String messageId = "messageId"; final String patientId = "patientId"; final String patientUniqueId = "patientUniqueId"; final String purposeOfUse = "purposeOfUse"; final String recipientSubjectNPI = "recipientSubjectNPI"; final String xacml = "NotXacml"; final byte[] bytes = xacml.getBytes("UTF-8"); final XacmlRequest xacmlRequest = new XacmlRequest(); xacmlRequest.setHomeCommunityId(homeCommunityId); xacmlRequest.setIntermediarySubjectNPI(intermediarySubjectNPI); xacmlRequest.setMessageId(messageId); xacmlRequest.setPatientId(patientId); xacmlRequest.setPatientUniqueId(patientUniqueId); xacmlRequest.setPurposeOfUse(purposeOfUse); xacmlRequest.setRecipientSubjectNPI(recipientSubjectNPI); final PolicyDto policyDto = mock(PolicyDto.class); when( polRepRestClient.getPoliciesCombinedAsPolicySet(anyString(), anyString(), anyString(), eq(PolicyCombiningAlgIds.DENY_OVERRIDES))).thenReturn( policyDto); when(policyDto.getPolicy()).thenReturn(bytes); final String hl7Query = "hl7Query"; when( hl7v3Transformer.getPixQueryXml(eq(patientId), anyString(), eq(Hl7v3Transformer.XML_PIX_QUERY))).thenReturn( hl7Query); final PRPAIN201309UV02 req = mock(PRPAIN201309UV02.class); when( requestXMLToJava.getPIXQueryReqObject(hl7Query, PixManagerConstants.ENCODE_STRING)).thenReturn(req); final PRPAIN201310UV02 resp = mock(PRPAIN201310UV02.class); when(pixManagerService.pixManagerPRPAIN201309UV02(req)) .thenReturn(resp); final PixManagerBean pixManagerBean = mock(PixManagerBean.class); when( pixManagerMessageHelper.getQueryMessage(eq(resp), any(PixManagerBean.class))).thenReturn(pixManagerBean); final List<Evaluatable> response = sut.getPolicies(xacmlRequest); assertNotNull(response); assertTrue(response.size() == 1); assertNotNull(response.get(0)); }