Search in sources :

Example 1 with AS4ReceiptMessage

use of com.helger.phase4.messaging.domain.AS4ReceiptMessage in project phase4 by phax.

the class MockClientMessages method createReceiptMessageSigned.

@Nonnull
public static Document createReceiptMessageSigned(@Nonnull final ESoapVersion eSoapVersion, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aAttachments, @Nonnull @WillNotClose final AS4ResourceHelper aResHelper) throws WSSecurityException, DOMException {
    final Document aUserMessage = createUserMessageSigned(eSoapVersion, aPayload, aAttachments, aResHelper);
    final AS4ReceiptMessage aReceiptMsg = AS4ReceiptMessage.create(eSoapVersion, MessageHelperMethods.createRandomMessageID(), null, aUserMessage, true).setMustUnderstand(true);
    final Document aDoc = aReceiptMsg.getAsSoapDocument();
    return AS4Signer.createSignedMessage(AS4CryptoFactoryProperties.getDefaultInstance(), aDoc, eSoapVersion, aReceiptMsg.getMessagingID(), aAttachments, aResHelper, false, AS4SigningParams.createDefault());
}
Also used : AS4ReceiptMessage(com.helger.phase4.messaging.domain.AS4ReceiptMessage) Document(org.w3c.dom.Document) Nonnull(javax.annotation.Nonnull)

Example 2 with AS4ReceiptMessage

use of com.helger.phase4.messaging.domain.AS4ReceiptMessage in project phase4 by phax.

the class AS4ClientReceiptMessage method buildMessage.

@Override
public AS4ClientBuiltMessage buildMessage(@Nonnull @Nonempty final String sMessageID, @Nullable final IAS4ClientBuildMessageCallback aCallback) throws WSSecurityException {
    _checkMandatoryAttributes();
    final AS4ReceiptMessage aReceiptMsg = AS4ReceiptMessage.create(getSoapVersion(), sMessageID, m_aEbms3UserMessage, m_aSoapDocument, m_bNonRepudiation);
    if (aCallback != null)
        aCallback.onAS4Message(aReceiptMsg);
    final Document aPureDoc = aReceiptMsg.getAsSoapDocument();
    if (aCallback != null)
        aCallback.onSoapDocument(aPureDoc);
    Document aDoc = aPureDoc;
    if (m_bReceiptShouldBeSigned && signingParams().isSigningEnabled()) {
        final IAS4CryptoFactory aCryptoFactory = internalCreateCryptoFactory();
        final boolean bMustUnderstand = true;
        final Document aSignedDoc = AS4Signer.createSignedMessage(aCryptoFactory, aDoc, getSoapVersion(), aReceiptMsg.getMessagingID(), null, getAS4ResourceHelper(), bMustUnderstand, signingParams().getClone());
        if (aCallback != null)
            aCallback.onSignedSoapDocument(aSignedDoc);
        aDoc = aSignedDoc;
    }
    // Wrap SOAP XML
    return new AS4ClientBuiltMessage(sMessageID, new HttpXMLEntity(aDoc, getSoapVersion().getMimeType()));
}
Also used : AS4ReceiptMessage(com.helger.phase4.messaging.domain.AS4ReceiptMessage) IAS4CryptoFactory(com.helger.phase4.crypto.IAS4CryptoFactory) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document)

Example 3 with AS4ReceiptMessage

use of com.helger.phase4.messaging.domain.AS4ReceiptMessage in project phase4 by phax.

the class AS4RequestHandler method _createResponseReceiptMessage.

/**
 * @param aState
 *        The processing state of the incoming message. Never
 *        <code>null</code>.
 * @param aSoapDocument
 *        document which should be used as source for the receipt to convert
 *        it to non-repudiation information. Can be <code>null</code>.
 * @param eSoapVersion
 *        SOAPVersion which should be used
 * @param aEffectiveLeg
 *        the leg that is used to determined, how the receipt should be build
 * @param aUserMessage
 *        used if no non-repudiation information is needed, prints the
 *        usermessage in receipt. Can be <code>null</code>.
 * @param aResponseAttachments
 *        that should be sent back if needed. Can be <code>null</code>.
 * @throws WSSecurityException
 */
@Nonnull
private IAS4ResponseFactory _createResponseReceiptMessage(@Nonnull final IAS4MessageState aState, @Nullable final Document aSoapDocument, @Nonnull final ESoapVersion eSoapVersion, @Nonnull @Nonempty final String sResponseMessageID, @Nonnull final PModeLeg aEffectiveLeg, @Nullable final Ebms3UserMessage aUserMessage, @Nullable final ICommonsList<WSS4JAttachment> aResponseAttachments) throws WSSecurityException {
    final AS4ReceiptMessage aReceiptMessage = AS4ReceiptMessage.create(eSoapVersion, sResponseMessageID, aUserMessage, aSoapDocument, _isSendNonRepudiationInformation(aEffectiveLeg)).setMustUnderstand(true);
    // We've got our response
    final Document aResponseDoc = aReceiptMessage.getAsSoapDocument();
    final AS4SigningParams aSigningParams = new AS4SigningParams().setFromPMode(aEffectiveLeg.getSecurity());
    final Document aSignedDoc = _signResponseIfNeeded(aResponseAttachments, aSigningParams, aResponseDoc, aEffectiveLeg.getProtocol().getSoapVersion(), aReceiptMessage.getMessagingID());
    return new AS4ResponseFactoryXML(m_aMessageMetadata, aState, sResponseMessageID, aSignedDoc, eSoapVersion.getMimeType());
}
Also used : AS4SigningParams(com.helger.phase4.crypto.AS4SigningParams) AS4ReceiptMessage(com.helger.phase4.messaging.domain.AS4ReceiptMessage) Document(org.w3c.dom.Document) Nonnull(javax.annotation.Nonnull)

Example 4 with AS4ReceiptMessage

use of com.helger.phase4.messaging.domain.AS4ReceiptMessage 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

AS4ReceiptMessage (com.helger.phase4.messaging.domain.AS4ReceiptMessage)3 Nonnull (javax.annotation.Nonnull)3 Document (org.w3c.dom.Document)3 AS4SigningParams (com.helger.phase4.crypto.AS4SigningParams)1 IAS4CryptoFactory (com.helger.phase4.crypto.IAS4CryptoFactory)1 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 HttpXMLEntity (com.helger.phase4.http.HttpXMLEntity)1 ReferenceType (com.helger.xsds.xmldsig.ReferenceType)1 Node (org.w3c.dom.Node)1