[WSS4J] wss4j/src/org/apache/ws/security SOAP12Constants.java,NONE,1.1 SOAPConstants.java,NONE,1.1 SOAP11Constants.java,NONE,1.1 WSConstants.java,1.11,1.12 WSSecurityEngine.java,1.32,1.33

[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
In directory sc8-pr-cvs1:/tmp/cvs-serv27132/src/org/apache/ws/security

Modified Files:
	WSConstants.java WSSecurityEngine.java 
Added Files:
	SOAP12Constants.java SOAPConstants.java SOAP11Constants.java 
Log Message:
Add SOAP 1.2 handling. Most of the code shamelessly copied from Axis
and modified.

--- NEW FILE: SOAP12Constants.java ---
/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Axis" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact [email protected]
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
package org.apache.ws.security;

import javax.xml.namespace.QName;

/**
 * SOAP 1.2 constants
 *
 * @author Glen Daniels ([email protected])
 * @author Andras Avar ([email protected])
 */
public class SOAP12Constants implements SOAPConstants {
    private static QName headerQName = new QName(WSConstants.URI_SOAP12_ENV,
                                                 WSConstants.ELEM_HEADER);
    private static QName bodyQName = new QName(WSConstants.URI_SOAP12_ENV,
                                               WSConstants.ELEM_BODY);
    private static QName roleQName = new QName(WSConstants.URI_SOAP12_ENV,
                                                WSConstants.ATTR_ROLE);
    
    // Public constants for SOAP 1.2
    
    /** MessageContext property name for webmethod */
    public static final String PROP_WEBMETHOD = "soap12.webmethod";

    public String getEnvelopeURI() {
        return WSConstants.URI_SOAP12_ENV;
    }

    public QName getHeaderQName() {
        return headerQName;
    }

    public QName getBodyQName() {
        return bodyQName;
    }

    /**
     * Obtain the QName for the role attribute (actor/role)
     */
    public QName getRoleAttributeQName() {
        return roleQName;
    }

    /**
     * Obtain the "next" role/actor URI
     */
    public String getNextRoleURI() {
        return WSConstants.URI_SOAP12_NEXT_ROLE;
    }

}

--- NEW FILE: SOAPConstants.java ---
/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Axis" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact [email protected]
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
package org.apache.ws.security;

import javax.xml.namespace.QName;
import java.io.Serializable;

/**
 * An interface definining SOAP constants.  This allows various parts of the
 * engine to avoid hardcoding dependence on a particular SOAP version and its
 * associated URIs, etc.
 *
 * This might be fleshed out later to encapsulate factories for behavioral
 * objects which act differently depending on the SOAP version, but for now
 * it just supplies common namespaces + QNames.
 *
 * @author Glen Daniels ([email protected])
 * @author Andras Avar ([email protected])
 */
public interface SOAPConstants extends Serializable {
    /** SOAP 1.1 constants - thread-safe and shared */
    public SOAP11Constants SOAP11_CONSTANTS = new SOAP11Constants();
    /** SOAP 1.2 constants - thread-safe and shared */
    public SOAP12Constants SOAP12_CONSTANTS = new SOAP12Constants();

    /**
     * Obtain the envelope namespace for this version of SOAP
     */
    public String getEnvelopeURI();

    /**
     * Obtain the QName for the Header element
     */
    public QName getHeaderQName();

    /**
     * Obtain the QName for the Body element
     */
    public QName getBodyQName();

    /**
     * Obtain the QName for the role attribute (actor/role)
     */
    public QName getRoleAttributeQName();

    /**
     * Obtain the "next" role/actor URI
     */ 
    public String getNextRoleURI();


}

--- NEW FILE: SOAP11Constants.java ---
/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Axis" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact [email protected]
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
package org.apache.ws.security;

import javax.xml.namespace.QName;

/**
 * SOAP 1.1 constants
 *
 * @author Glen Daniels ([email protected])
 * @author Andras Avar ([email protected])
 */
public class SOAP11Constants implements SOAPConstants {
    private static QName headerQName = new QName(WSConstants.URI_SOAP11_ENV,
                                                 WSConstants.ELEM_HEADER);
    private static QName bodyQName = new QName(WSConstants.URI_SOAP11_ENV,
                                               WSConstants.ELEM_BODY);
    private static QName roleQName = new QName(WSConstants.URI_SOAP11_ENV,
                                                WSConstants.ATTR_ACTOR);

    public String getEnvelopeURI() {
        return WSConstants.URI_SOAP11_ENV;
    }

    public QName getHeaderQName() {
        return headerQName;
    }

    public QName getBodyQName() {
        return bodyQName;
    }

    /**
     * Obtain the QName for the role attribute (actor/role)
     */
    public QName getRoleAttributeQName() {
        return roleQName;
    }

    /**
     * Obtain the "next" role/actor URI
     */
    public String getNextRoleURI() {
        return WSConstants.URI_SOAP11_NEXT_ACTOR;
    }
}

Index: WSConstants.java
===================================================================
RCS file: /cvsroot/wss4j/wss4j/src/org/apache/ws/security/WSConstants.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** WSConstants.java	17 Dec 2003 13:41:15 -0000	1.11
--- WSConstants.java	21 Jan 2004 12:14:42 -0000	1.12
***************
*** 73,77 ****
      public static final String ENC_KEY_LN = "EncryptedKey";
      public static final String REF_LIST_LN = "ReferenceList";
!     public static final String SOAP_NS = "http://schemas.xmlsoap.org/soap/envelope/";
      public static final String SOAP_SEC_NS = "http://schemas.xmlsoap.org/soap/security/2000-12";
      public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";
--- 73,77 ----
      public static final String ENC_KEY_LN = "EncryptedKey";
      public static final String REF_LIST_LN = "ReferenceList";
!     // public static final String SOAP_NS = "http://schemas.xmlsoap.org/soap/envelope/";
      public static final String SOAP_SEC_NS = "http://schemas.xmlsoap.org/soap/security/2000-12";
      public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";
***************
*** 85,88 ****
--- 85,122 ----
      public static final String CREATED_LN = "Created";
  
+ 	//
+ 	// SOAP-ENV Namespaces
+ 	//
+ 	public static final String URI_SOAP11_ENV =
+ 								"http://schemas.xmlsoap.org/soap/envelope/" ;
+ 	public static final String URI_SOAP12_ENV =
+ 								   "http://www.w3.org/2003/05/soap-envelope";
+ 	// public static final String URI_DEFAULT_SOAP_ENV =
+ 		// DEFAULT_SOAP_VERSION.getEnvelopeURI();
+ 
+ 	public static final String[] URIS_SOAP_ENV = {
+ 		URI_SOAP11_ENV,
+ 		URI_SOAP12_ENV,
+ 	};
+ 
+ 	// Misc SOAP Namespaces / URIs
+ 	public static final String URI_SOAP11_NEXT_ACTOR =
+ 									 "http://schemas.xmlsoap.org/soap/actor/next" ;
+ 	public static final String URI_SOAP12_NEXT_ROLE =
+ 									 "http://www.w3.org/2003/05/soap-envelope/role/next";
+ 	public static final String URI_SOAP12_NONE_ROLE =
+ 						 "http://www.w3.org/2003/05/soap-envelope/role/none";
+ 	public static final String URI_SOAP12_ULTIMATE_ROLE =
+ 			 "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver";
+ 
+ 	public static final String ELEM_ENVELOPE = "Envelope" ;
+ 	public static final String ELEM_HEADER   = "Header" ;
+ 	public static final String ELEM_BODY     = "Body" ;
+ 
+ 	public static final String ATTR_MUST_UNDERSTAND = "mustUnderstand" ;
+ 	public static final String ATTR_ACTOR           = "actor" ;
+ 	public static final String ATTR_ROLE            = "role" ;
+ 
+ 
  	/**
  	 * Sets the {@link org.apache.ws.security.message.WSSAddUsernameToken#build(Document, String, String) UserNameToken}

Index: WSSecurityEngine.java
===================================================================
RCS file: /cvsroot/wss4j/wss4j/src/org/apache/ws/security/WSSecurityEngine.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** WSSecurityEngine.java	16 Jan 2004 15:24:02 -0000	1.32
--- WSSecurityEngine.java	21 Jan 2004 12:14:42 -0000	1.33
***************
*** 221,228 ****
          String headerActor = null;
  		WSSecurityEngineResult wsResult = null;
  
          for (int i = 0; i < len; i++) {
              elem = (Element) list.item(i);
!             attr = elem.getAttributeNodeNS(WSConstants.SOAP_NS, "actor");
              if (attr != null) {
                  headerActor = attr.getValue();
--- 221,229 ----
          String headerActor = null;
  		WSSecurityEngineResult wsResult = null;
+ 		SOAPConstants sc = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
  
          for (int i = 0; i < len; i++) {
              elem = (Element) list.item(i);
!             attr = elem.getAttributeNodeNS(sc.getEnvelopeURI(), sc.getRoleAttributeQName().getLocalPart());
              if (attr != null) {
                  headerActor = attr.getValue();
***************
*** 230,234 ****
              if ((headerActor == null) || (headerActor.length() == 0) ||
              	headerActor.equalsIgnoreCase(actor) ||
!        			headerActor.equals("http://schemas.xmlsoap.org/soap/actor/next")) {
         			if (doDebug) {
                  	log.debug("Processing WS-Security header for '" + actor + "' actor.");
--- 231,235 ----
              if ((headerActor == null) || (headerActor.length() == 0) ||
              	headerActor.equalsIgnoreCase(actor) ||
!        			headerActor.equals(sc.getNextRoleURI())) {
         			if (doDebug) {
                  	log.debug("Processing WS-Security header for '" + actor + "' actor.");




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