[WSS4J] wss4j/src/org/apache/ws/security/message EnvelopeIdResolver.java,1.9,1.10 WSSignEnvelope.java,1.24,1.25 WSEncryptBody.java,1.26,1.27 WSBaseMessage.java,1.8,1.9

[email protected] Wed, 21 Jan 2004 04:14:44 -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:/tmp/cvs-serv27132/src/org/apache/ws/security/message

Modified Files:
	EnvelopeIdResolver.java WSSignEnvelope.java WSEncryptBody.java 
	WSBaseMessage.java 
Log Message:
Add SOAP 1.2 handling. Most of the code shamelessly copied from Axis
and modified.

Index: EnvelopeIdResolver.java
===================================================================
RCS file: /cvsroot/wss4j/wss4j/src/org/apache/ws/security/message/EnvelopeIdResolver.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** EnvelopeIdResolver.java	7 Jan 2004 15:24:54 -0000	1.9
--- EnvelopeIdResolver.java	21 Jan 2004 12:14:41 -0000	1.10
***************
*** 58,61 ****
--- 58,62 ----
  import org.apache.commons.logging.LogFactory;
  import org.apache.ws.security.WSConstants;
+ import org.apache.ws.security.SOAPConstants;
  import org.apache.ws.security.util.WSSecurityUtil;
  import org.apache.xml.security.signature.XMLSignatureInput;
***************
*** 149,153 ****
  		  */
  		String id = uriNodeValue.substring(1);
! 		Element selectedElem = WSSecurityUtil.findBodyElement(doc);
  		if (selectedElem == null) {
  			throw new ResourceResolverException(
--- 150,155 ----
  		  */
  		String id = uriNodeValue.substring(1);
! 		SOAPConstants sc = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
! 		Element selectedElem = WSSecurityUtil.findBodyElement(doc, sc);
  		if (selectedElem == null) {
  			throw new ResourceResolverException(

Index: WSSignEnvelope.java
===================================================================
RCS file: /cvsroot/wss4j/wss4j/src/org/apache/ws/security/message/WSSignEnvelope.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** WSSignEnvelope.java	15 Jan 2004 12:25:33 -0000	1.24
--- WSSignEnvelope.java	21 Jan 2004 12:14:41 -0000	1.25
***************
*** 175,178 ****
--- 175,182 ----
  			log.debug("Beginning signing...");
  		} 
+ 
+ 		Element envelope = doc.getDocumentElement();
+ 		soapConstants = WSSecurityUtil.getSOAPConstants(envelope);			
+ 		
          Element securityHeader = insertSecurityHeader(doc, true);
  
***************
*** 202,209 ****
  			t1=System.currentTimeMillis();
  		}
  		if (parts == null) {
  			parts = new Vector();
  			WSEncryptionPart encP =
! 				new WSEncryptionPart("Body", WSConstants.SOAP_NS, "Content");
  			parts.add(encP);
  		}
--- 206,217 ----
  			t1=System.currentTimeMillis();
  		}
+ 
  		if (parts == null) {
  			parts = new Vector();
  			WSEncryptionPart encP =
! 				new WSEncryptionPart(
! 					soapConstants.getBodyQName().getLocalPart(),
! 					soapConstants.getEnvelopeURI(),
! 					"Content");
  			parts.add(encP);
  		}
***************
*** 211,215 ****
  		String certUri = "id-" + certs[0].hashCode();
  		
- 		Element envelope = doc.getDocumentElement();
  		Transforms transforms = null;
  		
--- 219,222 ----

Index: WSEncryptBody.java
===================================================================
RCS file: /cvsroot/wss4j/wss4j/src/org/apache/ws/security/message/WSEncryptBody.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** WSEncryptBody.java	16 Jan 2004 15:24:02 -0000	1.26
--- WSEncryptBody.java	21 Jan 2004 12:14:41 -0000	1.27
***************
*** 254,258 ****
  
  		/*
! 		 * First step: set the encoding namespace in the SOAP:Envelope
  		 */
  		Element envelope = doc.getDocumentElement();
--- 254,258 ----
  
  		/*
! 		 * First step: set the encryption encoding namespace in the SOAP:Envelope
  		 */
  		Element envelope = doc.getDocumentElement();
***************
*** 262,265 ****
--- 262,267 ----
  			WSConstants.ENC_NS);
  
+ 		soapConstants = WSSecurityUtil.getSOAPConstants(envelope);			
+ 
  		/*
  		 * Second step: generate a symmetric key (session key) for
***************
*** 276,280 ****
  			parts = new Vector();
  			WSEncryptionPart encP =
! 				new WSEncryptionPart("Body", WSConstants.SOAP_NS, "Content");
  			parts.add(encP);
  		}
--- 278,285 ----
  			parts = new Vector();
  			WSEncryptionPart encP =
! 				new WSEncryptionPart(
! 					soapConstants.getBodyQName().getLocalPart(),
! 					soapConstants.getEnvelopeURI(),
! 					"Content");
  			parts.add(encP);
  		}
***************
*** 443,448 ****
  			"xmlns:" + WSConstants.ENC_PREFIX,
  			WSConstants.ENC_NS);
- 		// Element nsContext = WSSecurityUtil.createNamespaceContext(doc);
  
  		/*
  		 * Second step: generate a symmetric key from the specified
--- 448,453 ----
  			"xmlns:" + WSConstants.ENC_PREFIX,
  			WSConstants.ENC_NS);
  
+ 		soapConstants = WSSecurityUtil.getSOAPConstants(envelope);
  		/*
  		 * Second step: generate a symmetric key from the specified
***************
*** 461,465 ****
  			parts = new Vector();
  			WSEncryptionPart encP =
! 				new WSEncryptionPart("Body", WSConstants.SOAP_NS, "Content");
  			parts.add(encP);
  		}
--- 466,473 ----
  			parts = new Vector();
  			WSEncryptionPart encP =
! 				new WSEncryptionPart(
! 					soapConstants.getBodyQName().getLocalPart(),
! 					soapConstants.getEnvelopeURI(),
! 					"Content");
  			parts.add(encP);
  		}

Index: WSBaseMessage.java
===================================================================
RCS file: /cvsroot/wss4j/wss4j/src/org/apache/ws/security/message/WSBaseMessage.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** WSBaseMessage.java	22 Dec 2003 13:36:23 -0000	1.8
--- WSBaseMessage.java	21 Jan 2004 12:14:42 -0000	1.9
***************
*** 58,61 ****
--- 58,62 ----
  import org.apache.commons.logging.LogFactory;
  import org.apache.ws.security.WSConstants;
+ import org.apache.ws.security.SOAPConstants;
  import org.apache.ws.security.util.WSSecurityUtil;
  import org.w3c.dom.Document;
***************
*** 84,87 ****
--- 85,90 ----
  	protected Vector parts = null;
  	
+ 	protected SOAPConstants soapConstants = null;
+ 	
  	protected boolean doDebug = false;
  
***************
*** 191,196 ****
  			(Element) WSSecurityUtil.getDirectChild(
  				doc.getFirstChild(),
! 				"Body",
! 				WSConstants.SOAP_NS);
  		if (bodyElement == null) {
  			throw new Exception("SOAP Body Element node not found");
--- 194,199 ----
  			(Element) WSSecurityUtil.getDirectChild(
  				doc.getFirstChild(),
! 				soapConstants.getBodyQName().getLocalPart(),
! 				soapConstants.getEnvelopeURI());
  		if (bodyElement == null) {
  			throw new Exception("SOAP Body Element node not found");
***************
*** 240,244 ****
  	protected Element insertSecurityHeader(Document doc, boolean timestamp) {
  		// lookup a security header block that matches actor
! 		Element securityHeader = WSSecurityUtil.getSecurityHeader(doc, actor);
  		if (securityHeader == null) { 			// create if nothing found
  			securityHeader =
--- 243,248 ----
  	protected Element insertSecurityHeader(Document doc, boolean timestamp) {
  		// lookup a security header block that matches actor
! 		Element securityHeader =
! 			WSSecurityUtil.getSecurityHeader(doc, actor, soapConstants);
  		if (securityHeader == null) { 			// create if nothing found
  			securityHeader =
***************
*** 248,264 ****
  					true);
  					
! 			String soapPrefix = WSSecurityUtil.getPrefix(WSConstants.SOAP_NS, 
  														 securityHeader);
  			if (actor != null && actor.length() > 0) {
  				// Check for SOAP 1.2 here and use "role" instead of "actor"
  				securityHeader.setAttributeNS(
! 					WSConstants.SOAP_NS,
! 					soapPrefix + ":actor",
  					actor);
  			}
  			if (mustunderstand != null) {
  				securityHeader.setAttributeNS(
! 					WSConstants.SOAP_NS,
! 					soapPrefix + ":mustUnderstand",
  					mustunderstand);
  			}
--- 252,271 ----
  					true);
  					
! 			String soapPrefix =
! 				WSSecurityUtil.getPrefix(soapConstants.getEnvelopeURI(),
  														 securityHeader);
  			if (actor != null && actor.length() > 0) {
  				// Check for SOAP 1.2 here and use "role" instead of "actor"
  				securityHeader.setAttributeNS(
! 					soapConstants.getEnvelopeURI(),
! 					soapPrefix
! 						+ ":"
! 						+ soapConstants.getRoleAttributeQName().getLocalPart(),
  					actor);
  			}
  			if (mustunderstand != null) {
  				securityHeader.setAttributeNS(
! 					soapConstants.getEnvelopeURI(),
! 					soapPrefix + ":" + WSConstants.ATTR_MUST_UNDERSTAND,
  					mustunderstand);
  			}




-------------------------------------------------------
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