Author: coheigea
Date: Fri Feb 25 16:37:24 2011
New Revision: 1074621

URL: http://svn.apache.org/viewvc?rev=1074621&view=rev
Log:
[WSS-231] - Added a test to append a signature element after a Timestamp elemen

Modified:
    webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew3.java

Modified: 
webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew3.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew3.java?rev=1074621&r1=1074620&r2=1074621&view=diff
==============================================================================
--- webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew3.java 
(original)
+++ webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew3.java 
Fri Feb 25 16:37:24 2011
@@ -30,6 +30,7 @@ import org.apache.axis.message.SOAPEnvel
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ws.security.WSConstants;
+import org.apache.ws.security.WSEncryptionPart;
 import org.apache.ws.security.WSPasswordCallback;
 import org.apache.ws.security.WSSConfig;
 import org.apache.ws.security.WSSecurityEngine;
@@ -37,6 +38,7 @@ import org.apache.ws.security.components
 import org.apache.ws.security.components.crypto.CryptoFactory;
 import org.apache.ws.security.message.WSSecSignature;
 import org.apache.ws.security.message.WSSecHeader;
+import org.apache.ws.security.message.WSSecTimestamp;
 import org.w3c.dom.Document;
 
 import javax.security.auth.callback.Callback;
@@ -226,6 +228,45 @@ public class TestWSSecurityNew3 extends 
         
         verify(signedDoc);
     }
+    
+    /**
+     * This test adds a Timestamp to the security header, and then signs it, 
and appends
+     * the signature element after the Timestamp in the header.
+     * @throws Exception
+     */
+    public void testSignedTimestamp() throws Exception {
+        Document doc = unsignedEnvelope.getAsDocument();
+        WSSecHeader secHeader = new WSSecHeader();
+        secHeader.insertSecurityHeader(doc);
+        
+        WSSecTimestamp timestamp = new WSSecTimestamp();
+        timestamp.setTimeToLive(300);
+        Document createdDoc = timestamp.build(doc, secHeader);
+        
+        java.util.Vector parts = new java.util.Vector();
+        WSEncryptionPart encP =
+            new WSEncryptionPart(
+                "Timestamp",
+                WSConstants.WSU_NS,
+                "");
+        parts.add(encP);
+        
+        WSSecSignature builder = new WSSecSignature();
+        builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", 
"security");
+        builder.prepare(createdDoc, crypto, secHeader);
+        builder.addReferencesToSign(parts, secHeader);
+        builder.appendToHeader(secHeader);
+        builder.computeSignature();
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("After Signing....");
+            String outputString = 
+                
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
+            LOG.debug(outputString);
+        }
+        
+        verify(doc);
+    }
 
 
     /**


Reply via email to