Skip to content

Commit 7bb66cb

Browse files
committed
SWS-675 - XwssSecurityInterceptor in combination with <sws:interceptors>
1 parent fc3ed75 commit 7bb66cb

File tree

8 files changed

+145
-40
lines changed

8 files changed

+145
-40
lines changed

core/src/main/java/org/springframework/ws/config/InterceptorsBeanDefinitionParser.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -27,8 +27,8 @@
2727
import org.springframework.beans.factory.xml.ParserContext;
2828
import org.springframework.util.xml.DomUtils;
2929
import org.springframework.ws.server.SmartEndpointInterceptor;
30-
import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor;
31-
import org.springframework.ws.server.endpoint.interceptor.PayloadRootSmartEndpointInterceptor;
30+
import org.springframework.ws.soap.server.endpoint.interceptor.DelegatingSmartSoapEndpointInterceptor;
31+
import org.springframework.ws.soap.server.endpoint.interceptor.PayloadRootSmartSoapEndpointInterceptor;
3232
import org.springframework.ws.soap.server.endpoint.interceptor.SoapActionSmartEndpointInterceptor;
3333

3434
import org.w3c.dom.Element;
@@ -50,7 +50,7 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
5050
for (Element childElement : childElements) {
5151
if ("bean".equals(childElement.getLocalName())) {
5252
RootBeanDefinition smartInterceptorDef =
53-
createSmartInterceptorDefinition(DelegatingSmartEndpointInterceptor.class, childElement,
53+
createSmartInterceptorDefinition(DelegatingSmartSoapEndpointInterceptor.class, childElement,
5454
parserContext);
5555
BeanDefinitionHolder interceptorDef = createInterceptorDefinition(parserContext, childElement);
5656

@@ -62,7 +62,7 @@ else if ("payloadRoot".equals(childElement.getLocalName())) {
6262
List<Element> beanElements = DomUtils.getChildElementsByTagName(childElement, "bean");
6363
for (Element beanElement : beanElements) {
6464
RootBeanDefinition smartInterceptorDef =
65-
createSmartInterceptorDefinition(PayloadRootSmartEndpointInterceptor.class, childElement,
65+
createSmartInterceptorDefinition(PayloadRootSmartSoapEndpointInterceptor.class, childElement,
6666
parserContext);
6767
BeanDefinitionHolder interceptorDef = createInterceptorDefinition(parserContext, beanElement);
6868

core/src/main/java/org/springframework/ws/server/endpoint/interceptor/DelegatingSmartEndpointInterceptor.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -43,6 +43,14 @@ public DelegatingSmartEndpointInterceptor(EndpointInterceptor delegate) {
4343
this.delegate = delegate;
4444
}
4545

46+
/**
47+
* Returns the delegate.
48+
* @return
49+
*/
50+
protected EndpointInterceptor getDelegate() {
51+
return delegate;
52+
}
53+
4654
/**
4755
* {@inheritDoc}
4856
* <p/>
@@ -67,14 +75,14 @@ protected boolean shouldIntercept(WebServiceMessage request, Object endpoint) {
6775
}
6876

6977
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
70-
return delegate.handleRequest(messageContext, endpoint);
78+
return getDelegate().handleRequest(messageContext, endpoint);
7179
}
7280

7381
public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception {
74-
return delegate.handleResponse(messageContext, endpoint);
82+
return getDelegate().handleResponse(messageContext, endpoint);
7583
}
7684

7785
public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
78-
return delegate.handleFault(messageContext, endpoint);
86+
return getDelegate().handleFault(messageContext, endpoint);
7987
}
8088
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2005-2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ws.soap.server;
18+
19+
import org.springframework.ws.server.SmartEndpointInterceptor;
20+
21+
/**
22+
* SOAP-specific extension of the {@link org.springframework.ws.server.SmartEndpointInterceptor} interface. Allows for
23+
* handling of SOAP faults, which are considered different from regular responses.
24+
*
25+
* @author Arjen Poutsma
26+
* @since 2.0
27+
*/
28+
public interface SmartSoapEndpointInterceptor extends SmartEndpointInterceptor, SoapEndpointInterceptor {
29+
30+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2005-2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ws.soap.server.endpoint.interceptor;
18+
19+
import org.springframework.ws.server.EndpointInterceptor;
20+
import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor;
21+
import org.springframework.ws.soap.SoapHeaderElement;
22+
import org.springframework.ws.soap.server.SmartSoapEndpointInterceptor;
23+
import org.springframework.ws.soap.server.SoapEndpointInterceptor;
24+
25+
/**
26+
* Implementation of the {@link SmartSoapEndpointInterceptor} interface that delegates to a delegate {@link
27+
* SoapEndpointInterceptor}.
28+
*
29+
* @author Arjen Poutsma
30+
* @since 2.0
31+
*/
32+
public class DelegatingSmartSoapEndpointInterceptor extends DelegatingSmartEndpointInterceptor
33+
implements SmartSoapEndpointInterceptor {
34+
35+
/**
36+
* Creates a new instance of the {@code DelegatingSmartSoapEndpointInterceptor} with the given delegate.
37+
*
38+
* @param delegate the endpoint interceptor to delegate to.
39+
*/
40+
public DelegatingSmartSoapEndpointInterceptor(EndpointInterceptor delegate) {
41+
super(delegate);
42+
}
43+
44+
public boolean understands(SoapHeaderElement header) {
45+
EndpointInterceptor delegate = getDelegate();
46+
if (delegate instanceof SoapEndpointInterceptor) {
47+
return ((SoapEndpointInterceptor) delegate).understands(header);
48+
}
49+
else {
50+
return false;
51+
}
52+
}
53+
}
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.ws.server.endpoint.interceptor;
17+
package org.springframework.ws.soap.server.endpoint.interceptor;
1818

1919
import javax.xml.namespace.QName;
2020
import javax.xml.transform.TransformerException;
@@ -27,21 +27,24 @@
2727
import org.springframework.xml.transform.TransformerHelper;
2828

2929
/**
30-
* Implementation of the {@link org.springframework.ws.server.SmartEndpointInterceptor} interface that only intercepts
31-
* requests that have a specified namespace URI or local part (or both) as payload root.
30+
* Implementation of the {@link org.springframework.ws.soap.server.SmartSoapEndpointInterceptor
31+
* SmartSoapEndpointInterceptor} interface that only intercepts requests that have a specified namespace URI or local
32+
* part (or both) as payload root.
3233
*
3334
* @author Arjen Poutsma
3435
* @since 2.0
3536
*/
36-
public class PayloadRootSmartEndpointInterceptor extends DelegatingSmartEndpointInterceptor {
37+
public class PayloadRootSmartSoapEndpointInterceptor extends DelegatingSmartSoapEndpointInterceptor {
3738

3839
private TransformerHelper transformerHelper = new TransformerHelper();
3940

4041
private final String namespaceUri;
4142

4243
private final String localPart;
4344

44-
public PayloadRootSmartEndpointInterceptor(EndpointInterceptor delegate, String namespaceUri, String localPart) {
45+
public PayloadRootSmartSoapEndpointInterceptor(EndpointInterceptor delegate,
46+
String namespaceUri,
47+
String localPart) {
4548
super(delegate);
4649
Assert.hasLength(namespaceUri, "namespaceUri can not be empty");
4750
this.namespaceUri = namespaceUri;
@@ -56,8 +59,10 @@ public void setTransformerHelper(TransformerHelper transformerHelper) {
5659
protected boolean shouldIntercept(WebServiceMessage request, Object endpoint) {
5760
try {
5861
QName payloadRootName = PayloadRootUtils.getPayloadRootQName(request.getPayloadSource(), transformerHelper);
59-
return !(StringUtils.hasLength(namespaceUri) && !namespaceUri.equals(payloadRootName.getNamespaceURI()) ||
60-
StringUtils.hasLength(localPart) && !localPart.equals(payloadRootName.getLocalPart()));
62+
if (!namespaceUri.equals(payloadRootName.getNamespaceURI())) {
63+
return false;
64+
}
65+
return !StringUtils.hasLength(localPart) || localPart.equals(payloadRootName.getLocalPart());
6166

6267
}
6368
catch (TransformerException e) {

core/src/main/java/org/springframework/ws/soap/server/endpoint/interceptor/SoapActionSmartEndpointInterceptor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,7 +20,6 @@
2020
import org.springframework.util.StringUtils;
2121
import org.springframework.ws.WebServiceMessage;
2222
import org.springframework.ws.server.EndpointInterceptor;
23-
import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor;
2423
import org.springframework.ws.soap.SoapMessage;
2524

2625
/**
@@ -30,7 +29,7 @@
3029
* @author Arjen Poutsma
3130
* @since 2.0
3231
*/
33-
public class SoapActionSmartEndpointInterceptor extends DelegatingSmartEndpointInterceptor {
32+
public class SoapActionSmartEndpointInterceptor extends DelegatingSmartSoapEndpointInterceptor {
3433

3534
private final String soapAction;
3635

core/src/test/java/org/springframework/ws/config/InterceptorsBeanDefinitionParserTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,7 +21,7 @@
2121
import org.springframework.context.ApplicationContext;
2222
import org.springframework.context.support.ClassPathXmlApplicationContext;
2323
import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor;
24-
import org.springframework.ws.server.endpoint.interceptor.PayloadRootSmartEndpointInterceptor;
24+
import org.springframework.ws.soap.server.endpoint.interceptor.PayloadRootSmartSoapEndpointInterceptor;
2525
import org.springframework.ws.soap.server.endpoint.interceptor.SoapActionSmartEndpointInterceptor;
2626

2727
import org.junit.Before;
@@ -43,7 +43,7 @@ public void namespace() throws Exception {
4343
Map<String, ?> result = applicationContext.getBeansOfType(DelegatingSmartEndpointInterceptor.class);
4444
assertEquals("no smart interceptors found", 5, result.size());
4545

46-
result = applicationContext.getBeansOfType(PayloadRootSmartEndpointInterceptor.class);
46+
result = applicationContext.getBeansOfType(PayloadRootSmartSoapEndpointInterceptor.class);
4747
assertEquals("no interceptors found", 2, result.size());
4848

4949
result = applicationContext.getBeansOfType(SoapActionSmartEndpointInterceptor.class);
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,21 +14,22 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.ws.server.endpoint.interceptor;
17+
package org.springframework.ws.soap.server.endpoint.interceptor;
1818

1919
import org.springframework.ws.MockWebServiceMessage;
2020
import org.springframework.ws.MockWebServiceMessageFactory;
2121
import org.springframework.ws.context.DefaultMessageContext;
2222
import org.springframework.ws.context.MessageContext;
2323
import org.springframework.ws.server.EndpointInterceptor;
24+
import org.springframework.ws.server.endpoint.interceptor.EndpointInterceptorAdapter;
2425

2526
import org.junit.Before;
2627
import org.junit.Test;
2728

2829
import static org.junit.Assert.assertFalse;
2930
import static org.junit.Assert.assertTrue;
3031

31-
public class PayloadRootSmartEndpointInterceptorTest {
32+
public class PayloadRootSmartSoapEndpointInterceptorTest {
3233

3334
private EndpointInterceptor delegate;
3435

@@ -51,34 +52,43 @@ public void setUp() {
5152

5253
@Test(expected = IllegalArgumentException.class)
5354
public void neitherNamespaceNorLocalPart() {
54-
new PayloadRootSmartEndpointInterceptor(delegate, null, null);
55+
new PayloadRootSmartSoapEndpointInterceptor(delegate, null, null);
5556
}
5657

5758
@Test
5859
public void shouldInterceptFullMatch() throws Exception {
59-
PayloadRootSmartEndpointInterceptor interceptor =
60-
new PayloadRootSmartEndpointInterceptor(delegate, namespaceUri, localPart);
60+
PayloadRootSmartSoapEndpointInterceptor interceptor =
61+
new PayloadRootSmartSoapEndpointInterceptor(delegate, namespaceUri, localPart);
6162

6263
boolean result = interceptor.shouldIntercept(messageContext, null);
6364
assertTrue("Interceptor should apply", result);
6465
}
6566

6667
@Test
6768
public void shouldInterceptFullNonMatch() throws Exception {
68-
PayloadRootSmartEndpointInterceptor interceptor =
69-
new PayloadRootSmartEndpointInterceptor(delegate, "http://springframework.org/other", localPart);
69+
PayloadRootSmartSoapEndpointInterceptor interceptor =
70+
new PayloadRootSmartSoapEndpointInterceptor(delegate, "http://springframework.org/other", localPart);
7071

7172
boolean result = interceptor.shouldIntercept(messageContext, null);
72-
assertFalse("Interceptor should apply", result);
73+
assertFalse("Interceptor should not apply", result);
7374
}
7475

7576
@Test
7677
public void shouldInterceptNamespaceUriMatch() throws Exception {
77-
PayloadRootSmartEndpointInterceptor interceptor =
78-
new PayloadRootSmartEndpointInterceptor(delegate, namespaceUri, null);
78+
PayloadRootSmartSoapEndpointInterceptor interceptor =
79+
new PayloadRootSmartSoapEndpointInterceptor(delegate, namespaceUri, null);
7980

8081
boolean result = interceptor.shouldIntercept(messageContext, null);
8182
assertTrue("Interceptor should apply", result);
8283
}
84+
85+
@Test
86+
public void shouldInterceptNamespaceUriNonMatch() throws Exception {
87+
PayloadRootSmartSoapEndpointInterceptor interceptor =
88+
new PayloadRootSmartSoapEndpointInterceptor(delegate, "http://springframework.org/other", null);
89+
90+
boolean result = interceptor.shouldIntercept(messageContext, null);
91+
assertFalse("Interceptor should not apply", result);
92+
}
8393

8494
}

0 commit comments

Comments
 (0)