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);
}
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;
}
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());
}
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());
}
}
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());
}
}
Aggregations