[WSS4J] wss4j/src/org/apache/ws/security/message WSSignEnvelope.java,1.29,1.30

[email protected] Tue, 10 Feb 2004 07:22:21 -0800
Newsgroups gmane.text.xml.wss4j
Message-ID <[email protected]>
Update of /cvsroot/wss4j/wss4j/src/org/apache/ws/security/message
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5988/src/org/apache/ws/security/message

Modified Files:
	WSSignEnvelope.java 
Log Message:
First working version of STRTransform with limited functionality. Only
direct references are supported yet. But all hooks are in place, 
STRTransfrom is registered, and gets called, XML setup seems to be
ok. Refer to inline documentation of STRTransform.java

Index: WSSignEnvelope.java
===================================================================
RCS file: /cvsroot/wss4j/wss4j/src/org/apache/ws/security/message/WSSignEnvelope.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- WSSignEnvelope.java	9 Feb 2004 16:10:28 -0000	1.29
+++ WSSignEnvelope.java	10 Feb 2004 15:22:19 -0000	1.30
@@ -184,7 +184,6 @@
 		 */
 		WSDocInfo wsDocInfo = new WSDocInfo(doc.hashCode());
 		wsDocInfo.setCrypto(crypto);
-		WSDocInfoStore.store(wsDocInfo);
 		
 		Element envelope = doc.getDocumentElement();
 		SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(envelope);			
@@ -257,9 +256,9 @@
 				}
 			}
 			else if (elemName.equals("STRTransform")) {
-				Element ctx = null;	// This element shall conatin the arg to STR
+				Element ctx = createSTRParameter(doc);	// This element shall conatin the arg to STR
 				transforms = new Transforms(doc);
-				transforms.addTransform(STRTransform.implementedTransformURI /*, ctx */);
+				transforms.addTransform(STRTransform.implementedTransformURI, ctx);
 				sig.addDocument("#" + keyInfoUri, transforms);
 			}
 			else {
@@ -314,7 +313,17 @@
 			t3=System.currentTimeMillis();
 		}
         info.addUnknownElement(secRef.getElement());
-        sig.sign(crypto.getPrivateKey(user, password));
+        
+		WSDocInfoStore.store(wsDocInfo);
+		try {
+			sig.sign(crypto.getPrivateKey(user, password));
+		}
+		catch (Exception ex) {
+			throw ex;
+		}
+		finally {
+			WSDocInfoStore.delete(wsDocInfo); 
+		}
 		if (tlog.isDebugEnabled() ) {
 			t4=System.currentTimeMillis();
 			tlog.debug("SignEnvelope: cre-Sig= " + (t1-t0) +
@@ -322,13 +331,36 @@
 			" sec-ref= " + (t3-t2) +
 			" signature= " + (t4-t3));
 		}
-		
-		WSDocInfoStore.delete(wsDocInfo);        
-
         if (doDebug) {
         	log.debug("Signing complete.");
         } 
         return (doc);
     }
+    
+    private Element createSTRParameter(Document doc) {
+		Element transformParam =
+			doc.createElementNS(
+				WSConstants.WSSE_NS,
+				WSConstants.WSSE_PREFIX + ":TransformationParameters");
+
+		WSSecurityUtil.setNamespace(
+			transformParam,
+			WSConstants.WSSE_NS,
+			WSConstants.WSSE_PREFIX);
+
+		Element canonElem =
+			doc.createElementNS(
+				WSConstants.SIG_NS,
+				WSConstants.SIG_PREFIX + ":CanonicalizationMethod");
+
+		WSSecurityUtil.setNamespace(
+			canonElem,
+			WSConstants.SIG_NS,
+			WSConstants.SIG_PREFIX);
+			
+		canonElem.setAttributeNS(null, "Algorithm", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315");
+		transformParam.appendChild(canonElem);
+		return transformParam;
+    }
 
 }



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn