cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1450436 - in /cxf/branches/2.7.x-fixes/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml: SamlTokenTest.java client/SamlElementCallbackHandler.java
Date Tue, 26 Feb 2013 21:31:09 GMT
Author: coheigea
Date: Tue Feb 26 21:31:09 2013
New Revision: 1450436

URL: http://svn.apache.org/r1450436
Log:
Merged revisions 1450433 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1450433 | coheigea | 2013-02-26 13:27:36 -0800 (Tue, 26 Feb 2013) | 2 lines

  Adding a test that uses a SAML CallbackHandler to set a DOM Element directly on a SAMLCallback

........

Added:
    cxf/branches/2.7.x-fixes/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/client/SamlElementCallbackHandler.java
Modified:
    cxf/branches/2.7.x-fixes/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/SamlTokenTest.java

Modified: cxf/branches/2.7.x-fixes/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/SamlTokenTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/SamlTokenTest.java?rev=1450436&r1=1450435&r2=1450436&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/SamlTokenTest.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/SamlTokenTest.java
Tue Feb 26 21:31:09 2013
@@ -29,6 +29,7 @@ import org.apache.cxf.Bus;
 import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.systest.ws.common.SecurityTestUtil;
 import org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler;
+import org.apache.cxf.systest.ws.saml.client.SamlElementCallbackHandler;
 import org.apache.cxf.systest.ws.saml.client.SamlRoleCallbackHandler;
 import org.apache.cxf.systest.ws.saml.server.Server;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -108,6 +109,40 @@ public class SamlTokenTest extends Abstr
     }
     
     @org.junit.Test
+    public void testSaml1ElementOverTransport() throws Exception {
+
+        SpringBusFactory bf = new SpringBusFactory();
+        URL busFile = SamlTokenTest.class.getResource("client/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, "DoubleItSaml1TransportPort");
+        DoubleItPortType saml1Port = 
+                service.getPort(portQName, DoubleItPortType.class);
+        updateAddressPort(saml1Port, PORT2);
+        
+        try {
+            saml1Port.doubleIt(25);
+            fail("Expected failure on an invocation with no SAML Assertion");
+        } catch (javax.xml.ws.soap.SOAPFaultException ex) {
+            assertTrue(ex.getMessage().contains("No SAML CallbackHandler available"));
+        }
+        
+        ((BindingProvider)saml1Port).getRequestContext().put(
+            "ws-security.saml-callback-handler", new SamlElementCallbackHandler(false)
+        );
+        int result = saml1Port.doubleIt(25);
+        assertTrue(result == 50);
+        
+        ((java.io.Closeable)saml1Port).close();
+        bus.shutdown(true);
+    }
+    
+    @org.junit.Test
     public void testSaml2OverSymmetric() throws Exception {
 
         SpringBusFactory bf = new SpringBusFactory();
@@ -611,5 +646,4 @@ public class SamlTokenTest extends Abstr
         bus.shutdown(true);
     }
     
-    
 }

Added: cxf/branches/2.7.x-fixes/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/client/SamlElementCallbackHandler.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/client/SamlElementCallbackHandler.java?rev=1450436&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/client/SamlElementCallbackHandler.java
(added)
+++ cxf/branches/2.7.x-fixes/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/saml/client/SamlElementCallbackHandler.java
Tue Feb 26 21:31:09 2013
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.cxf.systest.ws.saml.client;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.ws.security.saml.ext.AssertionWrapper;
+import org.apache.ws.security.saml.ext.SAMLCallback;
+import org.apache.ws.security.saml.ext.SAMLParms;
+
+/**
+ * A CallbackHandler instance that is used by the STS to mock up a SAML Attribute Assertion.
This
+ * particular CallbackHandler creates the SAML Assertion by delegating it to the standard
+ * SamlCallbackHandler, and then just sets it on the SAMLCallback as a DOM Element. Essentially,
+ * this is a test that it's possible to set a DOM Element on the SAMLCallback and have it
included
+ * in the request.
+ */
+public class SamlElementCallbackHandler implements CallbackHandler {
+    private boolean saml2 = true;
+    
+    public SamlElementCallbackHandler() {
+        //
+    }
+    
+    public SamlElementCallbackHandler(boolean saml2) {
+        this.saml2 = saml2;
+    }
+    
+    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
{
+        for (int i = 0; i < callbacks.length; i++) {
+            if (callbacks[i] instanceof SAMLCallback) {
+                SAMLCallback callback = (SAMLCallback) callbacks[i];
+                Element assertionElement;
+                try {
+                    Document doc = DOMUtils.createDocument();
+                    assertionElement = getSAMLAssertion(doc);
+                } catch (Exception e) {
+                    throw new IOException(e.getMessage());
+                }
+                callback.setAssertionElement(assertionElement);
+            }
+        }
+    }
+    
+    /**
+     * Mock up a SAML Assertion by using another SAMLCallbackHandler
+     * @throws Exception 
+     */
+    private Element getSAMLAssertion(Document doc) throws Exception {
+        SAMLParms parms = new SAMLParms();
+        SamlCallbackHandler callbackHandler = new SamlCallbackHandler(saml2);
+        parms.setCallbackHandler(callbackHandler);
+        AssertionWrapper assertionWrapper = new AssertionWrapper(parms);
+
+        return assertionWrapper.toDOM(doc);
+    }
+
+    
+}



Mime
View raw message