This is an automated email from the ASF dual-hosted git repository.
robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-rampart.git
The following commit(s) were added to refs/heads/master by this push:
new d2b312de RAMPART-419: create the soap:Header before WSS4J inserts
wsse:Security
d2b312de is described below
commit d2b312de25e653a12dfd27cd59e66be050a63d2a
Author: Robert Lazarski <[email protected]>
AuthorDate: Tue Nov 17 11:48:10 2026 -1000
RAMPART-419: create the soap:Header before WSS4J inserts wsse:Security
An outgoing envelope without a soap:Header made WSS4J create one as a
plain DOM element. With Axiom 2 the DOM envelope accepts it, but it is
not a SOAPHeader, so getHeader() stays null and later handlers add a
second header. Create it through the Axiom API on the sender path first.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
---
.../org/apache/rampart/RampartMessageData.java | 9 ++-
.../org/apache/rampart/HeaderlessEnvelopeTest.java | 66 ++++++++++++++++++++++
2 files changed, 74 insertions(+), 1 deletion(-)
diff --git
a/modules/rampart-core/src/main/java/org/apache/rampart/RampartMessageData.java
b/modules/rampart-core/src/main/java/org/apache/rampart/RampartMessageData.java
index c4ffe877..f40a865d 100644
---
a/modules/rampart-core/src/main/java/org/apache/rampart/RampartMessageData.java
+++
b/modules/rampart-core/src/main/java/org/apache/rampart/RampartMessageData.java
@@ -385,13 +385,15 @@ public class RampartMessageData {
}
+ SOAPEnvelope envelope = null;
if(this.policyData != null) {
// Get the SOAP envelope as document, then create a security
// header and insert into the document (Envelope)
// WE SHOULD ONLY DO THE CONVERTION IF THERE IS AN APPLICABLE
POLICY
this.document =
Axis2Util.getDocumentFromSOAPEnvelope(msgCtx.getEnvelope(), true);
-
msgCtx.setEnvelope((SOAPEnvelope)this.document.getDocumentElement());
+ envelope = (SOAPEnvelope)this.document.getDocumentElement();
+ msgCtx.setEnvelope(envelope);
this.soapConstants =
WSSecurityUtil.getSOAPConstants(this.document.getDocumentElement());
@@ -538,6 +540,11 @@ public class RampartMessageData {
}
if(this.sender && this.policyData != null) {
+ // RAMPART-419: an envelope without a soap:Header makes WSS4J
create one as a
+ // plain DOM element. The Axiom DOM envelope then has a Header
child that is not
+ // a SOAPHeader, so getHeader() still returns null and
anything that asks for
+ // the header afterwards adds a second one. Create it as a
SOAPHeader first.
+ envelope.getOrCreateHeader();
this.secHeader = new WSSecHeader(this.document);
secHeader.insertSecurityHeader();
// RAMPART-261
diff --git
a/modules/rampart-tests/src/test/java/org/apache/rampart/HeaderlessEnvelopeTest.java
b/modules/rampart-tests/src/test/java/org/apache/rampart/HeaderlessEnvelopeTest.java
new file mode 100644
index 00000000..feb294b0
--- /dev/null
+++
b/modules/rampart-tests/src/test/java/org/apache/rampart/HeaderlessEnvelopeTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rampart;
+
+import java.util.ArrayList;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axis2.context.MessageContext;
+import org.apache.neethi.Policy;
+import org.apache.wss4j.dom.WSConstants;
+
+/**
+ * RAMPART-419: an outgoing envelope without a soap:Header (a message built by
hand,
+ * or one that never passed through addressing) made WSS4J create the header
as a
+ * plain DOM element, which the Axiom DOM envelope refuses.
+ */
+public class HeaderlessEnvelopeTest extends MessageBuilderTestBase {
+
+ private static final String POLICY =
"test-resources/policy/rampart-asymm-binding-1.xml";
+
+ public void testSoap11EnvelopeWithoutHeader() throws Exception {
+ buildWithoutHeader(getMsgCtx());
+ }
+
+ public void testSoap12EnvelopeWithoutHeader() throws Exception {
+ buildWithoutHeader(getMsgCtx12());
+ }
+
+ private void buildWithoutHeader(MessageContext ctx) throws Exception {
+ SOAPEnvelope env = ctx.getEnvelope();
+ env.getHeader().detach();
+ assertNull("test setup: the envelope must have no header",
env.getHeader());
+
+ Policy policy = loadPolicy(POLICY);
+ ctx.setProperty(RampartMessageData.KEY_RAMPART_POLICY, policy);
+ new MessageBuilder().build(ctx);
+
+ SOAPHeader header = ctx.getEnvelope().getHeader();
+ assertNotNull("a soap:Header must have been created", header);
+ assertEquals("the created header must be the envelope's first child",
+ header, ctx.getEnvelope().getFirstElement());
+
+ ArrayList<QName> list = new ArrayList<QName>();
+ list.add(new QName(WSConstants.WSU_NS,
WSConstants.TIMESTAMP_TOKEN_LN));
+ list.add(new QName(WSConstants.WSSE_NS, WSConstants.BINARY_TOKEN_LN));
+ list.add(new QName(WSConstants.SIG_NS, WSConstants.SIG_LN));
+ verifySecHeader(list.iterator(), ctx.getEnvelope());
+ }
+}