Search in sources :

Example 1 with NonRepudiationInformation

use of com.helger.phase4.ebms3header.NonRepudiationInformation in project phase4 by phax.

the class AS4ReceiptMessage method create.

/**
 * This method creates a receipt message.
 *
 * @param eSoapVersion
 *        SOAP Version which should be used
 * @param sMessageID
 *        Message ID to use. May neither be <code>null</code> nor empty.
 * @param aEbms3UserMessage
 *        The received usermessage which should be responded too
 * @param aSoapDocument
 *        If the SOAPDocument has WSS4j elements and the following parameter
 *        is true NonRepudiation will be used if the message is signed
 * @param bShouldUseNonRepudiation
 *        If NonRepudiation should be used or not
 * @return AS4ReceiptMessage
 */
@Nonnull
public static AS4ReceiptMessage create(@Nonnull final ESoapVersion eSoapVersion, @Nonnull @Nonempty final String sMessageID, @Nullable final Ebms3UserMessage aEbms3UserMessage, @Nullable final Node aSoapDocument, @Nonnull final boolean bShouldUseNonRepudiation) {
    // Only for signed messages
    final ICommonsList<Node> aDSRefs = _getAllReferences(aSoapDocument);
    final Ebms3SignalMessage aSignalMessage = new Ebms3SignalMessage();
    // Message Info
    {
        // Always use "now" as date time
        final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo(sMessageID, aEbms3UserMessage != null ? aEbms3UserMessage.getMessageInfo().getMessageId() : null);
        aSignalMessage.setMessageInfo(aEbms3MessageInfo);
    }
    final Ebms3Receipt aEbms3Receipt = new Ebms3Receipt();
    if (aDSRefs.isNotEmpty() && bShouldUseNonRepudiation) {
        final NonRepudiationInformation aNonRepudiationInformation = new NonRepudiationInformation();
        for (final Node aRef : aDSRefs) {
            // Read XMLDsig Reference
            final ReferenceType aRefObj = XMLDSigReaderBuilder.dsigReference().read(aRef);
            // Add to NR response
            final MessagePartNRInformation aMessagePartNRInformation = new MessagePartNRInformation();
            aMessagePartNRInformation.setReference(aRefObj);
            aNonRepudiationInformation.addMessagePartNRInformation(aMessagePartNRInformation);
        }
        aEbms3Receipt.addAny(Ebms3WriterBuilder.nonRepudiationInformation().getAsDocument(aNonRepudiationInformation).getDocumentElement());
    } else {
        if (aDSRefs.isEmpty())
            LOGGER.info("Found no ds:Reference elements in the source message, hence returning the source UserMessage in the Receipt");
        else
            LOGGER.info("Non-repudiation is disabled, hence returning the source UserMessage in the Receipt");
        // If the original usermessage is not signed, the receipt will contain the
        // original message part without wss4j security
        aEbms3Receipt.addAny(AS4UserMessage.create(eSoapVersion, aEbms3UserMessage).getAsSoapDocument().getDocumentElement());
    }
    aSignalMessage.setReceipt(aEbms3Receipt);
    return new AS4ReceiptMessage(eSoapVersion, aSignalMessage);
}
Also used : Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) Ebms3Receipt(com.helger.phase4.ebms3header.Ebms3Receipt) NonRepudiationInformation(com.helger.phase4.ebms3header.NonRepudiationInformation) Node(org.w3c.dom.Node) MessagePartNRInformation(com.helger.phase4.ebms3header.MessagePartNRInformation) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) ReferenceType(com.helger.xsds.xmldsig.ReferenceType) Nonnull(javax.annotation.Nonnull)

Aggregations

Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)1 Ebms3Receipt (com.helger.phase4.ebms3header.Ebms3Receipt)1 Ebms3SignalMessage (com.helger.phase4.ebms3header.Ebms3SignalMessage)1 MessagePartNRInformation (com.helger.phase4.ebms3header.MessagePartNRInformation)1 NonRepudiationInformation (com.helger.phase4.ebms3header.NonRepudiationInformation)1 ReferenceType (com.helger.xsds.xmldsig.ReferenceType)1 Nonnull (javax.annotation.Nonnull)1 Node (org.w3c.dom.Node)1