Skip to content

Add support for providing an AttachmentCallbackHandler to WSS4J RequestData #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

elfogre
Copy link
Contributor

@elfogre elfogre commented Jan 2, 2018

Hello Spring-ws comunity,

I'm using spring-ws to develope an AS4 server. Everything works correct (SAAJ + Wss4j2) except when I want to sign/encrypt Soap attachments in a request. When I try it, I get an error:

Caused by: org.apache.wss4j.common.ext.WSSecurityException: Error during Signature: 
	at org.apache.wss4j.dom.action.SignatureAction.execute(SignatureAction.java:162)
	at org.apache.wss4j.dom.handler.WSHandler.doSenderAction(WSHandler.java:234)
	at org.springframework.ws.soap.security.wss4j2.Wss4jHandler.doSenderAction(Wss4jHandler.java:63)
	at org.springframework.ws.soap.security.wss4j2.Wss4jSecurityInterceptor.secureMessage(Wss4jSecurityInterceptor.java:563)
	... 32 common frames omitted
Caused by: org.apache.wss4j.common.ext.WSSecurityException: Cannot setup signature data structure
	at org.apache.wss4j.dom.message.WSSecSignatureBase.addReferencesToSign(WSSecSignatureBase.java:208)
	at org.apache.wss4j.dom.message.WSSecSignature.addReferencesToSign(WSSecSignature.java:412)
	at org.apache.wss4j.dom.action.SignatureAction.execute(SignatureAction.java:147)
	... 35 common frames omitted
Caused by: org.apache.wss4j.common.ext.WSSecurityException: no attachment callbackhandler supplied
	at org.apache.wss4j.dom.message.WSSecSignatureBase.addAttachmentReferences(WSSecSignatureBase.java:228)
	at org.apache.wss4j.dom.message.WSSecSignatureBase.addReferencesToSign(WSSecSignatureBase.java:111)
	... 37 common frames omitted

Wss4j2 needs an attachmentCallbackHandler to work, but it can't be set it via Wss4jSecurityInterceptor. I've add a new field, it's setter and I add a line in initializeRequestData method to set it in the request. After this I could sign without problems attachments in SOAP.

A SAAJ attachmentCallbackHandler implementation with its test is also included in the pull request.

@pivotal-issuemaster
Copy link

@elfogre Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@elfogre Thank you for signing the Contributor License Agreement!

@veithen
Copy link
Contributor

veithen commented Jan 8, 2018

Shouldn't this use the MimeMessage API so that it works with both SAAJ and Axiom?

@elfogre
Copy link
Contributor Author

elfogre commented Jan 8, 2018

My first approach was with org.springframework.ws.mime.Attachment instead of SAAJ dependant AttachmentPart . However there is a design problem with org.springframework.ws.mime.Attachment that requires a big change. I'll try to explain:

  • Attachment interface declare getters for attachment contentId, contentType and InputStream for the content itself, but it lacks for a getter for mimeHeaders (like Content-Transfer-Encoding or Content-Location).

  • Axiom implementation of attachment (org.springframework.ws.soap.axiom.AxiomAttachment) stores all its data in a String for contentId and a DataHandler for contentType and content itself. There is no space for mime headers.

  • Saaj implementation (org.springframework.ws.soap.saaj.SaajAttachment) stores its data in a javax.xml.soap.AttachmentPart that have accessors for mime Headers.

As I need all attachment mime-headers to be correctly processed in the attachmentCallbackHandler, I can't use Axiom and I have to access javax.xml.soap.AttachmentPart in SAAJ implementation. This is the reason why this callback is only for SAAJ.

If we write accesors for mime-header in Attachment interface and in saaj and axiom attachment implementations, we can easily change this CallbackHandler to use SoapMessage API.

I can write that code if you think it's useful

@gregturn gregturn changed the base branch from master to main April 7, 2021 15:51
@gregturn gregturn force-pushed the main branch 3 times, most recently from 86e5d92 to 4c5bd74 Compare May 12, 2023 21:32
@snicoll snicoll added the status: waiting-for-triage An issue we've not yet triaged label Feb 19, 2025
@snicoll snicoll changed the title - SwA profile 1.1 with Wss4jSecurityInterceptor Add support for providing an AttachmentCallbackHandler to WSS4J RequestData Mar 5, 2025
@snicoll snicoll added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 5, 2025
@snicoll snicoll added this to the 4.1.0-M1 milestone Mar 5, 2025
@snicoll
Copy link
Member

snicoll commented Mar 5, 2025

Thanks for the PR and I apologize for taking this long to review it. We'll add the setter. As for the implementation, I'd rather keep it on your side for now. We can revisit this based on interest from the community.

@snicoll snicoll self-assigned this Mar 10, 2025
snicoll pushed a commit that referenced this pull request Mar 10, 2025
snicoll added a commit that referenced this pull request Mar 10, 2025
@snicoll snicoll closed this in ef6dbe6 Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants