Author: ruchithf
Date: Thu Sep  7 06:09:31 2006
New Revision: 441080

URL: http://svn.apache.org/viewvc?view=rev&rev=441080
Log:
Updated SecConv impl classes to handle the WS-SX versions and improved 
ConversationException.


Added:
    
webservices/wss4j/trunk/src/org/apache/ws/security/conversation/errors.properties
Modified:
    webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java
    webservices/wss4j/trunk/src/org/apache/ws/security/WSSecurityEngine.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/conversation/ConversationConstants.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/conversation/ConversationException.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKEncrypt.java
    webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKSign.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDerivedKeyBase.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSecurityContextToken.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/DerivedKeyToken.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/SecurityContextToken.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java

Modified: webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java?view=diff&rev=441080&r1=441079&r2=441080
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java Thu Sep  
7 06:09:31 2006
@@ -243,9 +243,11 @@
             name = "org.apache.ws.security.processor.ReferenceListProcessor";
         } else if (el.equals(WSSecurityEngine.signatureConfirmation)) {
             name = 
"org.apache.ws.security.processor.SignatureConfirmationProcessor";
-        } else if (el.equals(WSSecurityEngine.DERIVED_KEY_TOKEN)) {
+        } else if (el.equals(WSSecurityEngine.DERIVED_KEY_TOKEN_05_02) ||
+                el.equals(WSSecurityEngine.DERIVED_KEY_TOKEN_05_12)) {
             name = "org.apache.ws.security.processor.DerivedKeyTokenProcessor";
-        } else if(el.equals(WSSecurityEngine.SECURITY_CONTEXT_TOKEN)) {
+        } else if(el.equals(WSSecurityEngine.SECURITY_CONTEXT_TOKEN_05_02) ||
+                el.equals(WSSecurityEngine.SECURITY_CONTEXT_TOKEN_05_12)) {
             name = 
"org.apache.ws.security.processor.SecurityContextTokenProcessor";
         }
 

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/WSSecurityEngine.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/WSSecurityEngine.java?view=diff&rev=441080&r1=441079&r2=441080
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/WSSecurityEngine.java 
(original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/WSSecurityEngine.java 
Thu Sep  7 06:09:31 2006
@@ -88,12 +88,22 @@
     /**
      * <code>wsc:DerivedKeyToken</code> as defined by WS-SecureConversation 
specification
      */
-    public static final QName DERIVED_KEY_TOKEN = new 
QName(ConversationConstants.WSC_NS, ConversationConstants.DERIVED_KEY_TOKEN_LN);
+    public static final QName DERIVED_KEY_TOKEN_05_02 = new 
QName(ConversationConstants.WSC_NS_05_02, 
ConversationConstants.DERIVED_KEY_TOKEN_LN);
 
     /**
      * <code>wsc:SecurityContextToken</code> as defined by 
WS-SecureConversation specification
      */
-    public static final QName SECURITY_CONTEXT_TOKEN = new 
QName(ConversationConstants.WSC_NS, 
ConversationConstants.SECURITY_CONTEXT_TOKEN_LN);
+    public static final QName SECURITY_CONTEXT_TOKEN_05_02 = new 
QName(ConversationConstants.WSC_NS_05_02, 
ConversationConstants.SECURITY_CONTEXT_TOKEN_LN);
+
+    /**
+     * <code>wsc:DerivedKeyToken</code> as defined by WS-SecureConversation 
specification in WS-SX
+     */
+    public static final QName DERIVED_KEY_TOKEN_05_12 = new 
QName(ConversationConstants.WSC_NS_05_02, 
ConversationConstants.DERIVED_KEY_TOKEN_LN);
+
+    /**
+     * <code>wsc:SecurityContextToken</code> as defined by 
WS-SecureConversation specification in WS-SX
+     */
+    public static final QName SECURITY_CONTEXT_TOKEN_05_12 = new 
QName(ConversationConstants.WSC_NS_05_02, 
ConversationConstants.SECURITY_CONTEXT_TOKEN_LN);
     
     public WSSecurityEngine() {
     }

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/conversation/ConversationConstants.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/conversation/ConversationConstants.java?view=diff&rev=441080&r1=441079&r2=441080
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/conversation/ConversationConstants.java
 (original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/conversation/ConversationConstants.java
 Thu Sep  7 06:09:31 2006
@@ -21,22 +21,31 @@
  */
 public class ConversationConstants {
 
-       private static final String NS_YEAR_PREFIX = 
"http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512";;
-       
+    public final static int VERSION_05_02 = 1;
+    
+    public final static int VERSION_05_12 = 2;
+    
+    public final static int DEFAULT_VERSION = VERSION_05_02; 
+    
+    /**
+     * WS-SecConv Feb 2005 version
+     */
+    public final static String WSC_NS_05_02 = 
"http://schemas.xmlsoap.org/ws/2005/02/sc";; 
+    
     /**
-     * WS-Secure Conversation namespace 
+     * WS-Sx version
      */
-    public final static String WSC_NS = NS_YEAR_PREFIX;
+    public final static String WSC_NS_05_12 = 
"http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512";;
     
     /**
-     * TOken type of DerivedKeyToken
+     * Token type of DerivedKeyToken
      */
-    public final static String TOKEN_TYPE_DERIVED_KEY_TOKEN = WSC_NS + "/dk";
+    public final static String TOKEN_TYPE_DERIVED_KEY_TOKEN =  "/dk";
     
     /**
      * Token type of SecurityContextToken
      */
-    public static final String TOKEN_TYPE_SECURITY_CONTEXT_TOKEN = WSC_NS  + 
"/sct";
+    public static final String TOKEN_TYPE_SECURITY_CONTEXT_TOKEN = "/sct";
     
     /**
      * Field WSC_PREFIX
@@ -119,5 +128,25 @@
     
     public interface DerivationAlgorithm {
         public final static String P_SHA_1 = 
"http://schemas.xmlsoap.org/ws/2005/02/sc/dk/p_sha1";;
+    }
+    
+    public static String getWSCNs(int version) throws ConversationException {
+        if(VERSION_05_02 == version) {
+            return WSC_NS_05_02;
+        } else if(VERSION_05_12 == version) {
+            return WSC_NS_05_12;
+        } else {
+            throw new ConversationException("unsupportedSecConvVersion");
+        }
+    }
+    
+    public static int getWSTVersion(String ns) throws ConversationException {
+        if(WSC_NS_05_02.equals(ns)) {
+            return VERSION_05_02;
+        } else if(WSC_NS_05_12.equals(ns)) {
+            return VERSION_05_12;
+        } else {
+            throw new ConversationException("unsupportedSecConvVersion");
+        }
     }
 }

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/conversation/ConversationException.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/conversation/ConversationException.java?view=diff&rev=441080&r1=441079&r2=441080
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/conversation/ConversationException.java
 (original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/conversation/ConversationException.java
 Thu Sep  7 06:09:31 2006
@@ -16,16 +16,103 @@
  */
 package org.apache.ws.security.conversation;
 
-import org.apache.ws.security.WSSecurityException;
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
 
-public class ConversationException extends WSSecurityException {
+public class ConversationException extends Exception {
+    
+    private static final long serialVersionUID = 970894530660804319L;
+    
+    public final static String BAD_CONTEXT_TOKEN = "BadContextToken";
+    public final static String UNSUPPORTED_CONTEXT_TOKEN = 
"UnsupportedContextToken";
+    public final static String UNKNOWN_DERIVATION_SOURCE = 
"UnknownDerivationSource";
+    public final static String RENEW_NEEDED = "RenewNeeded";
+    public final static String UNABLE_TO_REVIEW = "UnableToRenew";
+    
+    private static ResourceBundle resources;
+
+    private String faultCode;
+    private String faultString;
+    
+    static {
+        try {
+            resources = 
ResourceBundle.getBundle("org.apache.ws.security.conversation.errors");
+        } catch (MissingResourceException e) {
+            throw new RuntimeException(e.getMessage());
+        }
+    }
+    
+    public ConversationException(String faultCode, Object[] args) {
+        super(getMessage(faultCode, args));
+        this.faultCode = getFaultCode(faultCode);
+        this.faultString = getMessage(faultCode, args);
+    }
+    
+    /**
+     * Construct the fault properly code for the standard faults
+     * @param faultCode2
+     * @return
+     */
+    private String getFaultCode(String code) {
+        if(BAD_CONTEXT_TOKEN.equals(code) ||
+           UNABLE_TO_REVIEW.equals(code) ||
+           UNKNOWN_DERIVATION_SOURCE.equals(code) ||
+           UNSUPPORTED_CONTEXT_TOKEN.equals(code) ||
+           RENEW_NEEDED.equals(code)) {
+            return ConversationConstants.WSC_PREFIX+ ":" + code;
+        } else {
+            return code;
+        }
+    }
+
+    public ConversationException(String faultCode) {
+        this(faultCode, (Object[])null);
+    }
+    
+    public ConversationException(String faultCode, Object[] args, Throwable e) 
{
+        super(getMessage(faultCode, args),e);
+        this.faultCode = faultCode;
+        this.faultString = getMessage(faultCode, args);
+    }
+    
+    public ConversationException(String faultCode, Throwable e) {
+        this(faultCode, null, e);
+    }
 
     /**
-     * Constructor ConversationException
+     * get the message from resource bundle.
+     * <p/>
      *
-     * @param message
+     * @return the message translated from the property (message) file.
      */
-    public ConversationException(String message) {
-        super(message);
+    protected static String getMessage(String faultCode, Object[] args) {
+        String msg = null;
+        try {
+            msg = MessageFormat.format(resources.getString(faultCode), args);
+        } catch (MissingResourceException e) {
+            throw new RuntimeException("Undefined '" + faultCode + "' resource 
property");
+        }
+        if(msg != null) {
+            return msg;
+        } else {
+            return faultCode;
+        }
     }
+
+    /**
+     * @return Returns the faultCode.
+     */
+    protected String getFaultCode() {
+        return faultCode;
+    }
+
+    /**
+     * @return Returns the faultString.
+     */
+    protected String getFaultString() {
+        return faultString;
+    }
+    
+
 }

Added: 
webservices/wss4j/trunk/src/org/apache/ws/security/conversation/errors.properties
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/conversation/errors.properties?view=auto&rev=441080
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/conversation/errors.properties
 (added)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/conversation/errors.properties
 Thu Sep  7 06:09:31 2006
@@ -0,0 +1,9 @@
+BadContextToken = The requested context elements are insufficient or 
unsupported
+UnsupportedContextToken = Not all of the values associated with the SCT are 
supported
+UnknownDerivationSource = The specified source for the derivation is unknown
+RenewNeeded = The provided context token has expired
+UnableToRenew = The specified context token could not be renewed.
+
+
+
+unsupportedSecConvVersion = Unsupported WS-SecureConversation version
\ No newline at end of file

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKEncrypt.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKEncrypt.java?view=diff&rev=441080&r1=441079&r2=441080
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKEncrypt.java 
(original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKEncrypt.java 
Thu Sep  7 06:09:31 2006
@@ -17,15 +17,11 @@
 
 package org.apache.ws.security.message;
 
-import java.util.Vector;
-
-import javax.crypto.SecretKey;
-
 import org.apache.ws.security.SOAPConstants;
 import org.apache.ws.security.WSConstants;
 import org.apache.ws.security.WSEncryptionPart;
 import org.apache.ws.security.WSSecurityException;
-import org.apache.ws.security.components.crypto.Crypto;
+import org.apache.ws.security.conversation.ConversationException;
 import org.apache.ws.security.message.token.Reference;
 import org.apache.ws.security.message.token.SecurityTokenReference;
 import org.apache.ws.security.util.WSSecurityUtil;
@@ -37,6 +33,10 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
+import javax.crypto.SecretKey;
+
+import java.util.Vector;
+
 /**
  * Encrypts and signes parts of a message with derived keys derived from a
  * symmetric key. This symmetric key will be included as an EncryptedKey
@@ -48,7 +48,7 @@
     protected String symEncAlgo = WSConstants.AES_128;
     
     public Document build(Document doc, WSSecHeader secHeader)
-            throws WSSecurityException {
+            throws WSSecurityException, ConversationException {
         
         /*
          * Setup the encrypted key

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKSign.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKSign.java?view=diff&rev=441080&r1=441079&r2=441080
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKSign.java 
(original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKSign.java 
Thu Sep  7 06:09:31 2006
@@ -17,10 +17,6 @@
 
 package org.apache.ws.security.message;
 
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Vector;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ws.security.SOAPConstants;
@@ -29,7 +25,7 @@
 import org.apache.ws.security.WSDocInfoStore;
 import org.apache.ws.security.WSEncryptionPart;
 import org.apache.ws.security.WSSecurityException;
-import org.apache.ws.security.components.crypto.Crypto;
+import org.apache.ws.security.conversation.ConversationException;
 import org.apache.ws.security.message.token.Reference;
 import org.apache.ws.security.message.token.SecurityTokenReference;
 import org.apache.ws.security.saml.SAMLUtil;
@@ -51,6 +47,10 @@
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Vector;
+
 /**
  * Builder to sign with derived keys
  * 
@@ -80,7 +80,8 @@
     
     private WSDocInfo wsDocInfo;
 
-    public Document build(Document doc, WSSecHeader secHeader) throws 
WSSecurityException  {
+    public Document build(Document doc, WSSecHeader secHeader)
+            throws WSSecurityException, ConversationException {
         
         this.prepare(doc, secHeader);
         
@@ -109,7 +110,7 @@
     }
     
     public void prepare(Document doc, WSSecHeader secHeader)
-                            throws WSSecurityException {
+                            throws WSSecurityException, ConversationException {
         super.prepare(doc);
         
         wsDocInfo = new WSDocInfo(doc.hashCode());

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDerivedKeyBase.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDerivedKeyBase.java?view=diff&rev=441080&r1=441079&r2=441080
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDerivedKeyBase.java
 (original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDerivedKeyBase.java
 Thu Sep  7 06:09:31 2006
@@ -19,6 +19,7 @@
 
 import org.apache.ws.security.WSSecurityException;
 import org.apache.ws.security.conversation.ConversationConstants;
+import org.apache.ws.security.conversation.ConversationException;
 import org.apache.ws.security.conversation.dkalgo.AlgoFactory;
 import org.apache.ws.security.conversation.dkalgo.DerivationAlgorithm;
 import org.apache.ws.security.message.token.DerivedKeyToken;
@@ -83,7 +84,7 @@
      * is (or to be) derived from.
      */
     protected String tokenIdentifier = null;
-    
+
     /**
      * The derived key will change depending on the sig/encr algorithm.
      * Therefore the child classes are expected to provide this value.
@@ -97,6 +98,8 @@
      */
     protected Element strElem;
     
+    private int wscVersion = ConversationConstants.DEFAULT_VERSION;
+    
     /**
      * @param ephemeralKey The ephemeralKey to set.
      */
@@ -168,7 +171,7 @@
      * @throws WSSecurityException
      */
     public void prepare(Document doc)
-        throws WSSecurityException {
+        throws WSSecurityException, ConversationException {
         
         document = doc;
 
@@ -194,7 +197,7 @@
         
         
         //Add the DKTs
-        dkt = new DerivedKeyToken(document);
+        dkt = new DerivedKeyToken(this.wscVersion, document);
         dktId = "derivedKeyId-" + dkt.hashCode();
         
         dkt.setLength(length);
@@ -235,6 +238,13 @@
     public void appendDKElementToHeader(WSSecHeader secHeader) {
         WSSecurityUtil.appendChildElement(document, secHeader
             .getSecurityHeader(), dkt.getElement());
+    }
+
+    /**
+     * @param wscVersion The wscVersion to set.
+     */
+    public void setWscVersion(int wscVersion) {
+        this.wscVersion = wscVersion;
     }
 
 }

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSecurityContextToken.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSecurityContextToken.java?view=diff&rev=441080&r1=441079&r2=441080
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSecurityContextToken.java
 (original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSecurityContextToken.java
 Thu Sep  7 06:09:31 2006
@@ -18,6 +18,8 @@
 
 import org.apache.ws.security.WSSecurityException;
 import org.apache.ws.security.components.crypto.Crypto;
+import org.apache.ws.security.conversation.ConversationConstants;
+import org.apache.ws.security.conversation.ConversationException;
 import org.apache.ws.security.message.token.SecurityContextToken;
 import org.apache.ws.security.util.WSSecurityUtil;
 import org.w3c.dom.Document;
@@ -51,15 +53,17 @@
      * The symmetric secret associated with the SecurityContextToken
      */
     protected byte[] secret;
+    
+    private int wscVersion = ConversationConstants.DEFAULT_VERSION;
 
     public void prepare(Document doc, Crypto crypto)
-            throws WSSecurityException {
+            throws WSSecurityException, ConversationException  {
 
         if (sct == null) {
             if (this.identifier != null) {
-                this.sct = new SecurityContextToken(doc, this.identifier);
+                this.sct = new SecurityContextToken(this.wscVersion, doc, 
this.identifier);
             } else {
-                this.sct = new SecurityContextToken(doc);
+                this.sct = new SecurityContextToken(this.wscVersion, doc);
                 this.identifier = this.sct.getIdentifier();
             }
         }
@@ -136,6 +140,13 @@
      */
     public void setSctId(String sctId) {
         this.sctId = sctId;
+    }
+
+    /**
+     * @param wscVersion The wscVersion to set.
+     */
+    public void setWscVersion(int wscVersion) {
+        this.wscVersion = wscVersion;
     }
     
 }

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/DerivedKeyToken.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/token/DerivedKeyToken.java?view=diff&rev=441080&r1=441079&r2=441080
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/DerivedKeyToken.java
 (original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/DerivedKeyToken.java
 Thu Sep  7 06:09:31 2006
@@ -55,9 +55,6 @@
 
     private Log log = LogFactory.getLog(DerivedKeyToken.class.getName());
 
-    public static final QName TOKEN = new QName(ConversationConstants.WSC_NS,
-            ConversationConstants.
-            DERIVED_KEY_TOKEN_LN);
 
     //These are the elements that are used to create the SecurityContextToken
     protected Element element = null;
@@ -68,19 +65,34 @@
     protected Element elementLength = null;
     protected Element elementLabel = null;
     protected Element elementNonce = null;
+    
+    private String ns;
+    
+    /**
+     * This will create an empty DerivedKeyToken
+     *
+     * @param doc THe DOM document
+     */
+    public DerivedKeyToken(Document doc) throws ConversationException {
+        this(ConversationConstants.DEFAULT_VERSION, doc);
+    }
 
     /**
      * This will create an empty DerivedKeyToken
      *
      * @param doc THe DOM document
      */
-    public DerivedKeyToken(Document doc) {
+    public DerivedKeyToken(int version, Document doc) throws 
ConversationException {
+        
         log.debug("DerivedKeyToken: created");
-        this.element = doc.createElementNS(ConversationConstants.WSC_NS,
+        
+        this.ns = ConversationConstants.getWSCNs(version);
+        
+        this.element = doc.createElementNS(ns,
                 "wsc:" +
                 ConversationConstants.
                 DERIVED_KEY_TOKEN_LN);
-        WSSecurityUtil.setNamespace(this.element, ConversationConstants.WSC_NS,
+        WSSecurityUtil.setNamespace(this.element, ns,
                 ConversationConstants.WSC_PREFIX);
     }
 
@@ -95,7 +107,8 @@
         this.element = elem;
         QName el = new QName(this.element.getNamespaceURI(),
                 this.element.getLocalName());
-        if (!el.equals(TOKEN)) {
+        if (!el.equals(new QName(ConversationConstants.WSC_NS_05_02, 
ConversationConstants.DERIVED_KEY_TOKEN_LN)) &&
+                !el.equals(new QName(ConversationConstants.WSC_NS_05_12, 
ConversationConstants.DERIVED_KEY_TOKEN_LN))) {
             throw new 
WSSecurityException(WSSecurityException.INVALID_SECURITY_TOKEN,
                     "badTokenType00", new Object[]{el});
         }
@@ -103,20 +116,21 @@
                 getDirectChild(this.element,
                         ConversationConstants.SECURITY_TOKEN_REFERENCE_LN,
                         WSConstants.WSSE_NS);
+        
+        this.ns = el.getNamespaceURI();
+        
         this.elementProperties = (Element) WSSecurityUtil.getDirectChild(this.
-                element, ConversationConstants.PROPERTIES_LN,
-                ConversationConstants.WSC_NS);
+                element, ConversationConstants.PROPERTIES_LN, this.ns);
         this.elementGeneration = (Element) WSSecurityUtil.getDirectChild(this.
-                element, ConversationConstants.GENERATION_LN,
-                ConversationConstants.WSC_NS);
+                element, ConversationConstants.GENERATION_LN, this.ns);
         this.elementOffset = (Element) 
WSSecurityUtil.getDirectChild(this.element,
-                ConversationConstants.OFFSET_LN, ConversationConstants.WSC_NS);
+                ConversationConstants.OFFSET_LN, this.ns);
         this.elementLength = (Element) 
WSSecurityUtil.getDirectChild(this.element,
-                ConversationConstants.LENGTH_LN, ConversationConstants.WSC_NS);
+                ConversationConstants.LENGTH_LN, this.ns);
         this.elementLabel = (Element) 
WSSecurityUtil.getDirectChild(this.element,
-                ConversationConstants.LABEL_LN, ConversationConstants.WSC_NS);
+                ConversationConstants.LABEL_LN, this.ns);
         this.elementNonce = (Element) 
WSSecurityUtil.getDirectChild(this.element,
-                ConversationConstants.NONCE_LN, ConversationConstants.WSC_NS);
+                ConversationConstants.NONCE_LN, this.ns);
     }
 
     /**
@@ -161,15 +175,15 @@
      */
     private void addProperty(String propName, String propValue) {
         if (this.elementProperties == null) { //Create the properties element 
if it is not there
-            this.elementProperties = 
this.element.getOwnerDocument().createElementNS(ConversationConstants.WSC_NS,
+            this.elementProperties = 
this.element.getOwnerDocument().createElementNS(this.ns,
                     "wsc:" +
                     ConversationConstants.PROPERTIES_LN);
             WSSecurityUtil.setNamespace(this.elementProperties,
-                    ConversationConstants.WSC_NS,
+                    this.ns,
                     WSConstants.WSSE_PREFIX);
             this.element.appendChild(this.elementProperties);
         }
-        Element tempElement = 
this.element.getOwnerDocument().createElementNS(ConversationConstants.WSC_NS,
+        Element tempElement = 
this.element.getOwnerDocument().createElementNS(this.ns,
                 "wsc:" + propName);
         
tempElement.appendChild(this.element.getOwnerDocument().createTextNode(propValue));
 
@@ -210,7 +224,7 @@
             //If so change the value
             Node node = WSSecurityUtil.findElement(this.elementProperties,
                     propertyName,
-                    ConversationConstants.WSC_NS);
+                    this.ns);
             if (node != null && node instanceof Element) { //If the node is 
not null
                 Text node1 = getFirstNode((Element) node);
                 node1.setData((String) properties.get(propertyName));
@@ -243,11 +257,11 @@
      * @param length The length of the derived key as a long
      */
     public void setLength(int length) {
-        this.elementLength = 
this.element.getOwnerDocument().createElementNS(ConversationConstants.WSC_NS,
+        this.elementLength = 
this.element.getOwnerDocument().createElementNS(this.ns,
                 "wsc:" +
                 ConversationConstants.LENGTH_LN);
         WSSecurityUtil.setNamespace(this.elementLength,
-                ConversationConstants.WSC_NS,
+                this.ns,
                 ConversationConstants.WSC_PREFIX);
         
this.elementLength.appendChild(this.element.getOwnerDocument().createTextNode(Long.toString(length)));
         this.element.appendChild(this.elementLength);
@@ -268,11 +282,11 @@
     public void setOffset( int offset) throws ConversationException {
         //This element MUST NOT be used if the <Generation> element is 
specified
         if (this.elementGeneration == null) {
-            this.elementOffset = 
this.element.getOwnerDocument().createElementNS(ConversationConstants.WSC_NS,
+            this.elementOffset = 
this.element.getOwnerDocument().createElementNS(this.ns,
                     "wsc:" +
                     ConversationConstants.OFFSET_LN);
             WSSecurityUtil.setNamespace(this.elementOffset,
-                    ConversationConstants.WSC_NS,
+                    this.ns,
                     ConversationConstants.WSC_PREFIX);
             
this.elementOffset.appendChild(this.element.getOwnerDocument().createTextNode(Integer.toString(offset)));
             this.element.appendChild(this.elementOffset);
@@ -298,10 +312,10 @@
             ConversationException {
         //This element MUST NOT be used if the <Offset> element is specified
         if (this.elementOffset == null) {
-            this.elementGeneration = 
this.element.getOwnerDocument().createElementNS(ConversationConstants.WSC_NS,
+            this.elementGeneration = 
this.element.getOwnerDocument().createElementNS(this.ns,
                     "wsc:" + ConversationConstants.GENERATION_LN);
             WSSecurityUtil.setNamespace(this.elementGeneration,
-                    ConversationConstants.WSC_NS,
+                    this.ns,
                     ConversationConstants.WSC_PREFIX);
             
this.elementGeneration.appendChild(this.element.getOwnerDocument().createTextNode(Integer.toString(generation)));
             this.element.appendChild(this.elementGeneration);
@@ -323,10 +337,10 @@
      * @param label Label value as a string
      */
     public void setLabel(String label) {
-        this.elementLabel = 
this.element.getOwnerDocument().createElementNS(ConversationConstants.WSC_NS,
+        this.elementLabel = 
this.element.getOwnerDocument().createElementNS(this.ns,
                 "wsc:" +
                 ConversationConstants.LABEL_LN);
-        WSSecurityUtil.setNamespace(this.elementLabel, 
ConversationConstants.WSC_NS,
+        WSSecurityUtil.setNamespace(this.elementLabel, this.ns,
                 ConversationConstants.WSC_PREFIX);
         
this.elementLabel.appendChild(this.element.getOwnerDocument().createTextNode(label));
         this.element.appendChild(this.elementLabel);
@@ -338,10 +352,10 @@
      * @param nonce Nonce value as a string
      */
     public void setNonce(String nonce) {
-        this.elementNonce = 
this.element.getOwnerDocument().createElementNS(ConversationConstants.WSC_NS,
+        this.elementNonce = 
this.element.getOwnerDocument().createElementNS(this.ns,
                 "wsc:" +
                 ConversationConstants.NONCE_LN);
-        WSSecurityUtil.setNamespace(this.elementNonce, 
ConversationConstants.WSC_NS,
+        WSSecurityUtil.setNamespace(this.elementNonce, this.ns,
                 ConversationConstants.WSC_PREFIX);
         
this.elementNonce.appendChild(this.element.getOwnerDocument().createTextNode(nonce));
         this.element.appendChild(this.elementNonce);
@@ -432,7 +446,7 @@
      *         DerivedKeyToken
      */
     public String getAlgorithm() {
-        String algo = this.element.getAttributeNS(ConversationConstants.WSC_NS,
+        String algo = this.element.getAttributeNS(this.ns,
                 "Algorithm");
         if (algo == null || algo.equals("")) {
             return ConversationConstants.DerivationAlgorithm.P_SHA_1;
@@ -449,10 +463,10 @@
      */
     public void setAlgorithm(String algo) {
         String prefix = WSSecurityUtil.setNamespace(this.element,
-                ConversationConstants.WSC_NS,
+                this.ns,
                 ConversationConstants.
                 WSC_PREFIX);
-        this.element.setAttributeNS(ConversationConstants.WSC_NS,
+        this.element.setAttributeNS(this.ns,
                 prefix + ":Algorithm", algo);
     }
 

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/SecurityContextToken.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/token/SecurityContextToken.java?view=diff&rev=441080&r1=441079&r2=441080
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/SecurityContextToken.java
 (original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/SecurityContextToken.java
 Thu Sep  7 06:09:31 2006
@@ -3,6 +3,7 @@
 import org.apache.ws.security.WSConstants;
 import org.apache.ws.security.WSSecurityException;
 import org.apache.ws.security.conversation.ConversationConstants;
+import org.apache.ws.security.conversation.ConversationException;
 import org.apache.ws.security.util.DOM2Writer;
 import org.apache.ws.security.util.UUIDGenerator;
 import org.apache.ws.security.util.WSSecurityUtil;
@@ -19,10 +20,6 @@
  */
 public class SecurityContextToken {
 
-    public static final QName TOKEN = new QName(ConversationConstants.WSC_NS,
-            ConversationConstants.
-            SECURITY_CONTEXT_TOKEN_LN);
-
     /**
      * Security context token element
      */
@@ -32,21 +29,41 @@
      * Identifier element
      */
     protected Element elementIdentifier = null;
+    
+    /**
+     * Constructor to create the SCT
+     *
+     * @param doc
+     */
+    public SecurityContextToken(Document doc) throws ConversationException {
+        this(ConversationConstants.DEFAULT_VERSION, doc);
+    }
+
+    /**
+     * Constructor to create the SCT with a given uuid
+     *
+     * @param doc
+     */
+    public SecurityContextToken(Document doc, String uuid) throws 
ConversationException {
+        this(ConversationConstants.DEFAULT_VERSION, doc, uuid);
+    }
 
     /**
      * Constructor to create the SCT
      *
      * @param doc
      */
-    public SecurityContextToken(Document doc) {
+    public SecurityContextToken(int version, Document doc) throws 
ConversationException {
 
-        this.element = doc.createElementNS(ConversationConstants.WSC_NS,
+        String ns = ConversationConstants.getWSCNs(version);
+        
+        this.element = doc.createElementNS(ns,
                 "wsc:" + ConversationConstants.SECURITY_CONTEXT_TOKEN_LN);
 
-        WSSecurityUtil.setNamespace(this.element, ConversationConstants.WSC_NS,
+        WSSecurityUtil.setNamespace(this.element,ns,
                 ConversationConstants.WSC_PREFIX);
 
-        this.elementIdentifier = 
doc.createElementNS(ConversationConstants.WSC_NS,
+        this.elementIdentifier = doc.createElementNS(ns,
                 "wsc:" + ConversationConstants.IDENTIFIER_LN);
 
         this.element.appendChild(this.elementIdentifier);
@@ -63,15 +80,17 @@
      *
      * @param doc
      */
-    public SecurityContextToken(Document doc, String uuid) {
+    public SecurityContextToken(int version, Document doc, String uuid) throws 
ConversationException {
 
-        this.element = doc.createElementNS(ConversationConstants.WSC_NS,
+        String ns = ConversationConstants.getWSCNs(version);
+        
+        this.element = doc.createElementNS(ns,
                 "wsc:" + ConversationConstants.SECURITY_CONTEXT_TOKEN_LN);
 
-        WSSecurityUtil.setNamespace(this.element, ConversationConstants.WSC_NS,
+        WSSecurityUtil.setNamespace(this.element, ns,
                 ConversationConstants.WSC_PREFIX);
 
-        this.elementIdentifier = 
doc.createElementNS(ConversationConstants.WSC_NS,
+        this.elementIdentifier = doc.createElementNS(ns,
                 "wsc:" + ConversationConstants.IDENTIFIER_LN);
 
         this.element.appendChild(this.elementIdentifier);
@@ -89,11 +108,16 @@
         this.element = elem;
         QName el = new QName(this.element.getNamespaceURI(),
                 this.element.getLocalName());
-        if (!el.equals(TOKEN)) {    // If the element is not a security 
context token
+
+        if (!el.equals(new QName(ConversationConstants.WSC_NS_05_02, 
ConversationConstants.SECURITY_CONTEXT_TOKEN_LN)) &&
+                !el.equals(new QName(ConversationConstants.WSC_NS_05_12, 
ConversationConstants.SECURITY_CONTEXT_TOKEN_LN))) {    // If the element is 
not a security context token
             throw new 
WSSecurityException(WSSecurityException.INVALID_SECURITY_TOKEN, 
"badTokenType00",
                     new Object[]{el});
         }
-        this.elementIdentifier = (Element) 
WSSecurityUtil.getDirectChild(element, ConversationConstants.IDENTIFIER_LN, 
ConversationConstants.WSC_NS);
+
+        this.elementIdentifier = (Element) WSSecurityUtil.getDirectChild(
+                element, ConversationConstants.IDENTIFIER_LN, el
+                        .getNamespaceURI());
     }
 
     /**

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java?view=diff&rev=441080&r1=441079&r2=441080
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java
 (original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java
 Thu Sep  7 06:09:31 2006
@@ -194,7 +194,8 @@
                 if (el.equals(WSSecurityEngine.usernameToken)) {
                     ut = new UsernameToken(token);
                     secretKey = ut.getSecretKey();
-                } else if(el.equals(WSSecurityEngine.DERIVED_KEY_TOKEN)) {
+                } else if(el.equals(WSSecurityEngine.DERIVED_KEY_TOKEN_05_02) 
||
+                        el.equals(WSSecurityEngine.DERIVED_KEY_TOKEN_05_12)) {
                     dkt = new DerivedKeyToken(token);
                     String id = dkt.getID();
                     DerivedKeyTokenProcessor dktProcessor = 
(DerivedKeyTokenProcessor) wsDocInfo



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to