Search in sources :

Example 11 with PMode

use of com.helger.phase4.model.pmode.PMode in project phase4 by phax.

the class PModeJsonConverter method convertToNative.

@Nonnull
public static PMode convertToNative(@Nonnull final IJsonObject aElement) {
    final IJsonObject aInit = aElement.getAsObject(ELEMENT_INITIATOR);
    final PModeParty aInitiator = aInit == null ? null : PModePartyJsonConverter.convertToNative(aInit);
    final IJsonObject aResp = aElement.getAsObject(ELEMENT_RESPONDER);
    final PModeParty aResponder = aResp == null ? null : PModePartyJsonConverter.convertToNative(aResp);
    final String sAgreement = aElement.getAsString(ATTR_AGREEMENT);
    final String sMEP = aElement.getAsString(ATTR_MEP);
    final EMEP eMEP = EMEP.getFromIDOrNull(sMEP);
    if (eMEP == null)
        throw new IllegalStateException("Failed to resolve MEP '" + sMEP + "'");
    final String sMEPBinding = aElement.getAsString(ATTR_MEP_BINDING);
    final EMEPBinding eMEPBinding = EMEPBinding.getFromIDOrNull(sMEPBinding);
    if (eMEPBinding == null)
        throw new IllegalStateException("Failed to resolve MEPBinding '" + sMEPBinding + "'");
    final IJsonObject aL1 = aElement.getAsObject(ELEMENT_LEG1);
    final PModeLeg aLeg1 = aL1 == null ? null : PModeLegJsonConverter.convertToNative(aL1);
    final IJsonObject aL2 = aElement.getAsObject(ELEMENT_LEG2);
    final PModeLeg aLeg2 = aL2 == null ? null : PModeLegJsonConverter.convertToNative(aL2);
    final IJsonObject aPS = aElement.getAsObject(ELEMENT_PAYLOADSERVICE);
    final PModePayloadService aPayloadService = aPS == null ? null : PModePayloadServiceJsonConverter.convertToNative(aPS);
    final IJsonObject aRA = aElement.getAsObject(ELEMENT_RECEPETIONAWARENESS);
    final PModeReceptionAwareness aReceptionAwareness = aRA == null ? null : PModeReceptionAwarenessJsonConverter.convertToNative(aRA);
    return new PMode(getStubObject(aElement), aInitiator, aResponder, sAgreement, eMEP, eMEPBinding, aLeg1, aLeg2, aPayloadService, aReceptionAwareness);
}
Also used : EMEPBinding(com.helger.phase4.model.EMEPBinding) EMEP(com.helger.phase4.model.EMEP) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) IJsonObject(com.helger.json.IJsonObject) Nonnull(javax.annotation.Nonnull)

Example 12 with PMode

use of com.helger.phase4.model.pmode.PMode in project phase4 by phax.

the class AS4RequestHandler method _createMimeMessageForResponse.

/**
 * Returns the MimeMessage with encrypted attachment or without depending on
 * what is configured in the PMode within Leg2.
 *
 * @param aResponseDoc
 *        the document that contains the user message
 * @param aResponseAttachments
 *        The Attachments that should be encrypted
 * @param aLeg
 *        Leg to get necessary information, EncryptionAlgorithm, SOAPVersion
 * @param sEncryptToAlias
 *        The alias into the keystore that should be used for encryption
 * @return a MimeMessage to be sent
 * @throws MessagingException
 * @throws WSSecurityException
 */
@Nonnull
private AS4MimeMessage _createMimeMessageForResponse(@Nonnull final Document aResponseDoc, @Nonnull final ICommonsList<WSS4JAttachment> aResponseAttachments, @Nonnull final ESoapVersion eSoapVersion, @Nonnull final AS4CryptParams aCryptParms) throws WSSecurityException, MessagingException {
    final AS4MimeMessage aMimeMsg;
    if (aCryptParms.isCryptEnabled(LOGGER::warn)) {
        final boolean bMustUnderstand = true;
        aMimeMsg = AS4Encryptor.encryptMimeMessage(eSoapVersion, aResponseDoc, aResponseAttachments, m_aCryptoFactory, bMustUnderstand, m_aResHelper, aCryptParms);
    } else {
        aMimeMsg = MimeMessageCreator.generateMimeMessage(eSoapVersion, aResponseDoc, aResponseAttachments);
    }
    if (aMimeMsg == null)
        throw new IllegalStateException("Failed to create MimeMessage!");
    return aMimeMsg;
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) Nonnull(javax.annotation.Nonnull)

Example 13 with PMode

use of com.helger.phase4.model.pmode.PMode in project phase4 by phax.

the class PModeCheckTest method testWrongPModeID.

// Can not do that anymore since everything gets accepted with default profile
// pmode
@Test
@Ignore("The PMode resolution is not done based on PMode ID - therefore this cannot fail")
public void testWrongPModeID() throws Exception {
    m_aEbms3UserMessage.getCollaborationInfo().getAgreementRef().setPmode("this-is-a-wrong-id");
    // Needed to set since also Action and Service combination gets checked if
    // they are already in the pmode pool
    final Ebms3Service aService = new Ebms3Service();
    aService.setValue("Random Value");
    m_aEbms3UserMessage.getCollaborationInfo().setService(aService);
    final Document aDoc = AS4UserMessage.create(SOAP_VERSION, m_aEbms3UserMessage).setMustUnderstand(true).getAsSoapDocument(m_aPayload);
    assertNotNull(aDoc);
    sendPlainMessageAndWait(new HttpXMLEntity(aDoc, SOAP_VERSION.getMimeType()), false, EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getErrorCode());
}
Also used : HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Ebms3Service(com.helger.phase4.ebms3header.Ebms3Service) Document(org.w3c.dom.Document) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with PMode

use of com.helger.phase4.model.pmode.PMode in project phase4 by phax.

the class PModeCheckTest method testPModeWrongMPC.

@Test
public void testPModeWrongMPC() throws Exception {
    final PMode aPMode = MockPModeGenerator.getTestPMode(SOAP_VERSION);
    aPMode.getLeg1().getBusinessInfo().setMPCID("wrongmpc-id");
    final IPModeManager aPModeMgr = MetaAS4Manager.getPModeMgr();
    try {
        for (final String sPModeID : aPModeMgr.getAllIDs()) {
            aPModeMgr.deletePMode(sPModeID);
        }
        assertTrue(aPModeMgr.getAllIDs().isEmpty());
        aPModeMgr.createOrUpdatePMode(aPMode);
        // Needed since different ids set in message and pmode otherwise
        m_aEbms3UserMessage.setCollaborationInfo(MessageHelperMethods.createEbms3CollaborationInfo(aPMode.getInitiatorID() + "-" + aPMode.getResponderID(), DEFAULT_AGREEMENT, null, CAS4.DEFAULT_SERVICE_URL, CAS4.DEFAULT_ACTION_URL, AS4TestConstants.TEST_CONVERSATION_ID));
        final Document aSignedDoc = AS4UserMessage.create(SOAP_VERSION, m_aEbms3UserMessage).setMustUnderstand(true).getAsSoapDocument(m_aPayload);
        sendPlainMessageAndWait(new HttpXMLEntity(aSignedDoc, SOAP_VERSION.getMimeType()), false, EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getErrorCode());
    } finally {
        // The MockPModeGenerator generates automatically a PMode, we need
        // too delete it after we are done with the test
        MetaAS4Manager.getPModeMgr().deletePMode(aPMode.getID());
        aPModeMgr.deletePMode(aPMode.getID());
    }
}
Also used : IPModeManager(com.helger.phase4.model.pmode.IPModeManager) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) PMode(com.helger.phase4.model.pmode.PMode) Test(org.junit.Test)

Example 15 with PMode

use of com.helger.phase4.model.pmode.PMode in project phase4 by phax.

the class PModeCheckTest method testPModeLegProtocolAddressReject.

/**
 * Is ESENS specific, EBMS3 specification is the protocol an optional element.
 * Maybe refactoring into a test if http and SMTP addresses later on get
 * converted right
 *
 * @throws Exception
 *         In case of an error
 */
@Test
@Ignore("The PMode leg protocol address is curently not used, therefore the wrong address never pops up")
public void testPModeLegProtocolAddressReject() throws Exception {
    final String sInvalidPModeID = "pmode-" + GlobalIDFactory.getNewPersistentIntID();
    final PMode aPMode = MockPModeGenerator.getTestPMode(SOAP_VERSION);
    aPMode.setLeg1(new PModeLeg(PModeLegProtocol.createForDefaultSoapVersion("TestsimulationAddressWrong"), null, null, null, null));
    final IPModeManager aPModeMgr = MetaAS4Manager.getPModeMgr();
    try {
        aPModeMgr.createOrUpdatePMode(aPMode);
        final Wrapper<String> aMsgID = new Wrapper<>();
        final Document aDoc = modifyUserMessage(sInvalidPModeID, null, null, createDefaultProperties(), null, null, x -> aMsgID.set(x));
        final Document aSignedDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aDoc, SOAP_VERSION, aMsgID.get(), null, s_aResMgr, false, AS4SigningParams.createDefault());
        sendPlainMessageAndWait(new HttpXMLEntity(aSignedDoc, SOAP_VERSION.getMimeType()), false, EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getErrorCode());
    } finally {
        aPModeMgr.deletePMode(aPMode.getID());
    }
}
Also used : Wrapper(com.helger.commons.wrapper.Wrapper) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) IPModeManager(com.helger.phase4.model.pmode.IPModeManager) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) PMode(com.helger.phase4.model.pmode.PMode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Nonnull (javax.annotation.Nonnull)17 PModeLeg (com.helger.phase4.model.pmode.leg.PModeLeg)15 PMode (com.helger.phase4.model.pmode.PMode)13 Document (org.w3c.dom.Document)9 IPMode (com.helger.phase4.model.pmode.IPMode)8 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)6 Test (org.junit.Test)6 EAS4CompressionMode (com.helger.phase4.attachment.EAS4CompressionMode)5 Ebms3Property (com.helger.phase4.ebms3header.Ebms3Property)5 Ebms3UserMessage (com.helger.phase4.ebms3header.Ebms3UserMessage)5 EMEP (com.helger.phase4.model.EMEP)5 EMEPBinding (com.helger.phase4.model.EMEPBinding)5 PModeParty (com.helger.phase4.model.pmode.PModeParty)5 Phase4Exception (com.helger.phase4.util.Phase4Exception)5 AS4DecompressException (com.helger.phase4.attachment.AS4DecompressException)4 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)4 Ebms3Error (com.helger.phase4.ebms3header.Ebms3Error)4 HttpXMLEntity (com.helger.phase4.http.HttpXMLEntity)4 IOException (java.io.IOException)4 Nullable (javax.annotation.Nullable)4