Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 63279 invoked from network); 12 Apr 2011 12:29:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 12 Apr 2011 12:29:36 -0000 Received: (qmail 99724 invoked by uid 500); 12 Apr 2011 12:29:36 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 99666 invoked by uid 500); 12 Apr 2011 12:29:36 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 99659 invoked by uid 99); 12 Apr 2011 12:29:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Apr 2011 12:29:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Apr 2011 12:29:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B9D3623889B3; Tue, 12 Apr 2011 12:29:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1091384 - in /cxf/trunk/systests/ws-security/src/test: java/org/apache/cxf/systest/ws/saml/ java/org/apache/cxf/systest/ws/saml/client/ resources/org/apache/cxf/systest/ws/saml/client/ resources/wsdl_systest_wssec/saml/ Date: Tue, 12 Apr 2011 12:29:10 -0000 To: commits@cxf.apache.org From: coheigea@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110412122910.B9D3623889B3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: coheigea Date: Tue Apr 12 12:29:10 2011 New Revision: 1091384 URL: http://svn.apache.org/viewvc?rev=1091384&view=rev Log: [CXF-3432] - Added a test for the last commit. Modified: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/SamlTokenTest.java cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/client/SamlCallbackHandler.java cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/client/client.xml cxf/trunk/systests/ws-security/src/test/resources/wsdl_systest_wssec/saml/DoubleItSaml.wsdl 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=1091384&r1=1091383&r2=1091384&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 Tue Apr 12 12:29:10 2011 @@ -29,6 +29,7 @@ import javax.xml.ws.BindingProvider; import org.apache.cxf.Bus; import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler; import org.apache.cxf.systest.ws.saml.server.Server; import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; @@ -76,8 +77,7 @@ public class SamlTokenTest extends Abstr } ((BindingProvider)saml1Port).getRequestContext().put( - "ws-security.saml-callback-handler", - new org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler() + "ws-security.saml-callback-handler", new SamlCallbackHandler() ); try { saml1Port.doubleIt(BigInteger.valueOf(25)); @@ -87,8 +87,7 @@ public class SamlTokenTest extends Abstr } ((BindingProvider)saml1Port).getRequestContext().put( - "ws-security.saml-callback-handler", - new org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler(false) + "ws-security.saml-callback-handler", new SamlCallbackHandler(false) ); BigInteger result = saml1Port.doubleIt(BigInteger.valueOf(25)); assert result.equals(BigInteger.valueOf(50)); @@ -110,7 +109,7 @@ public class SamlTokenTest extends Abstr DoubleItService service = new DoubleItService(); DoubleItPortType saml2Port = service.getDoubleItSaml2SymmetricPort(); - + try { saml2Port.doubleIt(BigInteger.valueOf(25)); fail("Expected failure on an invocation with no SAML Assertion"); @@ -119,8 +118,7 @@ public class SamlTokenTest extends Abstr } ((BindingProvider)saml2Port).getRequestContext().put( - "ws-security.saml-callback-handler", - new org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler(false) + "ws-security.saml-callback-handler", new SamlCallbackHandler(false) ); try { saml2Port.doubleIt(BigInteger.valueOf(25)); @@ -130,12 +128,45 @@ public class SamlTokenTest extends Abstr } ((BindingProvider)saml2Port).getRequestContext().put( - "ws-security.saml-callback-handler", - new org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler() + "ws-security.saml-callback-handler", new SamlCallbackHandler() ); BigInteger result = saml2Port.doubleIt(BigInteger.valueOf(25)); assert result.equals(BigInteger.valueOf(50)); } + + /** + * Some negative tests. Send a sender-vouches assertion as a SupportingToken...this will + * fail as the provider will demand that there is a signature covering both the assertion + * and the message body. + */ + @org.junit.Test + public void testSaml2OverSymmetricSupporting() throws Exception { + + if (!unrestrictedPoliciesInstalled) { + return; + } + SpringBusFactory bf = new SpringBusFactory(); + URL busFile = SamlTokenTest.class.getResource("client/client.xml"); + + Bus bus = bf.createBus(busFile.toString()); + SpringBusFactory.setDefaultBus(bus); + SpringBusFactory.setThreadDefaultBus(bus); + + DoubleItService service = new DoubleItService(); + + DoubleItPortType saml2Port = service.getDoubleItSaml2SymmetricSupportingPort(); + + ((BindingProvider)saml2Port).getRequestContext().put( + "ws-security.saml-callback-handler", new SamlCallbackHandler() + ); + + try { + saml2Port.doubleIt(BigInteger.valueOf(25)); + fail("Expected failure on an invocation with an unsigned SAML SV Assertion"); + } catch (javax.xml.ws.soap.SOAPFaultException ex) { + assert ex.getMessage().contains("Assertion fails sender-vouches requirements"); + } + } @org.junit.Test public void testSaml2OverAsymmetric() throws Exception { @@ -163,8 +194,7 @@ public class SamlTokenTest extends Abstr } ((BindingProvider)saml2Port).getRequestContext().put( - "ws-security.saml-callback-handler", - new org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler(false) + "ws-security.saml-callback-handler", new SamlCallbackHandler(false) ); try { saml2Port.doubleIt(BigInteger.valueOf(25)); @@ -174,8 +204,7 @@ public class SamlTokenTest extends Abstr } ((BindingProvider)saml2Port).getRequestContext().put( - "ws-security.saml-callback-handler", - new org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler() + "ws-security.saml-callback-handler", new SamlCallbackHandler() ); BigInteger result = saml2Port.doubleIt(BigInteger.valueOf(25)); assert result.equals(BigInteger.valueOf(50)); @@ -196,8 +225,7 @@ public class SamlTokenTest extends Abstr DoubleItPortType saml1Port = service.getDoubleItSaml1SelfSignedTransportPort(); ((BindingProvider)saml1Port).getRequestContext().put( - "ws-security.saml-callback-handler", - new org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler(false) + "ws-security.saml-callback-handler", new SamlCallbackHandler(false) ); BigInteger result = saml1Port.doubleIt(BigInteger.valueOf(25)); assert result.equals(BigInteger.valueOf(50)); @@ -222,8 +250,7 @@ public class SamlTokenTest extends Abstr DoubleItPortType saml2Port = service.getDoubleItSaml2SymmetricProtectionPort(); ((BindingProvider)saml2Port).getRequestContext().put( - "ws-security.saml-callback-handler", - new org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler() + "ws-security.saml-callback-handler", new SamlCallbackHandler() ); BigInteger result = saml2Port.doubleIt(BigInteger.valueOf(25)); assert result.equals(BigInteger.valueOf(50)); Modified: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/client/SamlCallbackHandler.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/client/SamlCallbackHandler.java?rev=1091384&r1=1091383&r2=1091384&view=diff ============================================================================== --- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/client/SamlCallbackHandler.java (original) +++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/client/SamlCallbackHandler.java Tue Apr 12 12:29:10 2011 @@ -39,6 +39,7 @@ import org.opensaml.common.SAMLVersion; */ public class SamlCallbackHandler implements CallbackHandler { private boolean saml2 = true; + private String confirmationMethod = SAML2Constants.CONF_SENDER_VOUCHES; public SamlCallbackHandler() { // @@ -48,6 +49,10 @@ public class SamlCallbackHandler impleme this.saml2 = saml2; } + public void setConfirmationMethod(String confirmationMethod) { + this.confirmationMethod = confirmationMethod; + } + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof SAMLCallback) { @@ -60,8 +65,7 @@ public class SamlCallbackHandler impleme callback.setIssuer("sts"); String subjectName = "uid=sts-client,o=mock-sts.com"; String subjectQualifier = "www.mock-sts.com"; - String confirmationMethod = SAML2Constants.CONF_SENDER_VOUCHES; - if (!saml2) { + if (!saml2 && SAML2Constants.CONF_SENDER_VOUCHES.equals(confirmationMethod)) { confirmationMethod = SAML1Constants.CONF_SENDER_VOUCHES; } SubjectBean subjectBean = Modified: cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/client/client.xml URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/client/client.xml?rev=1091384&r1=1091383&r2=1091384&view=diff ============================================================================== --- cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/client/client.xml (original) +++ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/saml/client/client.xml Tue Apr 12 12:29:10 2011 @@ -59,9 +59,20 @@ value="org/apache/cxf/systest/ws/wssec10/client/bob.properties"/> - + + + + + + + + + - @@ -73,9 +84,9 @@ - + - - + - - + Modified: cxf/trunk/systests/ws-security/src/test/resources/wsdl_systest_wssec/saml/DoubleItSaml.wsdl URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/wsdl_systest_wssec/saml/DoubleItSaml.wsdl?rev=1091384&r1=1091383&r2=1091384&view=diff ============================================================================== --- cxf/trunk/systests/ws-security/src/test/resources/wsdl_systest_wssec/saml/DoubleItSaml.wsdl (original) +++ cxf/trunk/systests/ws-security/src/test/resources/wsdl_systest_wssec/saml/DoubleItSaml.wsdl Tue Apr 12 12:29:10 2011 @@ -129,6 +129,25 @@ + + + + + + + + + + + + + + + + + + + + + @@ -310,6 +333,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +