Author: coheigea
Date: Tue Aug 13 13:57:39 2013
New Revision: 1513496
URL: http://svn.apache.org/r1513496
Log:
[CXF-5199] - Using an EncryptBeforeSigning policy with no
EncryptedParts/Elements results in no Signature in the request
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AsymmetricBindingHandler.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/X509TokenTest.java
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/DoubleItX509.wsdl
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/client.xml
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/server.xml
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AsymmetricBindingHandler.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AsymmetricBindingHandler.java?rev=1513496&r1=1513495&r2=1513496&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AsymmetricBindingHandler.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AsymmetricBindingHandler.java
Tue Aug 13 13:57:39 2013
@@ -273,31 +273,35 @@ public class AsymmetricBindingHandler ex
//REVISIT - no token to encrypt with
//}
+ WSSecBase encrBase = null;
if (encryptionToken != null && encrParts.size() > 0) {
- WSSecBase encrBase = doEncryption(wrapper, encrParts, true);
+ encrBase = doEncryption(wrapper, encrParts, true);
handleEncryptedSignedHeaders(encrParts, sigParts);
-
- if (timestampEl != null) {
- WSEncryptionPart timestampPart =
- convertToEncryptionPart(timestampEl.getElement());
- sigParts.add(timestampPart);
- }
-
- if (isRequestor()) {
- try {
- addSupportingTokens(sigParts);
- } catch (WSSecurityException ex) {
- policyNotAsserted(encryptionToken, ex);
- }
- } else {
- addSignatureConfirmation(sigParts);
- }
-
+ }
+
+ if (timestampEl != null) {
+ WSEncryptionPart timestampPart =
+ convertToEncryptionPart(timestampEl.getElement());
+ sigParts.add(timestampPart);
+ }
+
+ if (isRequestor()) {
try {
- if ((sigParts.size() > 0) && initiatorWrapper != null &&
isRequestor()) {
+ addSupportingTokens(sigParts);
+ } catch (WSSecurityException ex) {
+ policyNotAsserted(encryptionToken, ex);
+ }
+ } else {
+ addSignatureConfirmation(sigParts);
+ }
+
+ try {
+ if (sigParts.size() > 0) {
+ if (initiatorWrapper != null && isRequestor()) {
doSignature(initiatorWrapper, sigParts, attached);
} else if (!isRequestor()) {
- AbstractTokenWrapper recipientSignatureToken =
abinding.getRecipientSignatureToken();
+ AbstractTokenWrapper recipientSignatureToken =
+ abinding.getRecipientSignatureToken();
if (recipientSignatureToken == null) {
recipientSignatureToken =
abinding.getRecipientToken();
}
@@ -305,16 +309,18 @@ public class AsymmetricBindingHandler ex
doSignature(recipientSignatureToken, sigParts,
attached);
}
}
- } catch (WSSecurityException ex) {
- throw new Fault(ex);
- } catch (SOAPException ex) {
- throw new Fault(ex);
}
+ } catch (WSSecurityException ex) {
+ throw new Fault(ex);
+ } catch (SOAPException ex) {
+ throw new Fault(ex);
+ }
- if (isRequestor()) {
- doEndorse();
- }
-
+ if (isRequestor()) {
+ doEndorse();
+ }
+
+ if (encrBase != null) {
encryptTokensInSecurityHeader(encryptionToken, encrBase);
}
}
Modified:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/X509TokenTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/X509TokenTest.java?rev=1513496&r1=1513495&r2=1513496&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/X509TokenTest.java
(original)
+++
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/X509TokenTest.java
Tue Aug 13 13:57:39 2013
@@ -412,6 +412,34 @@ public class X509TokenTest extends Abstr
}
@org.junit.Test
+ public void testAsymmetricEncryptBeforeSigningNoEnc() throws Exception {
+
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = X509TokenTest.class.getResource("client.xml");
+
+ Bus bus = bf.createBus(busFile.toString());
+ SpringBusFactory.setDefaultBus(bus);
+ SpringBusFactory.setThreadDefaultBus(bus);
+
+ URL wsdl = X509TokenTest.class.getResource("DoubleItX509.wsdl");
+ Service service = Service.create(wsdl, SERVICE_QNAME);
+ QName portQName = new QName(NAMESPACE,
"DoubleItAsymmetricEncryptBeforeSigningNoEncPort");
+ DoubleItPortType x509Port =
+ service.getPort(portQName, DoubleItPortType.class);
+ updateAddressPort(x509Port, PORT);
+
+ // DOM
+ x509Port.doubleIt(25);
+
+ // TODO Streaming
+ // SecurityTestUtil.enableStreaming(x509Port);
+ // x509Port.doubleIt(25);
+
+ ((java.io.Closeable)x509Port).close();
+ bus.shutdown(true);
+ }
+
+ @org.junit.Test
public void testAsymmetricEncryptSignature() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
Modified:
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/DoubleItX509.wsdl
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/DoubleItX509.wsdl?rev=1513496&r1=1513495&r2=1513496&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/DoubleItX509.wsdl
(original)
+++
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/DoubleItX509.wsdl
Tue Aug 13 13:57:39 2013
@@ -220,6 +220,25 @@
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
+ <wsdl:binding name="DoubleItAsymmetricEncryptBeforeSigningNoEncBinding"
type="tns:DoubleItPortType">
+ <wsp:PolicyReference
URI="#DoubleItAsymmetricEncryptBeforeSigningPolicy" />
+ <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_NoEnc_Policy"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal" />
+ <wsp:PolicyReference
URI="#DoubleItBinding_DoubleIt_NoEnc_Policy"/>
+ </wsdl:output>
+ <wsdl:fault name="DoubleItFault">
+ <soap:body use="literal" name="DoubleItFault" />
+ </wsdl:fault>
+ </wsdl:operation>
+ </wsdl:binding>
<wsdl:binding name="DoubleItAsymmetricEncryptSignatureBinding"
type="tns:DoubleItPortType">
<wsp:PolicyReference URI="#DoubleItAsymmetricEncryptSignaturePolicy" />
<soap:binding style="document"
@@ -480,6 +499,10 @@
binding="tns:DoubleItAsymmetricEncryptBeforeSigningBinding">
<soap:address
location="http://localhost:9001/DoubleItX509AsymmetricEncryptBeforeSigning" />
</wsdl:port>
+ <wsdl:port name="DoubleItAsymmetricEncryptBeforeSigningNoEncPort"
+
binding="tns:DoubleItAsymmetricEncryptBeforeSigningNoEncBinding">
+ <soap:address
location="http://localhost:9001/DoubleItX509AsymmetricEncryptBeforeSigningNoEnc"
/>
+ </wsdl:port>
<wsdl:port name="DoubleItAsymmetricEncryptSignaturePort"
binding="tns:DoubleItAsymmetricEncryptSignatureBinding">
<soap:address
location="http://localhost:9001/DoubleItX509AsymmetricEncryptSignature" />
@@ -1381,6 +1404,15 @@
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
+ <wsp:Policy wsu:Id="DoubleItBinding_DoubleIt_NoEnc_Policy">
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:SignedParts>
+ <sp:Body/>
+ </sp:SignedParts>
+ </wsp:All>
+ </wsp:ExactlyOne>
+ </wsp:Policy>
<wsp:Policy wsu:Id="DoubleItBinding_DoubleIt_Output_Policy">
<wsp:ExactlyOne>
<wsp:All>
Modified:
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/client.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/client.xml?rev=1513496&r1=1513495&r2=1513496&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/client.xml
(original)
+++
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/client.xml
Tue Aug 13 13:57:39 2013
@@ -139,6 +139,18 @@
</jaxws:properties>
</jaxws:client>
+ <jaxws:client
name="{http://www.example.org/contract/DoubleIt}DoubleItAsymmetricEncryptBeforeSigningNoEncPort"
+ createdFromAPI="true">
+ <jaxws:properties>
+ <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"/>
+ <entry key="ws-security.callback-handler"
+
value="org.apache.cxf.systest.ws.common.KeystorePasswordCallback"/>
+ </jaxws:properties>
+ </jaxws:client>
+
<jaxws:client
name="{http://www.example.org/contract/DoubleIt}DoubleItAsymmetricEncryptSignaturePort"
createdFromAPI="true">
<jaxws:properties>
Modified:
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/server.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/server.xml?rev=1513496&r1=1513495&r2=1513496&view=diff
==============================================================================
---
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/server.xml
(original)
+++
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/x509/server.xml
Tue Aug 13 13:57:39 2013
@@ -270,6 +270,25 @@
</jaxws:endpoint>
<jaxws:endpoint
+ id="AsymmetricEncryptBeforeSigningNoEnc"
+
address="http://localhost:${testutil.ports.Server}/DoubleItX509AsymmetricEncryptBeforeSigningNoEnc"
+ serviceName="s:DoubleItService"
+ endpointName="s:DoubleItAsymmetricEncryptBeforeSigningNoEncPort"
+ xmlns:s="http://www.example.org/contract/DoubleIt"
+ implementor="org.apache.cxf.systest.ws.common.DoubleItImpl"
+ wsdlLocation="org/apache/cxf/systest/ws/x509/DoubleItX509.wsdl">
+
+ <jaxws:properties>
+ <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.*"/>
+ </jaxws:properties>
+
+ </jaxws:endpoint>
+
+ <jaxws:endpoint
id="AsymmetricEncryptSignature"
address="http://localhost:${testutil.ports.Server}/DoubleItX509AsymmetricEncryptSignature"
serviceName="s:DoubleItService"