use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.
the class AS4Encryptor method _encryptMimeMessage.
@Nonnull
private static AS4MimeMessage _encryptMimeMessage(@Nonnull final ESoapVersion eSoapVersion, @Nonnull final Document aDoc, @Nullable final ICommonsList<WSS4JAttachment> aAttachments, @Nonnull final IAS4CryptoFactory aCryptoFactory, final boolean bMustUnderstand, @Nonnull @WillNotClose final AS4ResourceHelper aResHelper, @Nonnull final AS4CryptParams aCryptParams) throws WSSecurityException {
if (LOGGER.isInfoEnabled())
LOGGER.info("Now encrypting AS4 MIME message");
final WSSecHeader aSecHeader = new WSSecHeader(aDoc);
aSecHeader.insertSecurityHeader();
final WSSecEncrypt aBuilder = _createEncrypt(aSecHeader, aCryptParams);
// "cid:Attachments" is a predefined ID
aBuilder.getParts().add(new WSEncryptionPart(MessageHelperMethods.PREFIX_CID + "Attachments", "Content"));
WSS4JAttachmentCallbackHandler aAttachmentCallbackHandler = null;
if (CollectionHelper.isNotEmpty(aAttachments)) {
aAttachmentCallbackHandler = new WSS4JAttachmentCallbackHandler(aAttachments, aResHelper);
aBuilder.setAttachmentCallbackHandler(aAttachmentCallbackHandler);
}
// Ensure mustUnderstand value
final Attr aMustUnderstand = aSecHeader.getSecurityHeaderElement().getAttributeNodeNS(eSoapVersion.getNamespaceURI(), "mustUnderstand");
if (aMustUnderstand != null)
aMustUnderstand.setValue(eSoapVersion.getMustUnderstandValue(bMustUnderstand));
// Generate a session key
final KeyGenerator aKeyGen = KeyUtils.getKeyGenerator(WSS4JConstants.AES_128);
final SecretKey aSymmetricKey = aKeyGen.generateKey();
// Main sign and/or encrypt
final Document aEncryptedDoc = aBuilder.build(aCryptoFactory.getCrypto(), aSymmetricKey);
// The attachment callback handler contains the encrypted attachments
// Important: read the attachment stream only once!
ICommonsList<WSS4JAttachment> aEncryptedAttachments = null;
if (aAttachmentCallbackHandler != null) {
aEncryptedAttachments = aAttachmentCallbackHandler.getAllResponseAttachments();
// MIME Type and CTE must be set for encrypted attachments!
for (final WSS4JAttachment aAttachment : aEncryptedAttachments) {
aAttachment.overwriteMimeType(CMimeType.APPLICATION_OCTET_STREAM.getAsString());
aAttachment.setContentTransferEncoding(EContentTransferEncoding.BINARY);
}
}
// Use the encrypted attachments!
try {
return MimeMessageCreator.generateMimeMessage(eSoapVersion, aEncryptedDoc, aEncryptedAttachments);
} catch (final MessagingException ex) {
throw new WSSecurityException(ErrorCode.FAILURE, ex, "Failed to generate MIME message");
}
}
use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.
the class AS4ErrorMessage method create.
@Nonnull
public static AS4ErrorMessage create(@Nonnull final ESoapVersion eSoapVersion, @Nonnull final Ebms3MessageInfo aEbms3MessageInfo, @Nonnull final ICommonsList<Ebms3Error> aErrorMessages) {
final Ebms3SignalMessage aSignalMessage = new Ebms3SignalMessage();
// Message Info
aSignalMessage.setMessageInfo(aEbms3MessageInfo);
// Error Message
aSignalMessage.setError(aErrorMessages);
return new AS4ErrorMessage(eSoapVersion, aSignalMessage);
}
use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.
the class AS4PullRequestMessage method create.
@Nonnull
public static AS4PullRequestMessage create(@Nonnull final ESoapVersion eSoapVersion, @Nonnull final Ebms3MessageInfo aEbms3MessageInfo, @Nullable final String sMPC, @Nullable final List<Object> aAny) {
final Ebms3SignalMessage aSignalMessage = new Ebms3SignalMessage();
// Message Info
aSignalMessage.setMessageInfo(aEbms3MessageInfo);
// PullRequest
if (StringHelper.hasText(sMPC)) {
final Ebms3PullRequest aEbms3PullRequest = new Ebms3PullRequest();
aEbms3PullRequest.setMpc(sMPC);
aSignalMessage.setPullRequest(aEbms3PullRequest);
}
aSignalMessage.setAny(aAny);
return new AS4PullRequestMessage(eSoapVersion, aSignalMessage);
}
use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.
the class AS4UserMessage method create.
@Nonnull
public static AS4UserMessage create(@Nonnull final Ebms3MessageInfo aEbms3MessageInfo, @Nullable final Ebms3PayloadInfo aEbms3PayloadInfo, @Nonnull final Ebms3CollaborationInfo aEbms3CollaborationInfo, @Nonnull final Ebms3PartyInfo aEbms3PartyInfo, @Nullable final Ebms3MessageProperties aEbms3MessageProperties, @Nonnull final ESoapVersion eSoapVersion) {
final Ebms3UserMessage aUserMessage = new Ebms3UserMessage();
// Party Information
aUserMessage.setPartyInfo(aEbms3PartyInfo);
// Collaboration Information
aUserMessage.setCollaborationInfo(aEbms3CollaborationInfo);
// Properties
aUserMessage.setMessageProperties(aEbms3MessageProperties);
// Payload Information
aUserMessage.setPayloadInfo(aEbms3PayloadInfo);
// Message Info
aUserMessage.setMessageInfo(aEbms3MessageInfo);
return new AS4UserMessage(eSoapVersion, aUserMessage);
}
use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.
the class MimeMessageCreator method generateMimeMessage.
@Nonnull
public static AS4MimeMessage generateMimeMessage(@Nonnull final ESoapVersion eSoapVersion, @Nonnull final Document aSoapEnvelope, @Nullable final ICommonsList<WSS4JAttachment> aEncryptedAttachments) throws MessagingException {
ValueEnforcer.notNull(eSoapVersion, "SoapVersion");
ValueEnforcer.notNull(aSoapEnvelope, "SoapEnvelope");
final Charset aCharset = AS4XMLHelper.XWS.getCharset();
final SoapMimeMultipart aMimeMultipart = new SoapMimeMultipart(eSoapVersion, aCharset);
final EContentTransferEncoding eCTE = EContentTransferEncoding.BINARY;
final String sContentType = eSoapVersion.getMimeType(aCharset).getAsString();
{
// Message Itself (repeatable)
final MimeBodyPart aMessagePart = new MimeBodyPart();
aMessagePart.setDataHandler(new DataHandler(new DOMSource(aSoapEnvelope), sContentType));
aMessagePart.setHeader(CHttpHeader.CONTENT_TRANSFER_ENCODING, eCTE.getID());
aMimeMultipart.addBodyPart(aMessagePart);
}
boolean bIsRepeatable = true;
if (aEncryptedAttachments != null)
for (final WSS4JAttachment aEncryptedAttachment : aEncryptedAttachments) {
aEncryptedAttachment.addToMimeMultipart(aMimeMultipart);
if (!aEncryptedAttachment.isRepeatable())
bIsRepeatable = false;
}
// Build main message
final AS4MimeMessage aMsg = new AS4MimeMessage((Session) null, bIsRepeatable);
aMsg.setContent(aMimeMultipart);
aMsg.saveChanges();
return aMsg;
}
Aggregations