@Test public void testDirectEmailSend() throws Throwable { when(xdsbRegistry.getPatientUniqueId(anyString(), anyString())) .thenReturn(patientUniqueId); when(contextHandler.enforcePolicy(isA(XacmlRequest.class))).thenReturn( xacmlResponse).thenReturn(xacmlResponse); when( xdsbRepository.retrieveDocumentSet( any(RetrieveDocumentSetRequest.class), anyString(), anyString())).thenReturn(retrieveDocumentSetResponse); when(marshaller.marshal(isA(Object.class))).thenReturn( enforcementPolicies).thenReturn(enforcementPolicies); dSSResponseForDirect1 = mock(DSSResponseForDirect.class); when( documentSegmentation .segmentDocumentForDirect(isA(DSSRequestForDirect.class))) .thenReturn(dSSResponseForDirect1); when(context.getUserPrincipal()).thenReturn(samlTokenPrincipal); when( samlTokenParser.parse(samlTokenPrincipal.getToken(), "urn:oasis:names:tc:xacml:1.0:resource:resource-id")) .thenReturn( "d3bb3930-7241-11e3-b4f7-00155d3a2124^^^&2.16.840.1.113883.4.357&ISO"); when( samlTokenParser.parse(samlTokenPrincipal.getToken(), "urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject")) .thenReturn("1114252178"); when( samlTokenParser.parse(samlTokenPrincipal.getToken(), "urn:oasis:names:tc:xspa:1.0:subject:purposeofuse")) .thenReturn("TREATMENT"); when( samlTokenParser.parse(samlTokenPrincipal.getToken(), "urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject")) .thenReturn("1760717789"); when(dSSResponseForDirect1.getDocumentPayloadRawData()).thenReturn( dataHandler); when(dataHandlerToBytesConverter.toByteArray(any(DataHandler.class))) .thenReturn(byteValue); final DirectEmailSendResponse response = pep .directEmailSend(directEmailSendRequest); }
@Override public DirectEmailSendResponse directEmailSend(DirectEmailSendRequest input) { final DirectEmailSendResponse response = new DirectEmailSendResponse(); XacmlRequest xacmlRequest = null; String resourceId = null; String intermediarySubject = null; String purposeOfUse = null; String recipientSubject = null; final String messageId = createMessageId(); final String INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"; final String NO_POLICY = "NO_POLICY"; PolicyEnforcementPointResponseStatus pepResponseStatus = PolicyEnforcementPointResponseStatus.SUCCESS; try { logger.debug(messageId, aspectUtils.getInXMLFormat(input)); final SAMLTokenPrincipal samlTokenPrincipal = getUserPrincipal(messageId); resourceId = parseSamlToken(samlTokenPrincipal, URN_RESOURCE_ID, messageId); intermediarySubject = parseSamlToken(samlTokenPrincipal, URN_INTERMEDIARY_SUBJECT, messageId); purposeOfUse = parseSamlToken(samlTokenPrincipal, URN_PURPOSE_OF_USE, messageId); recipientSubject = parseSamlToken(samlTokenPrincipal, URN_RECIPIENT_SUBJECT, messageId); xacmlRequest = setXacmlRequest(resourceId, purposeOfUse, intermediarySubject, recipientSubject, messageId); logger.debug(messageId, aspectUtils.getInXMLFormat(xacmlRequest)); auditRequest(input, xacmlRequest); final XacmlResponse xacmlResponse = contextHandler .enforcePolicy(xacmlRequest); logger.debug(messageId, aspectUtils.getInXMLFormat(xacmlResponse)); if (PERMIT.equals(xacmlResponse.getPdpDecision())) { response.setPdpDecision(PERMIT); final String originalC32 = input.getC32(); byte[] processedPayload; final XacmlResult xacmlResult = createXacmlResult(xacmlRequest, xacmlResponse); final String xacmlResultString = marshaller .marshal(xacmlResult); final String xdsDocumentEntryUniqueId = ""; final boolean packageAsXdm = true; final DSSRequestForDirect request = new DSSRequestForDirect(); request.setDocumentXml(originalC32); request.setEnforcementPoliciesXml(xacmlResultString); request.setAudited(true); request.setAuditFailureByPass(isAuditFailureByPass); request.setPackageAsXdm(packageAsXdm); request.setRecipientEmailAddress(input.getRecipientEmail()); request.setSenderEmailAddress(input.getSenderEmail()); request.setXdsDocumentEntryUniqueId(xdsDocumentEntryUniqueId); final DSSResponseForDirect segmentDocumentResponse = documentSegmentation .segmentDocumentForDirect(request); processedPayload = dataHandlerToBytesConverter .toByteArray(segmentDocumentResponse .getDocumentPayloadRawData()); response.setMaskedDocument(segmentDocumentResponse .getSegmentedDocumentXml()); response.setFilteredStreamBody(processedPayload); } else { handlePDPDeny(messageId, xacmlRequest, xacmlResponse); } } catch (final SamlTokenPrincipalException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error( messageId, "SAMLTokenPrincipal cannot be retrieved from WebServiceContext.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final SamlTokenParserException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "SamlTokenParser failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final AuditException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "AuditService failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final NoPolicyFoundException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_CONSENT; logger.info(messageId, e.getMessage()); logger.debug(messageId, e.getMessage(), e); response.setPdpDecision(NO_POLICY); } catch (final PolicyProviderException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "PolicyProvider failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final XmlDocumentReadFailureException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; final StringBuilder errorBuilder = new StringBuilder(); errorBuilder .append("Schema validation failed: Unable to load schema: "); errorBuilder.append(e.getMessage()); errorBuilder.append("."); logger.error(messageId, errorBuilder.toString(), e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final IOException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "DataHandlerToBytesConverter failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final SimpleMarshallerException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "SimpleMarshaller failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final Throwable t) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "Unexpected exception occured in PolicyEnforcementPoint.", t); response.setPdpDecision(INTERNAL_SERVER_ERROR); } finally { try { if (xacmlRequest == null) { xacmlRequest = setXacmlRequestIfNull(resourceId, messageId); } auditResponse(response, xacmlRequest, pepResponseStatus); } catch (final Throwable e) { logger.error(messageId, "Cannot audit the response.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } } Assert.notNull(response.getPdpDecision()); return response; }
PolicyEnforcementPointImpl implements PolicyEnforcementPoint { @Override public DirectEmailSendResponse directEmailSend(DirectEmailSendRequest input) { final DirectEmailSendResponse response = new DirectEmailSendResponse(); XacmlRequest xacmlRequest = null; String resourceId = null; String intermediarySubject = null; String purposeOfUse = null; String recipientSubject = null; final String messageId = createMessageId(); final String INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"; final String NO_POLICY = "NO_POLICY"; PolicyEnforcementPointResponseStatus pepResponseStatus = PolicyEnforcementPointResponseStatus.SUCCESS; try { logger.debug(messageId, aspectUtils.getInXMLFormat(input)); final SAMLTokenPrincipal samlTokenPrincipal = getUserPrincipal(messageId); resourceId = parseSamlToken(samlTokenPrincipal, URN_RESOURCE_ID, messageId); intermediarySubject = parseSamlToken(samlTokenPrincipal, URN_INTERMEDIARY_SUBJECT, messageId); purposeOfUse = parseSamlToken(samlTokenPrincipal, URN_PURPOSE_OF_USE, messageId); recipientSubject = parseSamlToken(samlTokenPrincipal, URN_RECIPIENT_SUBJECT, messageId); xacmlRequest = setXacmlRequest(resourceId, purposeOfUse, intermediarySubject, recipientSubject, messageId); logger.debug(messageId, aspectUtils.getInXMLFormat(xacmlRequest)); auditRequest(input, xacmlRequest); final XacmlResponse xacmlResponse = contextHandler .enforcePolicy(xacmlRequest); logger.debug(messageId, aspectUtils.getInXMLFormat(xacmlResponse)); if (PERMIT.equals(xacmlResponse.getPdpDecision())) { response.setPdpDecision(PERMIT); final String originalC32 = input.getC32(); byte[] processedPayload; final XacmlResult xacmlResult = createXacmlResult(xacmlRequest, xacmlResponse); final String xacmlResultString = marshaller .marshal(xacmlResult); final String xdsDocumentEntryUniqueId = ""; final boolean packageAsXdm = true; final DSSRequestForDirect request = new DSSRequestForDirect(); request.setDocumentXml(originalC32); request.setEnforcementPoliciesXml(xacmlResultString); request.setAudited(true); request.setAuditFailureByPass(isAuditFailureByPass); request.setPackageAsXdm(packageAsXdm); request.setRecipientEmailAddress(input.getRecipientEmail()); request.setSenderEmailAddress(input.getSenderEmail()); request.setXdsDocumentEntryUniqueId(xdsDocumentEntryUniqueId); final DSSResponseForDirect segmentDocumentResponse = documentSegmentation .segmentDocumentForDirect(request); processedPayload = dataHandlerToBytesConverter .toByteArray(segmentDocumentResponse .getDocumentPayloadRawData()); response.setMaskedDocument(segmentDocumentResponse .getSegmentedDocumentXml()); response.setFilteredStreamBody(processedPayload); } else { handlePDPDeny(messageId, xacmlRequest, xacmlResponse); } } catch (final SamlTokenPrincipalException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error( messageId, "SAMLTokenPrincipal cannot be retrieved from WebServiceContext.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final SamlTokenParserException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "SamlTokenParser failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final AuditException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "AuditService failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final NoPolicyFoundException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_CONSENT; logger.info(messageId, e.getMessage()); logger.debug(messageId, e.getMessage(), e); response.setPdpDecision(NO_POLICY); } catch (final PolicyProviderException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "PolicyProvider failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final XmlDocumentReadFailureException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; final StringBuilder errorBuilder = new StringBuilder(); errorBuilder .append("Schema validation failed: Unable to load schema: "); errorBuilder.append(e.getMessage()); errorBuilder.append("."); logger.error(messageId, errorBuilder.toString(), e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final IOException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "DataHandlerToBytesConverter failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final SimpleMarshallerException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "SimpleMarshaller failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final Throwable t) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "Unexpected exception occured in PolicyEnforcementPoint.", t); response.setPdpDecision(INTERNAL_SERVER_ERROR); } finally { try { if (xacmlRequest == null) { xacmlRequest = setXacmlRequestIfNull(resourceId, messageId); } auditResponse(response, xacmlRequest, pepResponseStatus); } catch (final Throwable e) { logger.error(messageId, "Cannot audit the response.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } } Assert.notNull(response.getPdpDecision()); return response; } }
PolicyEnforcementPointImpl implements PolicyEnforcementPoint { @Override public DirectEmailSendResponse directEmailSend(DirectEmailSendRequest input) { final DirectEmailSendResponse response = new DirectEmailSendResponse(); XacmlRequest xacmlRequest = null; String resourceId = null; String intermediarySubject = null; String purposeOfUse = null; String recipientSubject = null; final String messageId = createMessageId(); final String INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"; final String NO_POLICY = "NO_POLICY"; PolicyEnforcementPointResponseStatus pepResponseStatus = PolicyEnforcementPointResponseStatus.SUCCESS; try { logger.debug(messageId, aspectUtils.getInXMLFormat(input)); final SAMLTokenPrincipal samlTokenPrincipal = getUserPrincipal(messageId); resourceId = parseSamlToken(samlTokenPrincipal, URN_RESOURCE_ID, messageId); intermediarySubject = parseSamlToken(samlTokenPrincipal, URN_INTERMEDIARY_SUBJECT, messageId); purposeOfUse = parseSamlToken(samlTokenPrincipal, URN_PURPOSE_OF_USE, messageId); recipientSubject = parseSamlToken(samlTokenPrincipal, URN_RECIPIENT_SUBJECT, messageId); xacmlRequest = setXacmlRequest(resourceId, purposeOfUse, intermediarySubject, recipientSubject, messageId); logger.debug(messageId, aspectUtils.getInXMLFormat(xacmlRequest)); auditRequest(input, xacmlRequest); final XacmlResponse xacmlResponse = contextHandler .enforcePolicy(xacmlRequest); logger.debug(messageId, aspectUtils.getInXMLFormat(xacmlResponse)); if (PERMIT.equals(xacmlResponse.getPdpDecision())) { response.setPdpDecision(PERMIT); final String originalC32 = input.getC32(); byte[] processedPayload; final XacmlResult xacmlResult = createXacmlResult(xacmlRequest, xacmlResponse); final String xacmlResultString = marshaller .marshal(xacmlResult); final String xdsDocumentEntryUniqueId = ""; final boolean packageAsXdm = true; final DSSRequestForDirect request = new DSSRequestForDirect(); request.setDocumentXml(originalC32); request.setEnforcementPoliciesXml(xacmlResultString); request.setAudited(true); request.setAuditFailureByPass(isAuditFailureByPass); request.setPackageAsXdm(packageAsXdm); request.setRecipientEmailAddress(input.getRecipientEmail()); request.setSenderEmailAddress(input.getSenderEmail()); request.setXdsDocumentEntryUniqueId(xdsDocumentEntryUniqueId); final DSSResponseForDirect segmentDocumentResponse = documentSegmentation .segmentDocumentForDirect(request); processedPayload = dataHandlerToBytesConverter .toByteArray(segmentDocumentResponse .getDocumentPayloadRawData()); response.setMaskedDocument(segmentDocumentResponse .getSegmentedDocumentXml()); response.setFilteredStreamBody(processedPayload); } else { handlePDPDeny(messageId, xacmlRequest, xacmlResponse); } } catch (final SamlTokenPrincipalException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error( messageId, "SAMLTokenPrincipal cannot be retrieved from WebServiceContext.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final SamlTokenParserException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "SamlTokenParser failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final AuditException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "AuditService failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final NoPolicyFoundException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_CONSENT; logger.info(messageId, e.getMessage()); logger.debug(messageId, e.getMessage(), e); response.setPdpDecision(NO_POLICY); } catch (final PolicyProviderException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "PolicyProvider failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final XmlDocumentReadFailureException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; final StringBuilder errorBuilder = new StringBuilder(); errorBuilder .append("Schema validation failed: Unable to load schema: "); errorBuilder.append(e.getMessage()); errorBuilder.append("."); logger.error(messageId, errorBuilder.toString(), e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final IOException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "DataHandlerToBytesConverter failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final SimpleMarshallerException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "SimpleMarshaller failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final Throwable t) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "Unexpected exception occured in PolicyEnforcementPoint.", t); response.setPdpDecision(INTERNAL_SERVER_ERROR); } finally { try { if (xacmlRequest == null) { xacmlRequest = setXacmlRequestIfNull(resourceId, messageId); } auditResponse(response, xacmlRequest, pepResponseStatus); } catch (final Throwable e) { logger.error(messageId, "Cannot audit the response.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } } Assert.notNull(response.getPdpDecision()); return response; } PolicyEnforcementPointImpl(boolean isAuditFailureByPass,
			XdsbRegistryAdapter xdsbRegistry,
			XdsbRepositoryAdapter xdsbRepository,
			XdsbErrorFactory xdsbErrorFactory, ContextHandler contextHandler,
			DSSWebServiceClient documentSegmentation,
			SimpleMarshaller marshaller, WebServiceContext context,
			SamlTokenParser parser,
			DataHandlerToBytesConverter dataHandlerToBytesConverter,
			AuditService auditService, AspectUtils aspectUtils); }
PolicyEnforcementPointImpl implements PolicyEnforcementPoint { @Override public DirectEmailSendResponse directEmailSend(DirectEmailSendRequest input) { final DirectEmailSendResponse response = new DirectEmailSendResponse(); XacmlRequest xacmlRequest = null; String resourceId = null; String intermediarySubject = null; String purposeOfUse = null; String recipientSubject = null; final String messageId = createMessageId(); final String INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"; final String NO_POLICY = "NO_POLICY"; PolicyEnforcementPointResponseStatus pepResponseStatus = PolicyEnforcementPointResponseStatus.SUCCESS; try { logger.debug(messageId, aspectUtils.getInXMLFormat(input)); final SAMLTokenPrincipal samlTokenPrincipal = getUserPrincipal(messageId); resourceId = parseSamlToken(samlTokenPrincipal, URN_RESOURCE_ID, messageId); intermediarySubject = parseSamlToken(samlTokenPrincipal, URN_INTERMEDIARY_SUBJECT, messageId); purposeOfUse = parseSamlToken(samlTokenPrincipal, URN_PURPOSE_OF_USE, messageId); recipientSubject = parseSamlToken(samlTokenPrincipal, URN_RECIPIENT_SUBJECT, messageId); xacmlRequest = setXacmlRequest(resourceId, purposeOfUse, intermediarySubject, recipientSubject, messageId); logger.debug(messageId, aspectUtils.getInXMLFormat(xacmlRequest)); auditRequest(input, xacmlRequest); final XacmlResponse xacmlResponse = contextHandler .enforcePolicy(xacmlRequest); logger.debug(messageId, aspectUtils.getInXMLFormat(xacmlResponse)); if (PERMIT.equals(xacmlResponse.getPdpDecision())) { response.setPdpDecision(PERMIT); final String originalC32 = input.getC32(); byte[] processedPayload; final XacmlResult xacmlResult = createXacmlResult(xacmlRequest, xacmlResponse); final String xacmlResultString = marshaller .marshal(xacmlResult); final String xdsDocumentEntryUniqueId = ""; final boolean packageAsXdm = true; final DSSRequestForDirect request = new DSSRequestForDirect(); request.setDocumentXml(originalC32); request.setEnforcementPoliciesXml(xacmlResultString); request.setAudited(true); request.setAuditFailureByPass(isAuditFailureByPass); request.setPackageAsXdm(packageAsXdm); request.setRecipientEmailAddress(input.getRecipientEmail()); request.setSenderEmailAddress(input.getSenderEmail()); request.setXdsDocumentEntryUniqueId(xdsDocumentEntryUniqueId); final DSSResponseForDirect segmentDocumentResponse = documentSegmentation .segmentDocumentForDirect(request); processedPayload = dataHandlerToBytesConverter .toByteArray(segmentDocumentResponse .getDocumentPayloadRawData()); response.setMaskedDocument(segmentDocumentResponse .getSegmentedDocumentXml()); response.setFilteredStreamBody(processedPayload); } else { handlePDPDeny(messageId, xacmlRequest, xacmlResponse); } } catch (final SamlTokenPrincipalException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error( messageId, "SAMLTokenPrincipal cannot be retrieved from WebServiceContext.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final SamlTokenParserException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "SamlTokenParser failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final AuditException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "AuditService failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final NoPolicyFoundException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_CONSENT; logger.info(messageId, e.getMessage()); logger.debug(messageId, e.getMessage(), e); response.setPdpDecision(NO_POLICY); } catch (final PolicyProviderException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "PolicyProvider failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final XmlDocumentReadFailureException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; final StringBuilder errorBuilder = new StringBuilder(); errorBuilder .append("Schema validation failed: Unable to load schema: "); errorBuilder.append(e.getMessage()); errorBuilder.append("."); logger.error(messageId, errorBuilder.toString(), e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final IOException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "DataHandlerToBytesConverter failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final SimpleMarshallerException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "SimpleMarshaller failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final Throwable t) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "Unexpected exception occured in PolicyEnforcementPoint.", t); response.setPdpDecision(INTERNAL_SERVER_ERROR); } finally { try { if (xacmlRequest == null) { xacmlRequest = setXacmlRequestIfNull(resourceId, messageId); } auditResponse(response, xacmlRequest, pepResponseStatus); } catch (final Throwable e) { logger.error(messageId, "Cannot audit the response.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } } Assert.notNull(response.getPdpDecision()); return response; } PolicyEnforcementPointImpl(boolean isAuditFailureByPass,
			XdsbRegistryAdapter xdsbRegistry,
			XdsbRepositoryAdapter xdsbRepository,
			XdsbErrorFactory xdsbErrorFactory, ContextHandler contextHandler,
			DSSWebServiceClient documentSegmentation,
			SimpleMarshaller marshaller, WebServiceContext context,
			SamlTokenParser parser,
			DataHandlerToBytesConverter dataHandlerToBytesConverter,
			AuditService auditService, AspectUtils aspectUtils); @Override DirectEmailSendResponse directEmailSend(DirectEmailSendRequest input); @Override AdhocQueryResponse registryStoredQuery(AdhocQueryRequest req); @Override RetrieveDocumentSetResponse retrieveDocumentSet(
			RetrieveDocumentSetRequest input); XacmlRequest setXacmlRequest(String resourceId, String purposeOfUse,
			String intermediarySubject, String recipientSubject,
			String messageId); XacmlRequest setXacmlRequestIfNull(String resourceId,
			final String messageId); }
PolicyEnforcementPointImpl implements PolicyEnforcementPoint { @Override public DirectEmailSendResponse directEmailSend(DirectEmailSendRequest input) { final DirectEmailSendResponse response = new DirectEmailSendResponse(); XacmlRequest xacmlRequest = null; String resourceId = null; String intermediarySubject = null; String purposeOfUse = null; String recipientSubject = null; final String messageId = createMessageId(); final String INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"; final String NO_POLICY = "NO_POLICY"; PolicyEnforcementPointResponseStatus pepResponseStatus = PolicyEnforcementPointResponseStatus.SUCCESS; try { logger.debug(messageId, aspectUtils.getInXMLFormat(input)); final SAMLTokenPrincipal samlTokenPrincipal = getUserPrincipal(messageId); resourceId = parseSamlToken(samlTokenPrincipal, URN_RESOURCE_ID, messageId); intermediarySubject = parseSamlToken(samlTokenPrincipal, URN_INTERMEDIARY_SUBJECT, messageId); purposeOfUse = parseSamlToken(samlTokenPrincipal, URN_PURPOSE_OF_USE, messageId); recipientSubject = parseSamlToken(samlTokenPrincipal, URN_RECIPIENT_SUBJECT, messageId); xacmlRequest = setXacmlRequest(resourceId, purposeOfUse, intermediarySubject, recipientSubject, messageId); logger.debug(messageId, aspectUtils.getInXMLFormat(xacmlRequest)); auditRequest(input, xacmlRequest); final XacmlResponse xacmlResponse = contextHandler .enforcePolicy(xacmlRequest); logger.debug(messageId, aspectUtils.getInXMLFormat(xacmlResponse)); if (PERMIT.equals(xacmlResponse.getPdpDecision())) { response.setPdpDecision(PERMIT); final String originalC32 = input.getC32(); byte[] processedPayload; final XacmlResult xacmlResult = createXacmlResult(xacmlRequest, xacmlResponse); final String xacmlResultString = marshaller .marshal(xacmlResult); final String xdsDocumentEntryUniqueId = ""; final boolean packageAsXdm = true; final DSSRequestForDirect request = new DSSRequestForDirect(); request.setDocumentXml(originalC32); request.setEnforcementPoliciesXml(xacmlResultString); request.setAudited(true); request.setAuditFailureByPass(isAuditFailureByPass); request.setPackageAsXdm(packageAsXdm); request.setRecipientEmailAddress(input.getRecipientEmail()); request.setSenderEmailAddress(input.getSenderEmail()); request.setXdsDocumentEntryUniqueId(xdsDocumentEntryUniqueId); final DSSResponseForDirect segmentDocumentResponse = documentSegmentation .segmentDocumentForDirect(request); processedPayload = dataHandlerToBytesConverter .toByteArray(segmentDocumentResponse .getDocumentPayloadRawData()); response.setMaskedDocument(segmentDocumentResponse .getSegmentedDocumentXml()); response.setFilteredStreamBody(processedPayload); } else { handlePDPDeny(messageId, xacmlRequest, xacmlResponse); } } catch (final SamlTokenPrincipalException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error( messageId, "SAMLTokenPrincipal cannot be retrieved from WebServiceContext.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final SamlTokenParserException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "SamlTokenParser failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final AuditException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "AuditService failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final NoPolicyFoundException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_CONSENT; logger.info(messageId, e.getMessage()); logger.debug(messageId, e.getMessage(), e); response.setPdpDecision(NO_POLICY); } catch (final PolicyProviderException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "PolicyProvider failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final XmlDocumentReadFailureException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; final StringBuilder errorBuilder = new StringBuilder(); errorBuilder .append("Schema validation failed: Unable to load schema: "); errorBuilder.append(e.getMessage()); errorBuilder.append("."); logger.error(messageId, errorBuilder.toString(), e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final IOException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "DataHandlerToBytesConverter failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final SimpleMarshallerException e) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "SimpleMarshaller failed.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } catch (final Throwable t) { pepResponseStatus = PolicyEnforcementPointResponseStatus.ERROR_SYSTEM; logger.error(messageId, "Unexpected exception occured in PolicyEnforcementPoint.", t); response.setPdpDecision(INTERNAL_SERVER_ERROR); } finally { try { if (xacmlRequest == null) { xacmlRequest = setXacmlRequestIfNull(resourceId, messageId); } auditResponse(response, xacmlRequest, pepResponseStatus); } catch (final Throwable e) { logger.error(messageId, "Cannot audit the response.", e); response.setPdpDecision(INTERNAL_SERVER_ERROR); } } Assert.notNull(response.getPdpDecision()); return response; } PolicyEnforcementPointImpl(boolean isAuditFailureByPass,
			XdsbRegistryAdapter xdsbRegistry,
			XdsbRepositoryAdapter xdsbRepository,
			XdsbErrorFactory xdsbErrorFactory, ContextHandler contextHandler,
			DSSWebServiceClient documentSegmentation,
			SimpleMarshaller marshaller, WebServiceContext context,
			SamlTokenParser parser,
			DataHandlerToBytesConverter dataHandlerToBytesConverter,
			AuditService auditService, AspectUtils aspectUtils); @Override DirectEmailSendResponse directEmailSend(DirectEmailSendRequest input); @Override AdhocQueryResponse registryStoredQuery(AdhocQueryRequest req); @Override RetrieveDocumentSetResponse retrieveDocumentSet(
			RetrieveDocumentSetRequest input); XacmlRequest setXacmlRequest(String resourceId, String purposeOfUse,
			String intermediarySubject, String recipientSubject,
			String messageId); XacmlRequest setXacmlRequestIfNull(String resourceId,
			final String messageId); static final String PERMIT; static final String SUPPORTED_ADHOCQUERY_RESPONSE_TYPE; static final String URN_RESOURCE_ID; static final String URN_INTERMEDIARY_SUBJECT; static final String URN_RECIPIENT_SUBJECT; static final String URN_PURPOSE_OF_USE; }