diff --git a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapMessageFactory.java b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapMessageFactory.java
index ad49a6f5..553ab3db 100644
--- a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapMessageFactory.java
+++ b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapMessageFactory.java
@@ -53,7 +53,30 @@ public class SaajSoapMessageFactory implements WebServiceMessageFactory, Initial
private String messageFactoryProtocol;
+ /**
+ * Default, empty constructor.
+ */
+ public SaajSoapMessageFactory() {
+ }
+
+ /**
+ * Constructor that takes a message factory as an argument.
+ */
+ public SaajSoapMessageFactory(MessageFactory messageFactory) {
+ this.messageFactory = messageFactory;
+ }
+
+ /**
+ * Returns the SAAJ MessageFactory used.
+ */
+ public MessageFactory getSaajMessageFactory() {
+ return messageFactory;
+ }
+
public void afterPropertiesSet() throws Exception {
+ if (messageFactory != null) {
+ return;
+ }
try {
if (SaajUtils.getSaajVersion() >= SaajUtils.SAAJ_13) {
if (!StringUtils.hasLength(messageFactoryProtocol)) {
diff --git a/core/src/test/java/org/springframework/ws/endpoint/interceptor/PayloadValidatingInterceptorTest.java b/core/src/test/java/org/springframework/ws/endpoint/interceptor/PayloadValidatingInterceptorTest.java
index 55c5f6cb..93c102bf 100644
--- a/core/src/test/java/org/springframework/ws/endpoint/interceptor/PayloadValidatingInterceptorTest.java
+++ b/core/src/test/java/org/springframework/ws/endpoint/interceptor/PayloadValidatingInterceptorTest.java
@@ -24,7 +24,6 @@ import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stream.StreamSource;
import junit.framework.TestCase;
@@ -48,7 +47,13 @@ public class PayloadValidatingInterceptorTest extends TestCase {
private MessageContext context;
- private SaajSoapMessageFactory factory;
+ private SaajSoapMessageFactory soap11Factory;
+
+ private MessageFactory messageFactory;
+
+ private SaajSoapMessageFactory soap12Factory;
+
+ private Transformer transformer;
protected void setUp() throws Exception {
interceptor = new PayloadValidatingInterceptor();
@@ -57,18 +62,16 @@ public class PayloadValidatingInterceptorTest extends TestCase {
interceptor.setValidateResponse(true);
interceptor.afterPropertiesSet();
- factory = new SaajSoapMessageFactory();
- factory.afterPropertiesSet();
- context = new DefaultMessageContext(factory);
+ soap11Factory = new SaajSoapMessageFactory(MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL));
+ soap12Factory = new SaajSoapMessageFactory(MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL));
+ transformer = TransformerFactory.newInstance().newTransformer();
}
public void testHandleInvalidRequestSoap11() throws Exception {
- MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
- SOAPMessage invalidMessage = messageFactory.createMessage();
- Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ SoapMessage invalidMessage = (SoapMessage) soap11Factory.createWebServiceMessage();
InputStream inputStream = getClass().getResourceAsStream("invalidMessage.xml");
- transformer.transform(new StreamSource(inputStream), new DOMResult(invalidMessage.getSOAPBody()));
- context = new DefaultMessageContext(new Saaj13SoapMessage(invalidMessage), factory);
+ transformer.transform(new StreamSource(inputStream), invalidMessage.getPayloadResult());
+ context = new DefaultMessageContext(invalidMessage, soap11Factory);
boolean result = interceptor.handleRequest(context, null);
assertFalse("Invalid response from interceptor", result);
@@ -84,14 +87,10 @@ public class PayloadValidatingInterceptorTest extends TestCase {
}
public void testHandleInvalidRequestSoap12() throws Exception {
- MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
- SOAPMessage invalidMessage = messageFactory.createMessage();
- Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ SoapMessage invalidMessage = (SoapMessage) soap12Factory.createWebServiceMessage();
InputStream inputStream = getClass().getResourceAsStream("invalidMessage.xml");
- transformer.transform(new StreamSource(inputStream), new DOMResult(invalidMessage.getSOAPBody()));
- factory.setSoapProtocol(SOAPConstants.SOAP_1_2_PROTOCOL);
- factory.afterPropertiesSet();
- context = new DefaultMessageContext(new Saaj13SoapMessage(invalidMessage), factory);
+ transformer.transform(new StreamSource(inputStream), invalidMessage.getPayloadResult());
+ context = new DefaultMessageContext(invalidMessage, soap12Factory);
boolean result = interceptor.handleRequest(context, null);
assertFalse("Invalid response from interceptor", result);
@@ -113,12 +112,10 @@ public class PayloadValidatingInterceptorTest extends TestCase {
interceptor.setFaultStringOrReasonLocale(locale);
interceptor.setAddValidationErrorDetail(false);
- MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
- SOAPMessage invalidMessage = messageFactory.createMessage();
- Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ SoapMessage invalidMessage = (SoapMessage) soap11Factory.createWebServiceMessage();
InputStream inputStream = getClass().getResourceAsStream("invalidMessage.xml");
- transformer.transform(new StreamSource(inputStream), new DOMResult(invalidMessage.getSOAPBody()));
- context = new DefaultMessageContext(new Saaj13SoapMessage(invalidMessage), factory);
+ transformer.transform(new StreamSource(inputStream), invalidMessage.getPayloadResult());
+ context = new DefaultMessageContext(invalidMessage, soap11Factory);
boolean result = interceptor.handleRequest(context, null);
assertFalse("Invalid response from interceptor", result);
@@ -171,6 +168,8 @@ public class PayloadValidatingInterceptorTest extends TestCase {
public void testNamespacesInType() throws Exception {
// Make sure we use Xerces for this testcase: the JAXP implementation used internally by JDK 1.5 has a bug
// See http://opensource.atlassian.com/projects/spring/browse/SWS-35
+ String previousSchemaFactory =
+ System.getProperty("javax.xml.validation.SchemaFactory:" + XMLConstants.W3C_XML_SCHEMA_NS_URI, "");
System.setProperty("javax.xml.validation.SchemaFactory:" + XMLConstants.W3C_XML_SCHEMA_NS_URI,
"org.apache.xerces.jaxp.validation.XMLSchemaFactory");
try {
@@ -179,13 +178,17 @@ public class PayloadValidatingInterceptorTest extends TestCase {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage saajMessage =
SaajUtils.loadMessage(new ClassPathResource("validSoapMessage.xml", getClass()), messageFactory);
+ context = new DefaultMessageContext(new Saaj13SoapMessage(saajMessage),
+ new SaajSoapMessageFactory(messageFactory));
+
boolean result = interceptor.handleRequest(context, null);
assertTrue("Invalid response from interceptor", result);
assertFalse("Response set", context.hasResponse());
}
finally {
// Reset the property
- System.setProperty("javax.xml.validation.SchemaFactory:" + XMLConstants.W3C_XML_SCHEMA_NS_URI, "");
+ System.setProperty("javax.xml.validation.SchemaFactory:" + XMLConstants.W3C_XML_SCHEMA_NS_URI,
+ previousSchemaFactory);
}
}
diff --git a/security/src/main/java/org/springframework/ws/soap/security/AbstractWsSecurityInterceptor.java b/security/src/main/java/org/springframework/ws/soap/security/AbstractWsSecurityInterceptor.java
index 7df2ddb4..fbf9276a 100644
--- a/security/src/main/java/org/springframework/ws/soap/security/AbstractWsSecurityInterceptor.java
+++ b/security/src/main/java/org/springframework/ws/soap/security/AbstractWsSecurityInterceptor.java
@@ -23,10 +23,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert;
import org.springframework.ws.context.MessageContext;
+import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapEndpointInterceptor;
import org.springframework.ws.soap.SoapHeaderElement;
-import org.springframework.ws.soap.SoapBody;
-import org.springframework.ws.soap.context.SoapMessageContext;
+import org.springframework.ws.soap.SoapMessage;
/**
* Interceptor base class for interceptors that handle WS-Security.
@@ -38,17 +38,17 @@ import org.springframework.ws.soap.context.SoapMessageContext;
*/
public abstract class AbstractWsSecurityInterceptor implements SoapEndpointInterceptor {
+ private static final QName WS_SECURITY_NAME =
+ new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security");
+
/**
* Logger available to subclasses.
*/
- private final Log logger = LogFactory.getLog(getClass());
-
- private boolean validateRequest = true;
+ protected final Log logger = LogFactory.getLog(getClass());
private boolean secureResponse = true;
- private static final QName WS_SECURITY_NAME =
- new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security");
+ private boolean validateRequest = true;
/**
* Indicates whether outgoing responsed are to be secured. Defaults to true.
@@ -66,20 +66,14 @@ public abstract class AbstractWsSecurityInterceptor implements SoapEndpointInter
public final boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
if (validateRequest) {
- Assert.isTrue(messageContext instanceof SoapMessageContext,
- "WsSecurityInterceptor requires a SoapMessageContext");
- SoapMessageContext soapMessageContext = (SoapMessageContext) messageContext;
+ Assert.isTrue(messageContext.getRequest() instanceof SoapMessage,
+ "WsSecurityInterceptor requires a SoapMessage request");
try {
- validateRequest(soapMessageContext);
+ validateMessage((SoapMessage) messageContext.getRequest());
return true;
}
catch (WsSecurityValidationException ex) {
- if (logger.isWarnEnabled()) {
- logger.warn("Could not validate request: " + ex.getMessage());
- }
- SoapBody response = soapMessageContext.getSoapResponse().getSoapBody();
- response.addClientOrSenderFault(ex.getMessage(), Locale.ENGLISH);
- return false;
+ return handleValidationException(ex, messageContext);
}
}
else {
@@ -89,18 +83,14 @@ public abstract class AbstractWsSecurityInterceptor implements SoapEndpointInter
public final boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception {
if (secureResponse) {
- Assert.isTrue(messageContext instanceof SoapMessageContext,
- "WsSecurityInterceptor requires a SoapMessageContext");
- SoapMessageContext soapMessageContext = (SoapMessageContext) messageContext;
+ Assert.isTrue(messageContext.getResponse() instanceof SoapMessage,
+ "WsSecurityInterceptor requires a SoapMessage response");
try {
- secureResponse(soapMessageContext);
+ secureMessage((SoapMessage) messageContext.getResponse());
return true;
}
catch (WsSecuritySecurementException ex) {
- if (logger.isErrorEnabled()) {
- logger.error("Could not secure response: " + ex.getMessage(), ex);
- }
- return false;
+ return handleSecurementException(ex, messageContext);
}
}
else {
@@ -108,29 +98,64 @@ public abstract class AbstractWsSecurityInterceptor implements SoapEndpointInter
}
}
+ /**
+ * Returns true, i.e. faults are not secured.
+ */
public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
return true;
}
+ public boolean understands(SoapHeaderElement headerElement) {
+ return WS_SECURITY_NAME.equals(headerElement.getName());
+ }
+
+ /**
+ * Handles an securement exception. Default implementation logs the given exception, and returns
+ * false.
+ *
+ * @param ex the validation exception
+ * @param messageContext the message context
+ * @return true to continue processing the message, false (the default) otherwise
+ */
+ protected boolean handleSecurementException(WsSecuritySecurementException ex, MessageContext messageContext) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Could not secure response: " + ex.getMessage(), ex);
+ }
+ return false;
+ }
+
+ /**
+ * Handles an invalid SOAP message. Default implementation logs the given exception, and creates a SOAP 1.1 Client
+ * or SOAP 1.2 Sender Fault with the exception message as fault string, and returns false.
+ *
+ * @param ex the validation exception
+ * @param messageContext the message context
+ * @return true to continue processing the message, false (the default) otherwise
+ */
+ protected boolean handleValidationException(WsSecurityValidationException ex, MessageContext messageContext) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Could not validate request: " + ex.getMessage());
+ }
+ SoapBody response = ((SoapMessage) messageContext.getResponse()).getSoapBody();
+ response.addClientOrSenderFault(ex.getMessage(), Locale.ENGLISH);
+ return false;
+ }
+
/**
* Abstract template method. Subclasses are required to validate the request contained in the given
* SoapMessageContext, and replace the original request with the validated version.
*
- * @param messageContext the soap message context
+ * @param soapMessage the soap message to validate
* @throws WsSecurityValidationException in case of validation errors
*/
- protected abstract void validateRequest(SoapMessageContext messageContext) throws WsSecurityValidationException;
+ protected abstract void validateMessage(SoapMessage soapMessage) throws WsSecurityValidationException;
/**
* Abstract template method. Subclasses are required to secure the response contained in the given
* SoapMessageContext, and replace the original response with the secured version.
*
- * @param messageContext the soap message context
+ * @param soapMessage the soap message to secure
* @throws WsSecuritySecurementException in case of securement errors
*/
- protected abstract void secureResponse(SoapMessageContext messageContext) throws WsSecuritySecurementException;
-
- public boolean understands(SoapHeaderElement headerElement) {
- return WS_SECURITY_NAME.equals(headerElement.getName());
- }
+ protected abstract void secureMessage(SoapMessage soapMessage) throws WsSecuritySecurementException;
}
diff --git a/security/src/main/java/org/springframework/ws/soap/security/xwss/XwsSecurityInterceptor.java b/security/src/main/java/org/springframework/ws/soap/security/xwss/XwsSecurityInterceptor.java
index 719410db..7709aa59 100644
--- a/security/src/main/java/org/springframework/ws/soap/security/xwss/XwsSecurityInterceptor.java
+++ b/security/src/main/java/org/springframework/ws/soap/security/xwss/XwsSecurityInterceptor.java
@@ -17,7 +17,6 @@
package org.springframework.ws.soap.security.xwss;
import java.io.InputStream;
-
import javax.security.auth.callback.CallbackHandler;
import javax.xml.soap.SOAPMessage;
@@ -25,15 +24,13 @@ import com.sun.xml.wss.ProcessingContext;
import com.sun.xml.wss.XWSSProcessor;
import com.sun.xml.wss.XWSSProcessorFactory;
import com.sun.xml.wss.XWSSecurityException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
-import org.springframework.ws.soap.context.SoapMessageContext;
-import org.springframework.ws.soap.saaj.SaajSoapMessageContext;
+import org.springframework.ws.soap.SoapMessage;
+import org.springframework.ws.soap.saaj.SaajSoapMessage;
import org.springframework.ws.soap.security.AbstractWsSecurityInterceptor;
+import org.springframework.ws.soap.security.WsSecurityValidationException;
import org.springframework.ws.soap.security.xwss.callback.CallbackHandlerChain;
/**
@@ -49,19 +46,17 @@ import org.springframework.ws.soap.security.xwss.callback.CallbackHandlerChain;
* Web Services Tutorial.
*
SaajSoapMessages to operate. This
- * means that you must use a SaajSoapMessageContextFactory to create the SOAP messages.
+ * means that you must use a SaajSoapMessageFactory to create the SOAP messages.
*
* @author Arjen Poutsma
* @see #setCallbackHandler(javax.security.auth.callback.CallbackHandler)
* @see #setPolicyConfiguration(org.springframework.core.io.Resource)
* @see com.sun.xml.wss.impl.callback.XWSSCallback
- * @see org.springframework.ws.soap.saaj.SaajSoapMessageContextFactory
+ * @see org.springframework.ws.soap.saaj.SaajSoapMessageFactory
* @see XWSS
*/
public class XwsSecurityInterceptor extends AbstractWsSecurityInterceptor implements InitializingBean {
- private static final Log logger = LogFactory.getLog(XwsSecurityInterceptor.class);
-
private XWSSProcessor processor;
private CallbackHandler callbackHandler;
@@ -117,35 +112,23 @@ public class XwsSecurityInterceptor extends AbstractWsSecurityInterceptor implem
}
}
- protected void secureResponse(SoapMessageContext soapMessageContext) throws XwsSecuritySecurementException {
- Assert.isTrue(soapMessageContext instanceof SaajSoapMessageContext,
- "XwsSecurityInterceptor requires a SaajSoapMessageContext. " +
- "Use a SaajSoapMessageContextFactory to create the SOAP messages.");
- SaajSoapMessageContext saajMessageContext = (SaajSoapMessageContext) soapMessageContext;
- SOAPMessage securedMessage = secureMessage(saajMessageContext.getSaajResponse());
- saajMessageContext.setSaajResponse(securedMessage);
- }
-
- protected void validateRequest(SoapMessageContext soapMessageContext) throws XwsSecurityValidationException {
- Assert.isTrue(soapMessageContext instanceof SaajSoapMessageContext,
- "XwsSecurityInterceptor requires a SaajSoapMessageContext" +
- "Use a SaajSoapMessageContextFactory to create the SOAP messages.");
- SaajSoapMessageContext saajMessageContext = (SaajSoapMessageContext) soapMessageContext;
- SOAPMessage validatedMessage = validateMessage(saajMessageContext.getSaajRequest());
- saajMessageContext.setSaajRequest(validatedMessage);
- }
-
/**
- * Secures the given SAAJ message in accordance with the defined security policy and returns the secured result.
+ * Secures the given SoapMessage message in accordance with the defined security policy and returns the secured
+ * result.
*
- * @param message the message to be secured
+ * @param soapMessage the message to be secured
* @return the secured message
* @throws XwsSecuritySecurementException in case of errors
+ * @throws IllegalArgumentException when soapMessage is not a SaajSoapMessage
*/
- protected SOAPMessage secureMessage(SOAPMessage message) throws XwsSecuritySecurementException {
+ protected void secureMessage(SoapMessage soapMessage) throws XwsSecuritySecurementException {
+ Assert.isTrue(soapMessage instanceof SaajSoapMessage, "XwsSecurityInterceptor requires a SaajSoapMessage. " +
+ "Use a SaajSoapMessageFactory to create the SOAP messages.");
+ SaajSoapMessage saajSoapMessage = (SaajSoapMessage) soapMessage;
try {
- ProcessingContext context = processor.createProcessingContext(message);
- return processor.secureOutboundMessage(context);
+ ProcessingContext context = processor.createProcessingContext(saajSoapMessage.getSaajMessage());
+ SOAPMessage result = processor.secureOutboundMessage(context);
+ saajSoapMessage.setSaajMessage(result);
}
catch (XWSSecurityException ex) {
throw new XwsSecuritySecurementException(ex.getMessage(), ex);
@@ -153,17 +136,22 @@ public class XwsSecurityInterceptor extends AbstractWsSecurityInterceptor implem
}
/**
- * Validates the given SAAJ message in accordance with the defined security policy and returns the validated
+ * Validates the given SoapMessage message in accordance with the defined security policy and returns the validated
* result.
*
- * @param message the message to be validated
+ * @param soapMessage the message to be validated
* @return the validated message
* @throws XwsSecurityValidationException in case of errors
+ * @throws IllegalArgumentException when soapMessage is not a SaajSoapMessage
*/
- protected SOAPMessage validateMessage(SOAPMessage message) throws XwsSecurityValidationException {
+ protected void validateMessage(SoapMessage soapMessage) throws WsSecurityValidationException {
+ Assert.isTrue(soapMessage instanceof SaajSoapMessage, "XwsSecurityInterceptor requires a SaajSoapMessage. " +
+ "Use a SaajSoapMessageFactory to create the SOAP messages.");
+ SaajSoapMessage saajSoapMessage = (SaajSoapMessage) soapMessage;
try {
- ProcessingContext context = processor.createProcessingContext(message);
- return processor.verifyInboundMessage(context);
+ ProcessingContext context = processor.createProcessingContext(saajSoapMessage.getSaajMessage());
+ SOAPMessage result = processor.verifyInboundMessage(context);
+ saajSoapMessage.setSaajMessage(result);
}
catch (XWSSecurityException ex) {
throw new XwsSecurityValidationException(ex.getMessage(), ex);
diff --git a/security/src/test/java/org/springframework/ws/soap/security/xwss/XwsSecurityInterceptorTest.java b/security/src/test/java/org/springframework/ws/soap/security/xwss/XwsSecurityInterceptorTest.java
index 12b71933..4cbe2718 100644
--- a/security/src/test/java/org/springframework/ws/soap/security/xwss/XwsSecurityInterceptorTest.java
+++ b/security/src/test/java/org/springframework/ws/soap/security/xwss/XwsSecurityInterceptorTest.java
@@ -20,8 +20,13 @@ import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import junit.framework.TestCase;
-import org.springframework.ws.soap.saaj.SaajSoapMessageContext;
-import org.springframework.ws.soap.saaj.saaj13.Saaj13SoapMessageContext;
+import org.springframework.ws.context.DefaultMessageContext;
+import org.springframework.ws.context.MessageContext;
+import org.springframework.ws.soap.SoapMessage;
+import org.springframework.ws.soap.saaj.SaajSoapMessage;
+import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
+import org.springframework.ws.soap.saaj.saaj13.Saaj13SoapMessage;
+import org.springframework.ws.soap.security.WsSecurityValidationException;
public class XwsSecurityInterceptorTest extends TestCase {
@@ -35,42 +40,43 @@ public class XwsSecurityInterceptorTest extends TestCase {
final SOAPMessage request = messageFactory.createMessage();
final SOAPMessage validatedRequest = messageFactory.createMessage();
XwsSecurityInterceptor interceptor = new XwsSecurityInterceptor() {
- protected SOAPMessage secureMessage(SOAPMessage message) throws XwsSecuritySecurementException {
+
+ protected void secureMessage(SoapMessage soapMessage) throws XwsSecuritySecurementException {
fail("secure not expected");
- return null;
}
- protected SOAPMessage validateMessage(SOAPMessage message) throws XwsSecurityValidationException {
- assertEquals("Invalid message", request, message);
- return validatedRequest;
+ protected void validateMessage(SoapMessage message) throws WsSecurityValidationException {
+ SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
+ assertEquals("Invalid message", request, saajSoapMessage.getSaajMessage());
+ saajSoapMessage.setSaajMessage(validatedRequest);
}
};
- SaajSoapMessageContext context = new Saaj13SoapMessageContext(request, messageFactory);
+ MessageContext context =
+ new DefaultMessageContext(new Saaj13SoapMessage(request), new SaajSoapMessageFactory(messageFactory));
interceptor.handleRequest(context, null);
- assertEquals("Invalid request", validatedRequest, context.getSaajRequest());
+ assertEquals("Invalid request", validatedRequest, ((SaajSoapMessage) context.getRequest()).getSaajMessage());
}
public void testhandleResponse() throws Exception {
- final SOAPMessage response = messageFactory.createMessage();
final SOAPMessage securedResponse = messageFactory.createMessage();
XwsSecurityInterceptor interceptor = new XwsSecurityInterceptor() {
- protected SOAPMessage secureMessage(SOAPMessage message) throws XwsSecuritySecurementException {
- assertEquals("Invalid message", response, message);
- return securedResponse;
+
+ protected void secureMessage(SoapMessage message) throws XwsSecuritySecurementException {
+ SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
+ saajSoapMessage.setSaajMessage(securedResponse);
}
- protected SOAPMessage validateMessage(SOAPMessage message) throws XwsSecurityValidationException {
+ protected void validateMessage(SoapMessage soapMessage) throws WsSecurityValidationException {
fail("validate not expected");
- return null;
}
};
SOAPMessage request = messageFactory.createMessage();
- SaajSoapMessageContext context = new Saaj13SoapMessageContext(request, messageFactory);
- context.setSaajResponse(response);
+ MessageContext context =
+ new DefaultMessageContext(new Saaj13SoapMessage(request), new SaajSoapMessageFactory(messageFactory));
interceptor.handleResponse(context, null);
- assertEquals("Invalid response", securedResponse, context.getSaajResponse());
+ assertEquals("Invalid response", securedResponse, ((SaajSoapMessage) context.getResponse()).getSaajMessage());
}
}
\ No newline at end of file
diff --git a/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorEncryptTest.java b/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorEncryptTest.java
index 12475244..96196750 100644
--- a/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorEncryptTest.java
+++ b/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorEncryptTest.java
@@ -22,8 +22,8 @@ import javax.xml.soap.SOAPMessage;
import com.sun.xml.wss.impl.callback.DecryptionKeyCallback;
import com.sun.xml.wss.impl.callback.EncryptionKeyCallback;
-
import org.springframework.core.io.ClassPathResource;
+import org.springframework.ws.soap.saaj.SaajSoapMessage;
import org.springframework.ws.soap.security.xwss.callback.AbstractCallbackHandler;
public class XwssMessageInterceptorEncryptTest extends XwssMessageInterceptorKeyStoreTestCase {
@@ -52,8 +52,9 @@ public class XwssMessageInterceptorEncryptTest extends XwssMessageInterceptorKey
};
interceptor.setCallbackHandler(handler);
interceptor.afterPropertiesSet();
- SOAPMessage message = loadSaajMessage("empty-soap.xml");
- SOAPMessage result = interceptor.secureMessage(message);
+ SaajSoapMessage message = loadSaajMessage("empty-soap.xml");
+ interceptor.secureMessage(message);
+ SOAPMessage result = message.getSaajMessage();
assertNotNull("No result returned", result);
assertXpathExists("BinarySecurityToken does not exist",
"SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:BinarySecurityToken", result);
@@ -85,8 +86,9 @@ public class XwssMessageInterceptorEncryptTest extends XwssMessageInterceptorKey
};
interceptor.setCallbackHandler(handler);
interceptor.afterPropertiesSet();
- SOAPMessage message = loadSaajMessage("empty-soap.xml");
- SOAPMessage result = interceptor.secureMessage(message);
+ SaajSoapMessage message = loadSaajMessage("empty-soap.xml");
+ interceptor.secureMessage(message);
+ SOAPMessage result = message.getSaajMessage();
assertNotNull("No result returned", result);
assertXpathExists("BinarySecurityToken does not exist",
"SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:BinarySecurityToken", result);
@@ -118,8 +120,9 @@ public class XwssMessageInterceptorEncryptTest extends XwssMessageInterceptorKey
};
interceptor.setCallbackHandler(handler);
interceptor.afterPropertiesSet();
- SOAPMessage message = loadSaajMessage("encrypted-soap.xml");
- SOAPMessage result = interceptor.validateMessage(message);
+ SaajSoapMessage message = loadSaajMessage("encrypted-soap.xml");
+ interceptor.validateMessage(message);
+ SOAPMessage result = message.getSaajMessage();
assertNotNull("No result returned", result);
assertXpathNotExists("Security Header not removed", "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security", result);
}
diff --git a/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorSignTest.java b/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorSignTest.java
index b3002a84..90a00a95 100644
--- a/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorSignTest.java
+++ b/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorSignTest.java
@@ -17,15 +17,14 @@
package org.springframework.ws.soap.security.xwss;
import java.security.cert.X509Certificate;
-
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.xml.soap.SOAPMessage;
import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
import com.sun.xml.wss.impl.callback.SignatureKeyCallback;
-
import org.springframework.core.io.ClassPathResource;
+import org.springframework.ws.soap.saaj.SaajSoapMessage;
import org.springframework.ws.soap.security.xwss.callback.AbstractCallbackHandler;
public class XwssMessageInterceptorSignTest extends XwssMessageInterceptorKeyStoreTestCase {
@@ -54,8 +53,9 @@ public class XwssMessageInterceptorSignTest extends XwssMessageInterceptorKeySto
};
interceptor.setCallbackHandler(handler);
interceptor.afterPropertiesSet();
- SOAPMessage message = loadSaajMessage("empty-soap.xml");
- SOAPMessage result = interceptor.secureMessage(message);
+ SaajSoapMessage message = loadSaajMessage("empty-soap.xml");
+ interceptor.secureMessage(message);
+ SOAPMessage result = message.getSaajMessage();
assertNotNull("No result returned", result);
assertXpathExists("BinarySecurityToken does not exist",
"SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:BinarySecurityToken", result);
@@ -88,8 +88,9 @@ public class XwssMessageInterceptorSignTest extends XwssMessageInterceptorKeySto
};
interceptor.setCallbackHandler(handler);
interceptor.afterPropertiesSet();
- SOAPMessage message = loadSaajMessage("empty-soap.xml");
- SOAPMessage result = interceptor.secureMessage(message);
+ SaajSoapMessage message = loadSaajMessage("empty-soap.xml");
+ interceptor.secureMessage(message);
+ SOAPMessage result = message.getSaajMessage();
assertNotNull("No result returned", result);
assertXpathExists("BinarySecurityToken does not exist",
"SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:BinarySecurityToken", result);
@@ -118,8 +119,9 @@ public class XwssMessageInterceptorSignTest extends XwssMessageInterceptorKeySto
};
interceptor.setCallbackHandler(handler);
interceptor.afterPropertiesSet();
- SOAPMessage message = loadSaajMessage("signed-soap.xml");
- SOAPMessage result = interceptor.validateMessage(message);
+ SaajSoapMessage message = loadSaajMessage("signed-soap.xml");
+ interceptor.validateMessage(message);
+ SOAPMessage result = message.getSaajMessage();
assertNotNull("No result returned", result);
assertXpathNotExists("Security Header not removed", "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security", result);
}
diff --git a/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorTestCase.java b/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorTestCase.java
index 87199b43..f1550e6c 100644
--- a/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorTestCase.java
+++ b/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorTestCase.java
@@ -20,18 +20,18 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
-
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import junit.framework.TestCase;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-
+import org.springframework.ws.soap.saaj.SaajSoapMessage;
+import org.springframework.ws.soap.saaj.saaj13.Saaj13SoapMessage;
import org.springframework.xml.xpath.XPathExpression;
import org.springframework.xml.xpath.XPathExpressionFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
public abstract class XwssMessageInterceptorTestCase extends TestCase {
@@ -76,14 +76,14 @@ public abstract class XwssMessageInterceptorTestCase extends TestCase {
assertNull(message, node);
}
- protected SOAPMessage loadSaajMessage(String fileName) throws SOAPException, IOException {
+ protected SaajSoapMessage loadSaajMessage(String fileName) throws SOAPException, IOException {
MimeHeaders mimeHeaders = new MimeHeaders();
mimeHeaders.addHeader("Content-Type", "text/xml");
InputStream is = null;
try {
is = getClass().getResourceAsStream(fileName);
- assertNotNull("Could not load SAAJ message with name [" + fileName + "]", is);
- return messageFactory.createMessage(mimeHeaders, is);
+ assertNotNull("Could not load SAAJ message with name [" + fileName + "]", is);
+ return new Saaj13SoapMessage(messageFactory.createMessage(mimeHeaders, is));
}
finally {
if (is != null) {
diff --git a/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorUsernameTokenTest.java b/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorUsernameTokenTest.java
index ac2d1ccd..66efda87 100644
--- a/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorUsernameTokenTest.java
+++ b/security/src/test/java/org/springframework/ws/soap/security/xwss/XwssMessageInterceptorUsernameTokenTest.java
@@ -25,6 +25,7 @@ import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
import com.sun.xml.wss.impl.callback.TimestampValidationCallback;
import com.sun.xml.wss.impl.callback.UsernameCallback;
import org.springframework.core.io.ClassPathResource;
+import org.springframework.ws.soap.saaj.SaajSoapMessage;
import org.springframework.ws.soap.security.xwss.callback.AbstractCallbackHandler;
public class XwssMessageInterceptorUsernameTokenTest extends XwssMessageInterceptorTestCase {
@@ -48,13 +49,12 @@ public class XwssMessageInterceptorUsernameTokenTest extends XwssMessageIntercep
};
interceptor.setCallbackHandler(handler);
interceptor.afterPropertiesSet();
- SOAPMessage message = loadSaajMessage("empty-soap.xml");
- SOAPMessage result = interceptor.secureMessage(message);
+ SaajSoapMessage message = loadSaajMessage("empty-soap.xml");
+ interceptor.secureMessage(message);
+ SOAPMessage result = message.getSaajMessage();
assertNotNull("No result returned", result);
- assertXpathEvaluatesTo("Invalid Username",
- "Bert",
- "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:UsernameToken/wsse:Username/text()",
- result);
+ assertXpathEvaluatesTo("Invalid Username", "Bert",
+ "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:UsernameToken/wsse:Username/text()", result);
assertXpathExists("Password does not exist",
"/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:UsernameToken/wsse:Password[@Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest']",
result);
@@ -79,15 +79,13 @@ public class XwssMessageInterceptorUsernameTokenTest extends XwssMessageIntercep
};
interceptor.setCallbackHandler(handler);
interceptor.afterPropertiesSet();
- SOAPMessage message = loadSaajMessage("empty-soap.xml");
- SOAPMessage result = interceptor.secureMessage(message);
+ SaajSoapMessage message = loadSaajMessage("empty-soap.xml");
+ interceptor.secureMessage(message);
+ SOAPMessage result = message.getSaajMessage();
assertNotNull("No result returned", result);
- assertXpathEvaluatesTo("Invalid Username",
- "Bert",
- "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:UsernameToken/wsse:Username/text()",
- result);
- assertXpathEvaluatesTo("Invalid Password",
- "Ernie",
+ assertXpathEvaluatesTo("Invalid Username", "Bert",
+ "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:UsernameToken/wsse:Username/text()", result);
+ assertXpathEvaluatesTo("Invalid Password", "Ernie",
"/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:UsernameToken/wsse:Password[@Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText']/text()",
result);
}
@@ -123,8 +121,9 @@ public class XwssMessageInterceptorUsernameTokenTest extends XwssMessageIntercep
};
interceptor.setCallbackHandler(handler);
interceptor.afterPropertiesSet();
- SOAPMessage message = loadSaajMessage("usernameTokenPlainText-soap.xml");
- SOAPMessage result = interceptor.validateMessage(message);
+ SaajSoapMessage message = loadSaajMessage("usernameTokenPlainText-soap.xml");
+ interceptor.validateMessage(message);
+ SOAPMessage result = message.getSaajMessage();
assertNotNull("No result returned", result);
assertXpathNotExists("Security Header not removed", "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security", result);
}
@@ -161,8 +160,9 @@ public class XwssMessageInterceptorUsernameTokenTest extends XwssMessageIntercep
};
interceptor.setCallbackHandler(handler);
interceptor.afterPropertiesSet();
- SOAPMessage message = loadSaajMessage("usernameTokenDigest-soap.xml");
- SOAPMessage result = interceptor.validateMessage(message);
+ SaajSoapMessage message = loadSaajMessage("usernameTokenDigest-soap.xml");
+ interceptor.validateMessage(message);
+ SOAPMessage result = message.getSaajMessage();
assertNotNull("No result returned", result);
assertXpathNotExists("Security Header not removed", "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security", result);
}