XacmlPolicyListFilter { public void filterByNPI(List<String> policies, String recipientSubjectNPI, String intermediarySubjectNPI) throws Exception { LinkedList<String> removeList = new LinkedList<String>(); for (String policy : policies) { Document policyDoc = documentXmlConverter.loadDocument(policy); String xPathExprIntermediary = XPATH_CONDITION_ATTRIBUTE_VALUE .replace("$", URN_XACML_1_INTERMEDIARY_SUBJECT); NodeList nodeListIntermediaryNPI = this.documentAccessor .getNodeList(policyDoc, xPathExprIntermediary); boolean containsIntermediaryNPI = containsInValue( nodeListIntermediaryNPI, intermediarySubjectNPI); if (containsIntermediaryNPI == false) { removeList.add(policy); } else { String xPathExprRecipient = XPATH_CONDITION_ATTRIBUTE_VALUE .replace("$", URN_XACML_1_RECIPIENT_SUBJECT); NodeList nodeListRecipientNPI = this.documentAccessor .getNodeList(policyDoc, xPathExprRecipient); boolean containsRecipientNPI = containsInValue( nodeListRecipientNPI, recipientSubjectNPI); if (containsRecipientNPI == false) { removeList.add(policy); } } } policies.removeAll(removeList); } XacmlPolicyListFilter(DocumentXmlConverter documentXmlConverter,
			DocumentAccessor documentAccessor); void filterByNPI(List<String> policies, String recipientSubjectNPI,
			String intermediarySubjectNPI); boolean containsInValue(NodeList nodeList, String value); static final String URN_XACML_1_INTERMEDIARY_SUBJECT; static final String URN_XACML_1_RECIPIENT_SUBJECT; static final String XPATH_CONDITION_ATTRIBUTE_VALUE; }
@Test public void testFilterByNPI_Policy1() throws Exception { sut.filterByNPI(policyList, "1760717789", "1114252178"); assertTrue(policyList.contains(policy1)); assertTrue(!policyList.contains(policy2)); }
@Test public void testFilterByNPI_Policy2() throws Exception { sut.filterByNPI(policyList, "22222", "11111"); assertTrue(!policyList.contains(policy1)); assertTrue(policyList.contains(policy2)); }