ws-wss4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r784786 - /webservices/wss4j/trunk/test/wssec/TestWSSecurityNew6.java
Date Mon, 15 Jun 2009 14:07:49 GMT
Author: coheigea
Date: Mon Jun 15 14:07:49 2009
New Revision: 784786

URL: http://svn.apache.org/viewvc?rev=784786&view=rev
Log:
[WSS-198] - Added a test for this issue on trunk (it works fine).

Modified:
    webservices/wss4j/trunk/test/wssec/TestWSSecurityNew6.java

Modified: webservices/wss4j/trunk/test/wssec/TestWSSecurityNew6.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/test/wssec/TestWSSecurityNew6.java?rev=784786&r1=784785&r2=784786&view=diff
==============================================================================
--- webservices/wss4j/trunk/test/wssec/TestWSSecurityNew6.java (original)
+++ webservices/wss4j/trunk/test/wssec/TestWSSecurityNew6.java Mon Jun 15 14:07:49 2009
@@ -24,6 +24,7 @@
 import junit.framework.TestSuite;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.ws.security.WSEncryptionPart;
 import org.apache.ws.security.WSPasswordCallback;
 import org.apache.ws.security.WSSecurityEngine;
 import org.apache.ws.security.components.crypto.Crypto;
@@ -37,6 +38,8 @@
 import javax.security.auth.callback.CallbackHandler;
 import javax.security.auth.callback.UnsupportedCallbackException;
 import java.io.IOException;
+import java.util.List;
+import java.util.Vector;
 
 /**
  * WS-Security Test Case <p/>
@@ -53,7 +56,7 @@
         +   "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" 
         +   "<SOAP-ENV:Body>" 
         +       "<add xmlns=\"http://ws.apache.org/counter/counter_port_type\">" 
-        +           "<value xmlns=\"\">15</value>" 
+        +           "<value xmlns=\"http://blah.com\">15</value>" 
         +       "</add>" 
         +   "</SOAP-ENV:Body>" 
         + "</SOAP-ENV:Envelope>";
@@ -82,7 +85,7 @@
 
 
     /**
-     * Test that encrypts and signs a WS-Security envelope, then performs
+     * Test that encrypts and then signs a WS-Security envelope, then performs
      * verification and decryption <p/>
      * 
      * @throws Exception
@@ -101,11 +104,74 @@
         secHeader.insertSecurityHeader(doc);
 
         Document encryptedDoc = encrypt.build(doc, crypto, secHeader);
-        Document encryptedSignedDoc = sign.build(encryptedDoc, crypto,
-                secHeader);
+        Document encryptedSignedDoc = sign.build(encryptedDoc, crypto, secHeader);
         LOG.info("After Encryption....");
         verify(encryptedSignedDoc);
     }
+    
+    
+    /**
+     * Test that signs and then encrypts a WS-Security envelope, then performs
+     * decryption and verification <p/>
+     * 
+     * @throws Exception
+     *             Thrown when there is any problem in signing, encryption,
+     *             decryption, or verification
+     */
+    public void testSigningEncryption() throws Exception {
+        WSSecEncrypt encrypt = new WSSecEncrypt();
+        WSSecSignature sign = new WSSecSignature();
+        encrypt.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e");
+        sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+        LOG.info("Before Encryption....");
+        Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
+
+        WSSecHeader secHeader = new WSSecHeader();
+        secHeader.insertSecurityHeader(doc);
+
+        Document signedDoc = sign.build(doc, crypto, secHeader);
+        Document encryptedSignedDoc = encrypt.build(signedDoc, crypto, secHeader);
+        LOG.info("After Encryption....");
+        verify(encryptedSignedDoc);
+    }
+    
+    
+    /**
+     * Test that signs a SOAP Body, and then encrypts some data inside the SOAP Body.
+     * As the encryption adds a wsu:Id to the encrypted element, this test checks that
+     * verification still works ok.
+     */
+    public void testWSS198() throws Exception {
+        WSSecEncrypt encrypt = new WSSecEncrypt();
+        WSSecSignature sign = new WSSecSignature();
+        encrypt.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e");
+        sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+        LOG.info("Before Encryption....");
+        Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
+        
+        List parts = new Vector();
+        WSEncryptionPart encP =
+            new WSEncryptionPart(
+                "add",
+                "http://ws.apache.org/counter/counter_port_type",
+                "");
+        parts.add(encP);
+        encrypt.setParts(parts);
+
+        WSSecHeader secHeader = new WSSecHeader();
+        secHeader.insertSecurityHeader(doc);
+
+        Document signedDoc = sign.build(doc, crypto, secHeader);
+        Document encryptedSignedDoc = encrypt.build(signedDoc, crypto, secHeader);
+        LOG.info("WSS198");
+        if (LOG.isDebugEnabled()) {
+            String outputString = 
+                org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(encryptedSignedDoc);
+            LOG.debug(outputString);
+        }
+        verify(encryptedSignedDoc);
+    }
+    
 
     /**
      * Verifies the soap envelope <p/>



---------------------------------------------------------------------
To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: wss4j-dev-help@ws.apache.org


Mime
View raw message