SWS-675 - XwssSecurityInterceptor in combination with <sws:interceptors>
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2011 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
|
||||
* 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,
|
||||
@@ -27,8 +27,8 @@ import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.springframework.ws.server.SmartEndpointInterceptor;
|
||||
import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor;
|
||||
import org.springframework.ws.server.endpoint.interceptor.PayloadRootSmartEndpointInterceptor;
|
||||
import org.springframework.ws.soap.server.endpoint.interceptor.DelegatingSmartSoapEndpointInterceptor;
|
||||
import org.springframework.ws.soap.server.endpoint.interceptor.PayloadRootSmartSoapEndpointInterceptor;
|
||||
import org.springframework.ws.soap.server.endpoint.interceptor.SoapActionSmartEndpointInterceptor;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
@@ -50,7 +50,7 @@ class InterceptorsBeanDefinitionParser implements BeanDefinitionParser {
|
||||
for (Element childElement : childElements) {
|
||||
if ("bean".equals(childElement.getLocalName())) {
|
||||
RootBeanDefinition smartInterceptorDef =
|
||||
createSmartInterceptorDefinition(DelegatingSmartEndpointInterceptor.class, childElement,
|
||||
createSmartInterceptorDefinition(DelegatingSmartSoapEndpointInterceptor.class, childElement,
|
||||
parserContext);
|
||||
BeanDefinitionHolder interceptorDef = createInterceptorDefinition(parserContext, childElement);
|
||||
|
||||
@@ -62,7 +62,7 @@ class InterceptorsBeanDefinitionParser implements BeanDefinitionParser {
|
||||
List<Element> beanElements = DomUtils.getChildElementsByTagName(childElement, "bean");
|
||||
for (Element beanElement : beanElements) {
|
||||
RootBeanDefinition smartInterceptorDef =
|
||||
createSmartInterceptorDefinition(PayloadRootSmartEndpointInterceptor.class, childElement,
|
||||
createSmartInterceptorDefinition(PayloadRootSmartSoapEndpointInterceptor.class, childElement,
|
||||
parserContext);
|
||||
BeanDefinitionHolder interceptorDef = createInterceptorDefinition(parserContext, beanElement);
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2011 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
|
||||
* 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,
|
||||
@@ -43,6 +43,14 @@ public class DelegatingSmartEndpointInterceptor implements SmartEndpointIntercep
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the delegate.
|
||||
* @return
|
||||
*/
|
||||
protected EndpointInterceptor getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p/>
|
||||
@@ -67,14 +75,14 @@ public class DelegatingSmartEndpointInterceptor implements SmartEndpointIntercep
|
||||
}
|
||||
|
||||
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
|
||||
return delegate.handleRequest(messageContext, endpoint);
|
||||
return getDelegate().handleRequest(messageContext, endpoint);
|
||||
}
|
||||
|
||||
public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception {
|
||||
return delegate.handleResponse(messageContext, endpoint);
|
||||
return getDelegate().handleResponse(messageContext, endpoint);
|
||||
}
|
||||
|
||||
public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
|
||||
return delegate.handleFault(messageContext, endpoint);
|
||||
return getDelegate().handleFault(messageContext, endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2005-2011 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.server;
|
||||
|
||||
import org.springframework.ws.server.SmartEndpointInterceptor;
|
||||
|
||||
/**
|
||||
* SOAP-specific extension of the {@link org.springframework.ws.server.SmartEndpointInterceptor} interface. Allows for
|
||||
* handling of SOAP faults, which are considered different from regular responses.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface SmartSoapEndpointInterceptor extends SmartEndpointInterceptor, SoapEndpointInterceptor {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2005-2011 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.server.endpoint.interceptor;
|
||||
|
||||
import org.springframework.ws.server.EndpointInterceptor;
|
||||
import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor;
|
||||
import org.springframework.ws.soap.SoapHeaderElement;
|
||||
import org.springframework.ws.soap.server.SmartSoapEndpointInterceptor;
|
||||
import org.springframework.ws.soap.server.SoapEndpointInterceptor;
|
||||
|
||||
/**
|
||||
* Implementation of the {@link SmartSoapEndpointInterceptor} interface that delegates to a delegate {@link
|
||||
* SoapEndpointInterceptor}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public class DelegatingSmartSoapEndpointInterceptor extends DelegatingSmartEndpointInterceptor
|
||||
implements SmartSoapEndpointInterceptor {
|
||||
|
||||
/**
|
||||
* Creates a new instance of the {@code DelegatingSmartSoapEndpointInterceptor} with the given delegate.
|
||||
*
|
||||
* @param delegate the endpoint interceptor to delegate to.
|
||||
*/
|
||||
public DelegatingSmartSoapEndpointInterceptor(EndpointInterceptor delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
public boolean understands(SoapHeaderElement header) {
|
||||
EndpointInterceptor delegate = getDelegate();
|
||||
if (delegate instanceof SoapEndpointInterceptor) {
|
||||
return ((SoapEndpointInterceptor) delegate).understands(header);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2011 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
|
||||
* 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,
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.server.endpoint.interceptor;
|
||||
package org.springframework.ws.soap.server.endpoint.interceptor;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.TransformerException;
|
||||
@@ -27,13 +27,14 @@ import org.springframework.ws.server.endpoint.support.PayloadRootUtils;
|
||||
import org.springframework.xml.transform.TransformerHelper;
|
||||
|
||||
/**
|
||||
* Implementation of the {@link org.springframework.ws.server.SmartEndpointInterceptor} interface that only intercepts
|
||||
* requests that have a specified namespace URI or local part (or both) as payload root.
|
||||
* Implementation of the {@link org.springframework.ws.soap.server.SmartSoapEndpointInterceptor
|
||||
* SmartSoapEndpointInterceptor} interface that only intercepts requests that have a specified namespace URI or local
|
||||
* part (or both) as payload root.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public class PayloadRootSmartEndpointInterceptor extends DelegatingSmartEndpointInterceptor {
|
||||
public class PayloadRootSmartSoapEndpointInterceptor extends DelegatingSmartSoapEndpointInterceptor {
|
||||
|
||||
private TransformerHelper transformerHelper = new TransformerHelper();
|
||||
|
||||
@@ -41,7 +42,9 @@ public class PayloadRootSmartEndpointInterceptor extends DelegatingSmartEndpoint
|
||||
|
||||
private final String localPart;
|
||||
|
||||
public PayloadRootSmartEndpointInterceptor(EndpointInterceptor delegate, String namespaceUri, String localPart) {
|
||||
public PayloadRootSmartSoapEndpointInterceptor(EndpointInterceptor delegate,
|
||||
String namespaceUri,
|
||||
String localPart) {
|
||||
super(delegate);
|
||||
Assert.hasLength(namespaceUri, "namespaceUri can not be empty");
|
||||
this.namespaceUri = namespaceUri;
|
||||
@@ -56,8 +59,10 @@ public class PayloadRootSmartEndpointInterceptor extends DelegatingSmartEndpoint
|
||||
protected boolean shouldIntercept(WebServiceMessage request, Object endpoint) {
|
||||
try {
|
||||
QName payloadRootName = PayloadRootUtils.getPayloadRootQName(request.getPayloadSource(), transformerHelper);
|
||||
return !(StringUtils.hasLength(namespaceUri) && !namespaceUri.equals(payloadRootName.getNamespaceURI()) ||
|
||||
StringUtils.hasLength(localPart) && !localPart.equals(payloadRootName.getLocalPart()));
|
||||
if (!namespaceUri.equals(payloadRootName.getNamespaceURI())) {
|
||||
return false;
|
||||
}
|
||||
return !StringUtils.hasLength(localPart) || localPart.equals(payloadRootName.getLocalPart());
|
||||
|
||||
}
|
||||
catch (TransformerException e) {
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2011 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
|
||||
* 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,
|
||||
@@ -20,7 +20,6 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.server.EndpointInterceptor;
|
||||
import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
|
||||
/**
|
||||
@@ -30,7 +29,7 @@ import org.springframework.ws.soap.SoapMessage;
|
||||
* @author Arjen Poutsma
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SoapActionSmartEndpointInterceptor extends DelegatingSmartEndpointInterceptor {
|
||||
public class SoapActionSmartEndpointInterceptor extends DelegatingSmartSoapEndpointInterceptor {
|
||||
|
||||
private final String soapAction;
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2011 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
|
||||
* 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,
|
||||
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor;
|
||||
import org.springframework.ws.server.endpoint.interceptor.PayloadRootSmartEndpointInterceptor;
|
||||
import org.springframework.ws.soap.server.endpoint.interceptor.PayloadRootSmartSoapEndpointInterceptor;
|
||||
import org.springframework.ws.soap.server.endpoint.interceptor.SoapActionSmartEndpointInterceptor;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -43,7 +43,7 @@ public class InterceptorsBeanDefinitionParserTest {
|
||||
Map<String, ?> result = applicationContext.getBeansOfType(DelegatingSmartEndpointInterceptor.class);
|
||||
assertEquals("no smart interceptors found", 5, result.size());
|
||||
|
||||
result = applicationContext.getBeansOfType(PayloadRootSmartEndpointInterceptor.class);
|
||||
result = applicationContext.getBeansOfType(PayloadRootSmartSoapEndpointInterceptor.class);
|
||||
assertEquals("no interceptors found", 2, result.size());
|
||||
|
||||
result = applicationContext.getBeansOfType(SoapActionSmartEndpointInterceptor.class);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
* Copyright 2005-2011 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
|
||||
* 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,
|
||||
@@ -14,13 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.server.endpoint.interceptor;
|
||||
package org.springframework.ws.soap.server.endpoint.interceptor;
|
||||
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.EndpointInterceptor;
|
||||
import org.springframework.ws.server.endpoint.interceptor.EndpointInterceptorAdapter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -28,7 +29,7 @@ import org.junit.Test;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class PayloadRootSmartEndpointInterceptorTest {
|
||||
public class PayloadRootSmartSoapEndpointInterceptorTest {
|
||||
|
||||
private EndpointInterceptor delegate;
|
||||
|
||||
@@ -51,13 +52,13 @@ public class PayloadRootSmartEndpointInterceptorTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void neitherNamespaceNorLocalPart() {
|
||||
new PayloadRootSmartEndpointInterceptor(delegate, null, null);
|
||||
new PayloadRootSmartSoapEndpointInterceptor(delegate, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldInterceptFullMatch() throws Exception {
|
||||
PayloadRootSmartEndpointInterceptor interceptor =
|
||||
new PayloadRootSmartEndpointInterceptor(delegate, namespaceUri, localPart);
|
||||
PayloadRootSmartSoapEndpointInterceptor interceptor =
|
||||
new PayloadRootSmartSoapEndpointInterceptor(delegate, namespaceUri, localPart);
|
||||
|
||||
boolean result = interceptor.shouldIntercept(messageContext, null);
|
||||
assertTrue("Interceptor should apply", result);
|
||||
@@ -65,20 +66,29 @@ public class PayloadRootSmartEndpointInterceptorTest {
|
||||
|
||||
@Test
|
||||
public void shouldInterceptFullNonMatch() throws Exception {
|
||||
PayloadRootSmartEndpointInterceptor interceptor =
|
||||
new PayloadRootSmartEndpointInterceptor(delegate, "http://springframework.org/other", localPart);
|
||||
PayloadRootSmartSoapEndpointInterceptor interceptor =
|
||||
new PayloadRootSmartSoapEndpointInterceptor(delegate, "http://springframework.org/other", localPart);
|
||||
|
||||
boolean result = interceptor.shouldIntercept(messageContext, null);
|
||||
assertFalse("Interceptor should apply", result);
|
||||
assertFalse("Interceptor should not apply", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldInterceptNamespaceUriMatch() throws Exception {
|
||||
PayloadRootSmartEndpointInterceptor interceptor =
|
||||
new PayloadRootSmartEndpointInterceptor(delegate, namespaceUri, null);
|
||||
PayloadRootSmartSoapEndpointInterceptor interceptor =
|
||||
new PayloadRootSmartSoapEndpointInterceptor(delegate, namespaceUri, null);
|
||||
|
||||
boolean result = interceptor.shouldIntercept(messageContext, null);
|
||||
assertTrue("Interceptor should apply", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldInterceptNamespaceUriNonMatch() throws Exception {
|
||||
PayloadRootSmartSoapEndpointInterceptor interceptor =
|
||||
new PayloadRootSmartSoapEndpointInterceptor(delegate, "http://springframework.org/other", null);
|
||||
|
||||
boolean result = interceptor.shouldIntercept(messageContext, null);
|
||||
assertFalse("Interceptor should not apply", result);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user