cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r821964 - in /cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j: TestPwdCallback.java WSS4JInOutTest.java
Date Mon, 05 Oct 2009 19:01:28 GMT
Author: dkulp
Date: Mon Oct  5 19:01:27 2009
New Revision: 821964

URL: http://svn.apache.org/viewvc?rev=821964&view=rev
Log:
[CXF-1970] Add unit test sfor UserNameToken
Patch from Colm O hEigeartaigh applied

Modified:
    cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/TestPwdCallback.java
    cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JInOutTest.java

Modified: cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/TestPwdCallback.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/TestPwdCallback.java?rev=821964&r1=821963&r2=821964&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/TestPwdCallback.java
(original)
+++ cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/TestPwdCallback.java
Mon Oct  5 19:01:27 2009
@@ -34,6 +34,7 @@
 
     static {
         passwords.put("myalias", "myAliasPassword");
+        passwords.put("alice", "alicePassword");
     }
 
     public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
{

Modified: cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JInOutTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JInOutTest.java?rev=821964&r1=821963&r2=821964&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JInOutTest.java
(original)
+++ cxf/trunk/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JInOutTest.java
Mon Oct  5 19:01:27 2009
@@ -311,6 +311,95 @@
     }
     
     @Test
+    @SuppressWarnings("unchecked")
+    public void testEncryptedUsernameToken() throws Exception {
+        Document doc = readDocument("wsse-request-clean.xml");
+
+        WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
+        PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();
+
+        SoapMessage msg = new SoapMessage(new MessageImpl());
+        Exchange ex = new ExchangeImpl();
+        ex.setInMessage(msg);
+        
+        SOAPMessage saajMsg = MessageFactory.newInstance().createMessage();
+        SOAPPart part = saajMsg.getSOAPPart();
+        part.setContent(new DOMSource(doc));
+        saajMsg.saveChanges();
+
+        msg.setContent(SOAPMessage.class, saajMsg);
+        
+        msg.put(
+            WSHandlerConstants.ACTION, 
+            WSHandlerConstants.USERNAME_TOKEN + " " + WSHandlerConstants.ENCRYPT
+        );
+        msg.put(WSHandlerConstants.ENC_PROP_FILE, "META-INF/cxf/outsecurity.properties");
+        msg.put(WSHandlerConstants.USER, "alice");
+        msg.put("password", "alicePassword");
+        msg.put(WSHandlerConstants.ENCRYPTION_USER, "myalias");
+        msg.put(
+            WSHandlerConstants.ENCRYPTION_PARTS, 
+            "{Content}{" + WSConstants.WSSE_NS + "}UsernameToken"
+        );
+
+        handler.handleMessage(msg);
+        doc = part;
+
+        assertValid("//wsse:Security", doc);
+
+        byte[] docbytes = getMessageBytes(doc);
+        XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(docbytes));
+
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+
+        dbf.setValidating(false);
+        dbf.setIgnoringComments(false);
+        dbf.setIgnoringElementContentWhitespace(true);
+        dbf.setNamespaceAware(true);
+
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        db.setEntityResolver(new NullResolver());
+        doc = StaxUtils.read(db, reader, false);
+
+        WSS4JInInterceptor inHandler = new WSS4JInInterceptor();
+
+        SoapMessage inmsg = new SoapMessage(new MessageImpl());
+        ex.setInMessage(inmsg);
+        inmsg.setContent(SOAPMessage.class, saajMsg);
+
+        inHandler.setProperty(
+            WSHandlerConstants.ACTION, 
+            WSHandlerConstants.USERNAME_TOKEN + " " + WSHandlerConstants.ENCRYPT
+        );
+        inHandler.setProperty(WSHandlerConstants.DEC_PROP_FILE, "META-INF/cxf/insecurity.properties");
+        inHandler.setProperty(
+            WSHandlerConstants.PW_CALLBACK_CLASS, 
+            "org.apache.cxf.ws.security.wss4j.TestPwdCallback"
+        );
+
+        inHandler.handleMessage(inmsg);
+        //
+        // Check that the EncryptedData is no longer there
+        //
+        assertInvalid("//s:Body/xenc:EncryptedData", saajMsg.getSOAPPart());
+        //
+        // There should be exactly 1 (WSS4J) HandlerResult
+        //
+        final java.util.List<WSHandlerResult> handlerResults = 
+            (java.util.List<WSHandlerResult>) inmsg.get(WSHandlerConstants.RECV_RESULTS);
+        assertNotNull(handlerResults);
+        assertSame(handlerResults.size(), 1);
+        
+        //
+        // This should contain exactly 2 protection results
+        //
+        final java.util.List<Object> protectionResults =
+            (java.util.List<Object>) handlerResults.get(0).getResults();
+        assertNotNull(protectionResults);
+        assertSame(protectionResults.size(), 2);
+    }
+    
+    @Test
     public void testCustomProcessor() throws Exception {
         Document doc = readDocument("wsse-request-clean.xml");
 



Mime
View raw message