diff --git a/security/src/main/java/org/springframework/ws/soap/security/wss4j/Wss4jSecurityInterceptor.java b/security/src/main/java/org/springframework/ws/soap/security/wss4j/Wss4jSecurityInterceptor.java index 5cf06444..faf05b52 100755 --- a/security/src/main/java/org/springframework/ws/soap/security/wss4j/Wss4jSecurityInterceptor.java +++ b/security/src/main/java/org/springframework/ws/soap/security/wss4j/Wss4jSecurityInterceptor.java @@ -633,6 +633,8 @@ public class Wss4jSecurityInterceptor extends AbstractWsSecurityInterceptor impl if (soapMessage instanceof AxiomSoapMessage) { // construct a new Axiom message with the processed envelope AxiomSoapMessage axiomMessage = (AxiomSoapMessage) soapMessage; + // save the Soap Action + String soapAction = axiomMessage.getSoapAction(); SOAPEnvelope envelopeFromDOMDocument = AxiomUtils.toEnvelope(envelope); SOAPFactory factory = (SOAPFactory) axiomMessage.getAxiomMessage().getOMFactory(); SOAPMessage newMessage = factory.createSOAPMessage(); @@ -640,6 +642,8 @@ public class Wss4jSecurityInterceptor extends AbstractWsSecurityInterceptor impl // replace the Axiom message axiomMessage.setAxiomMessage(newMessage); + // restore the Soap Action + axiomMessage.setSoapAction(soapAction); } } diff --git a/security/src/test/java/org/springframework/ws/soap/security/wss4j/AxiomWss4jMessageInterceptorSoapActionTest.java b/security/src/test/java/org/springframework/ws/soap/security/wss4j/AxiomWss4jMessageInterceptorSoapActionTest.java new file mode 100644 index 00000000..20539692 --- /dev/null +++ b/security/src/test/java/org/springframework/ws/soap/security/wss4j/AxiomWss4jMessageInterceptorSoapActionTest.java @@ -0,0 +1,21 @@ +/* + * Copyright 2008 the original author or authors. + * + * 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.springframework.ws.soap.security.wss4j; + +public class AxiomWss4jMessageInterceptorSoapActionTest extends Wss4jMessageInterceptorSoapActionTestCase { + +} diff --git a/security/src/test/java/org/springframework/ws/soap/security/wss4j/SaajWss4jMessageInterceptorSoapActionTest.java b/security/src/test/java/org/springframework/ws/soap/security/wss4j/SaajWss4jMessageInterceptorSoapActionTest.java new file mode 100644 index 00000000..21de82d5 --- /dev/null +++ b/security/src/test/java/org/springframework/ws/soap/security/wss4j/SaajWss4jMessageInterceptorSoapActionTest.java @@ -0,0 +1,21 @@ +/* + * Copyright 2008 the original author or authors. + * + * 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.springframework.ws.soap.security.wss4j; + +public class SaajWss4jMessageInterceptorSoapActionTest extends Wss4jMessageInterceptorSoapActionTestCase { + +} diff --git a/security/src/test/java/org/springframework/ws/soap/security/wss4j/Wss4jMessageInterceptorSoapActionTestCase.java b/security/src/test/java/org/springframework/ws/soap/security/wss4j/Wss4jMessageInterceptorSoapActionTestCase.java new file mode 100644 index 00000000..ee6ade1a --- /dev/null +++ b/security/src/test/java/org/springframework/ws/soap/security/wss4j/Wss4jMessageInterceptorSoapActionTestCase.java @@ -0,0 +1,71 @@ +/* + * Copyright 2008 the original author or authors. + * + * 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.springframework.ws.soap.security.wss4j; + +import java.util.Properties; + +import org.apache.ws.security.WSConstants; + +import org.springframework.ws.context.DefaultMessageContext; +import org.springframework.ws.context.MessageContext; +import org.springframework.ws.soap.SoapMessage; +import org.springframework.ws.soap.security.wss4j.callback.SimplePasswordValidationCallbackHandler; + +public abstract class Wss4jMessageInterceptorSoapActionTestCase extends Wss4jTestCase { + + private static final String SOAP_ACTION = "\"http://test\""; + + private Properties users = new Properties(); + + private Wss4jSecurityInterceptor interceptor; + + protected void onSetup() throws Exception { + users.setProperty("Bert", "Ernie"); + interceptor = new Wss4jSecurityInterceptor(); + interceptor.setValidationActions("UsernameToken"); + interceptor.setSecurementActions("UsernameToken"); + interceptor.setSecurementPasswordType(WSConstants.PW_TEXT); + SimplePasswordValidationCallbackHandler callbackHandler = new SimplePasswordValidationCallbackHandler(); + callbackHandler.setUsers(users); + interceptor.setValidationCallbackHandler(callbackHandler); + + interceptor.afterPropertiesSet(); + } + + public void testPreserveSoapActionOnValidation() throws Exception { + SoapMessage message = loadMessage("usernameTokenPlainText-soap.xml"); + message.setSoapAction(SOAP_ACTION); + MessageContext messageContext = new DefaultMessageContext(message, getMessageFactory()); + interceptor.validateMessage(message, messageContext); + + assertNotNull("Soap Action must not be null", message.getSoapAction()); + assertEquals("Soap Action is different from expected", SOAP_ACTION, message.getSoapAction()); + } + + public void testPreserveSoapActionOnSecurement() throws Exception { + SoapMessage message = loadMessage("empty-soap.xml"); + message.setSoapAction(SOAP_ACTION); + interceptor.setSecurementUsername("Bert"); + interceptor.setSecurementPassword("Ernie"); + MessageContext messageContext = getMessageContext(message); + interceptor.secureMessage(message, messageContext); + + assertNotNull("Soap Action must not be null", message.getSoapAction()); + assertEquals("Soap Action is different from expected", SOAP_ACTION, message.getSoapAction()); + + } +}