Author: coheigea
Date: Fri Jan 31 16:30:43 2014
New Revision: 1563168
URL: http://svn.apache.org/r1563168
Log:
Fixed an infinite loop caused by certain streaming action combinations for
WS-Security + partial test
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractStaxBindingHandler.java
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxAsymmetricBindingHandler.java
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/SamlTokenTest.java
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/DoubleItSaml.wsdl
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/client.xml
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/server.xml
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/stax-server.xml
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractStaxBindingHandler.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractStaxBindingHandler.java?rev=1563168&r1=1563167&r2=1563168&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractStaxBindingHandler.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractStaxBindingHandler.java
Fri Jan 31 16:30:43 2014
@@ -1004,4 +1004,27 @@ public abstract class AbstractStaxBindin
}
return null;
}
+
+ // Signature + Signed SAML Token actions are not allowed together
+ protected void removeSignatureIfSignedSAML() {
+ if (properties.getActions() != null) {
+ List<WSSConstants.Action> actionList = properties.getActions();
+ if (actionList.contains(WSSConstants.SAML_TOKEN_SIGNED)
+ && actionList.contains(WSSConstants.SIGNATURE)) {
+ actionList.remove(WSSConstants.SIGNATURE);
+ }
+ }
+ }
+
+ // If we have EncryptBeforeSigning, then we want to have the Signature
component after
+ // the Encrypt action, which is not the case if we have a Signed SAML
Supporting Token
+ protected void enforceEncryptBeforeSigningWithSignedSAML() {
+ if (properties.getActions() != null) {
+ List<WSSConstants.Action> actionList = properties.getActions();
+ if (actionList.contains(WSSConstants.SAML_TOKEN_SIGNED)) {
+ actionList.remove(WSSConstants.SAML_TOKEN_SIGNED);
+ actionList.add(WSSConstants.SAML_TOKEN_SIGNED);
+ }
+ }
+ }
}
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxAsymmetricBindingHandler.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxAsymmetricBindingHandler.java?rev=1563168&r1=1563167&r2=1563168&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxAsymmetricBindingHandler.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxAsymmetricBindingHandler.java
Fri Jan 31 16:30:43 2014
@@ -177,15 +177,7 @@ public class StaxAsymmetricBindingHandle
}
addSupportingTokens();
-
- WSSSecurityProperties properties = getProperties();
- if (properties.getActions() != null) {
- List<WSSConstants.Action> actionList = properties.getActions();
- if (actionList.contains(WSSConstants.SAML_TOKEN_SIGNED)
- && actionList.contains(WSSConstants.SIGNATURE)) {
- actionList.remove(WSSConstants.SIGNATURE);
- }
- }
+ removeSignatureIfSignedSAML();
List<SecurePart> enc = getEncryptedParts();
@@ -225,6 +217,7 @@ public class StaxAsymmetricBindingHandle
// Reshuffle so that a IssuedToken is above a Signature that
references it
if (customTokenAdded) {
+ WSSSecurityProperties properties = getProperties();
properties.getActions().remove(WSSConstants.CUSTOM_TOKEN);
properties.getActions().add(WSSConstants.CUSTOM_TOKEN);
}
@@ -347,6 +340,9 @@ public class StaxAsymmetricBindingHandle
}
}
+ removeSignatureIfSignedSAML();
+ enforceEncryptBeforeSigningWithSignedSAML();
+
// Reshuffle so that a IssuedToken is above a Signature that
references it
if (customTokenAdded) {
getProperties().getActions().remove(WSSConstants.CUSTOM_TOKEN);
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java?rev=1563168&r1=1563167&r2=1563168&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java
Fri Jan 31 16:30:43 2014
@@ -270,6 +270,9 @@ public class StaxSymmetricBindingHandler
}
}
+ removeSignatureIfSignedSAML();
+ enforceEncryptBeforeSigningWithSignedSAML();
+
// Reshuffle so that a IssuedToken is above a Signature that
references it
if (customTokenAdded) {
getProperties().getActions().remove(WSSConstants.CUSTOM_TOKEN);
@@ -373,15 +376,7 @@ public class StaxSymmetricBindingHandler
}
addSupportingTokens();
-
- WSSSecurityProperties properties = getProperties();
- if (isRequestor() && properties.getActions() != null) {
- List<WSSConstants.Action> actionList = properties.getActions();
- if (actionList.contains(WSSConstants.SAML_TOKEN_SIGNED)
- && actionList.contains(WSSConstants.SIGNATURE)) {
- actionList.remove(WSSConstants.SIGNATURE);
- }
- }
+ removeSignatureIfSignedSAML();
//Encryption
List<SecurePart> enc = getEncryptedParts();
Modified:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/SamlTokenTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/SamlTokenTest.java?rev=1563168&r1=1563167&r2=1563168&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/SamlTokenTest.java
(original)
+++
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/SamlTokenTest.java
Fri Jan 31 16:30:43 2014
@@ -738,6 +738,41 @@ public class SamlTokenTest extends Abstr
}
@org.junit.Test
+ public void testSaml2OverAsymmetricSignedEncryptedEncryptBeforeSigning()
throws Exception {
+
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = SamlTokenTest.class.getResource("client.xml");
+
+ Bus bus = bf.createBus(busFile.toString());
+ SpringBusFactory.setDefaultBus(bus);
+ SpringBusFactory.setThreadDefaultBus(bus);
+
+ URL wsdl = SamlTokenTest.class.getResource("DoubleItSaml.wsdl");
+ Service service = Service.create(wsdl, SERVICE_QNAME);
+ QName portQName =
+ new QName(NAMESPACE,
"DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigningPort");
+ DoubleItPortType saml2Port =
+ service.getPort(portQName, DoubleItPortType.class);
+ updateAddressPort(saml2Port, test.getPort());
+
+ if (test.isStreaming()) {
+ SecurityTestUtil.enableStreaming(saml2Port);
+ }
+
+ // TODO Only working for DOM client + server atm
+ if (!test.isStreaming() && PORT.equals(test.getPort())) {
+ ((BindingProvider)saml2Port).getRequestContext().put(
+ "ws-security.saml-callback-handler", new SamlCallbackHandler()
+ );
+ int result = saml2Port.doubleIt(25);
+ assertTrue(result == 50);
+ }
+
+ ((java.io.Closeable)saml2Port).close();
+ bus.shutdown(true);
+ }
+
+ @org.junit.Test
public void testSaml2OverAsymmetricEncrypted() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
@@ -960,4 +995,5 @@ public class SamlTokenTest extends Abstr
((java.io.Closeable)saml2Port).close();
bus.shutdown(true);
}
+
}
Modified:
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/DoubleItSaml.wsdl
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/DoubleItSaml.wsdl?rev=1563168&r1=1563167&r2=1563168&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/DoubleItSaml.wsdl
(original)
+++
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/DoubleItSaml.wsdl
Fri Jan 31 16:30:43 2014
@@ -233,6 +233,24 @@
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
+ <wsdl:binding
name="DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigningBinding"
type="tns:DoubleItPortType">
+ <wsp:PolicyReference
URI="#DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigningPolicy"/>
+ <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="DoubleIt">
+ <soap:operation soapAction=""/>
+ <wsdl:input>
+ <soap:body use="literal"/>
+ <wsp:PolicyReference
URI="#DoubleItBinding_DoubleIt_Input_Policy"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal"/>
+ <wsp:PolicyReference
URI="#DoubleItBinding_DoubleIt_Output_Policy"/>
+ </wsdl:output>
+ <wsdl:fault name="DoubleItFault">
+ <soap:body use="literal" name="DoubleItFault"/>
+ </wsdl:fault>
+ </wsdl:operation>
+ </wsdl:binding>
<wsdl:binding name="DoubleItSaml2AsymmetricEncryptedBinding"
type="tns:DoubleItPortType">
<wsp:PolicyReference URI="#DoubleItSaml2AsymmetricEncryptedPolicy"/>
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
@@ -343,6 +361,10 @@
<wsdl:port name="DoubleItSaml2AsymmetricSignedEncryptedPort"
binding="tns:DoubleItSaml2AsymmetricSignedEncryptedBinding">
<soap:address
location="http://localhost:9001/DoubleItSaml2AsymmetricSignedEncrypted"/>
</wsdl:port>
+ <wsdl:port
name="DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigningPort"
+
binding="tns:DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigningBinding">
+ <soap:address
location="http://localhost:9001/DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigning"/>
+ </wsdl:port>
<wsdl:port name="DoubleItSaml2AsymmetricEncryptedPort"
binding="tns:DoubleItSaml2AsymmetricEncryptedBinding">
<soap:address
location="http://localhost:9001/DoubleItSaml2AsymmetricEncrypted"/>
</wsdl:port>
@@ -871,6 +893,63 @@
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
+ <wsp:Policy
wsu:Id="DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigningPolicy">
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:AsymmetricBinding>
+ <wsp:Policy>
+ <sp:InitiatorToken>
+ <wsp:Policy>
+ <sp:X509Token
sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
+ <wsp:Policy>
+ <sp:WssX509V3Token10/>
+ </wsp:Policy>
+ </sp:X509Token>
+ </wsp:Policy>
+ </sp:InitiatorToken>
+ <sp:RecipientToken>
+ <wsp:Policy>
+ <sp:X509Token
sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToInitiator">
+ <wsp:Policy>
+ <sp:WssX509V3Token10/>
+ </wsp:Policy>
+ </sp:X509Token>
+ </wsp:Policy>
+ </sp:RecipientToken>
+ <sp:Layout>
+ <wsp:Policy>
+ <sp:Lax/>
+ </wsp:Policy>
+ </sp:Layout>
+ <sp:IncludeTimestamp/>
+ <sp:OnlySignEntireHeadersAndBody/>
+ <sp:EncryptBeforeSigning/>
+ <sp:AlgorithmSuite>
+ <wsp:Policy>
+ <sp:Basic128/>
+ </wsp:Policy>
+ </sp:AlgorithmSuite>
+ </wsp:Policy>
+ </sp:AsymmetricBinding>
+ <sp:Wss11>
+ <wsp:Policy>
+ <sp:MustSupportRefIssuerSerial/>
+ <sp:MustSupportRefThumbprint/>
+ <sp:MustSupportRefEncryptedKey/>
+ </wsp:Policy>
+ </sp:Wss11>
+ <sp:SignedEncryptedSupportingTokens>
+ <wsp:Policy>
+ <sp:SamlToken
sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
+ <wsp:Policy>
+ <sp:WssSamlV20Token11/>
+ </wsp:Policy>
+ </sp:SamlToken>
+ </wsp:Policy>
+ </sp:SignedEncryptedSupportingTokens>
+ </wsp:All>
+ </wsp:ExactlyOne>
+ </wsp:Policy>
<wsp:Policy wsu:Id="DoubleItSaml2AsymmetricEncryptedPolicy">
<wsp:ExactlyOne>
<wsp:All>
Modified:
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/client.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/client.xml?rev=1563168&r1=1563167&r2=1563168&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/client.xml
(original)
+++
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/client.xml
Fri Jan 31 16:30:43 2014
@@ -129,6 +129,15 @@
<entry key="ws-security.signature.username" value="alice"/>
</jaxws:properties>
</jaxws:client>
+ <jaxws:client
name="{http://www.example.org/contract/DoubleIt}DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigningPort"
createdFromAPI="true">
+ <jaxws:properties>
+ <entry key="ws-security.callback-handler"
value="org.apache.cxf.systest.ws.common.KeystorePasswordCallback"/>
+ <entry key="ws-security.encryption.properties"
value="bob.properties"/>
+ <entry key="ws-security.encryption.username" value="bob"/>
+ <entry key="ws-security.signature.properties"
value="alice.properties"/>
+ <entry key="ws-security.signature.username" value="alice"/>
+ </jaxws:properties>
+ </jaxws:client>
<jaxws:client
name="{http://www.example.org/contract/DoubleIt}DoubleItSaml2AsymmetricEncryptedPort"
createdFromAPI="true">
<jaxws:properties>
<entry key="ws-security.callback-handler"
value="org.apache.cxf.systest.ws.common.KeystorePasswordCallback"/>
Modified:
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/server.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/server.xml?rev=1563168&r1=1563167&r2=1563168&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/server.xml
(original)
+++
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/server.xml
Fri Jan 31 16:30:43 2014
@@ -157,6 +157,16 @@
<entry key="ws-security.saml2.validator"
value="org.apache.cxf.systest.ws.saml.CustomSaml2Validator"/>
</jaxws:properties>
</jaxws:endpoint>
+ <jaxws:endpoint xmlns:s="http://www.example.org/contract/DoubleIt"
id="Saml2TokenOverAsymmetricSignedEncryptedEncryptBeforeSigning"
address="http://localhost:${testutil.ports.Server}/DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigning"
serviceName="s:DoubleItService"
endpointName="s:DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigningPort"
implementor="org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl"
wsdlLocation="org/apache/cxf/systest/ws/saml/DoubleItSaml.wsdl">
+ <jaxws:properties>
+ <entry key="ws-security.username" value="bob"/>
+ <entry key="ws-security.callback-handler"
value="org.apache.cxf.systest.ws.common.KeystorePasswordCallback"/>
+ <entry key="ws-security.signature.properties"
value="bob.properties"/>
+ <entry key="ws-security.encryption.username"
value="useReqSigCert"/>
+ <entry key="ws-security.subject.cert.constraints"
value=".*O=apache.org.*"/>
+ <entry key="ws-security.saml2.validator"
value="org.apache.cxf.systest.ws.saml.CustomSaml2Validator"/>
+ </jaxws:properties>
+ </jaxws:endpoint>
<jaxws:endpoint xmlns:s="http://www.example.org/contract/DoubleIt"
id="Saml2TokenOverAsymmetricEncrypted"
address="http://localhost:${testutil.ports.Server}/DoubleItSaml2AsymmetricEncrypted"
serviceName="s:DoubleItService"
endpointName="s:DoubleItSaml2AsymmetricEncryptedPort"
implementor="org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl"
wsdlLocation="org/apache/cxf/systest/ws/saml/DoubleItSaml.wsdl">
<jaxws:properties>
<entry key="ws-security.username" value="bob"/>
Modified:
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/stax-server.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/stax-server.xml?rev=1563168&r1=1563167&r2=1563168&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/stax-server.xml
(original)
+++
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/stax-server.xml
Fri Jan 31 16:30:43 2014
@@ -175,6 +175,18 @@
<entry key="ws-security.enable.streaming" value="true"/>
</jaxws:properties>
</jaxws:endpoint>
+ <jaxws:endpoint xmlns:s="http://www.example.org/contract/DoubleIt"
id="Saml2TokenOverAsymmetricSignedEncryptedEncryptBeforeSigning"
address="http://localhost:${testutil.ports.StaxServer}/DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigning"
serviceName="s:DoubleItService"
endpointName="s:DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigningPort"
implementor="org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl"
wsdlLocation="org/apache/cxf/systest/ws/saml/DoubleItSaml.wsdl">
+ <jaxws:properties>
+ <entry key="ws-security.username" value="bob"/>
+ <entry key="ws-security.callback-handler"
value="org.apache.cxf.systest.ws.common.KeystorePasswordCallback"/>
+ <entry key="ws-security.signature.properties"
value="bob.properties"/>
+ <entry key="ws-security.encryption.username"
value="useReqSigCert"/>
+ <entry key="ws-security.subject.cert.constraints"
value=".*O=apache.org.*"/>
+ <!--<entry key="ws-security.saml2.validator"
+
value="org.apache.cxf.systest.ws.saml.CustomSaml2Validator"/>-->
+ <entry key="ws-security.enable.streaming" value="true"/>
+ </jaxws:properties>
+ </jaxws:endpoint>
<jaxws:endpoint xmlns:s="http://www.example.org/contract/DoubleIt"
id="Saml2TokenOverAsymmetricEncrypted"
address="http://localhost:${testutil.ports.StaxServer}/DoubleItSaml2AsymmetricEncrypted"
serviceName="s:DoubleItService"
endpointName="s:DoubleItSaml2AsymmetricEncryptedPort"
implementor="org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl"
wsdlLocation="org/apache/cxf/systest/ws/saml/DoubleItSaml.wsdl">
<jaxws:properties>
<entry key="ws-security.username" value="bob"/>