You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by we...@apache.org on 2005/09/06 20:32:27 UTC

svn commit: r279056 - /webservices/wss4j/trunk/src/org/apache/ws/security/message/token/SignatureConfirmation.java

Author: werner
Date: Tue Sep  6 11:32:22 2005
New Revision: 279056

URL: http://svn.apache.org/viewcvs?rev=279056&view=rev
Log:
First iplementation of the SignatureCOnfirmation feature of WSS 1.1.

Added:
    webservices/wss4j/trunk/src/org/apache/ws/security/message/token/SignatureConfirmation.java

Added: webservices/wss4j/trunk/src/org/apache/ws/security/message/token/SignatureConfirmation.java
URL: http://svn.apache.org/viewcvs/webservices/wss4j/trunk/src/org/apache/ws/security/message/token/SignatureConfirmation.java?rev=279056&view=auto
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/message/token/SignatureConfirmation.java (added)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/message/token/SignatureConfirmation.java Tue Sep  6 11:32:22 2005
@@ -0,0 +1,134 @@
+/*
+ * Copyright  2003-2004 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.ws.security.message.token;
+
+import org.apache.ws.security.WSConstants;
+import org.apache.ws.security.WSSecurityException;
+import org.apache.ws.security.util.DOM2Writer;
+import org.apache.ws.security.util.WSSecurityUtil;
+import org.apache.xml.security.exceptions.Base64DecodingException;
+import org.apache.xml.security.utils.Base64;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+
+/**
+ * Signature Confirmation element.
+ *
+ *
+ * @author Werner Dittmann (Werner.Dittmann@t-online.de)
+ */
+public class SignatureConfirmation {
+
+    private static final String VALUE = "Value"; 
+    protected Element element = null;
+    private byte[] signatureValue = null;
+    /**
+     * Constructs a <code>SignatureConfirmation</code> object and parses the
+     * <code>wsse11:SignatureCOnfirmation</code> element to initialize it.
+     *
+     * @param elem the <code>wsse11:SignatureCOnfirmation</code> element that
+     *             contains the confirmation data
+     */
+    public SignatureConfirmation(Element elem) throws WSSecurityException {
+
+        element = elem;
+        String sv = element.getAttributeNS(null, VALUE);
+        if (sv != null) {
+            try {
+                signatureValue = Base64.decode(sv);
+            } catch (Base64DecodingException e) {
+                throw new WSSecurityException(WSSecurityException.FAILURE,
+                        null,
+                        null,
+                        e);
+            }
+        }
+    }
+
+    /**
+     * Constructs a <code>SignatureConfirmation</code> object according
+     * to the defined parameters.
+     * <p/>
+     *
+     * @param doc the SOAP envelope as <code>Document</code>
+     * @param the Signature value as byte[] of <code>null</code> if no value
+     *        available.
+     */
+    public SignatureConfirmation(Document doc, byte[] signVal) {
+
+        element =
+                doc.createElementNS(WSConstants.WSSE11_NS,
+                        WSConstants.WSSE11_PREFIX
+                + ":"
+                + WSConstants.SIGNATURE_CONFIRMATION_LN);
+        WSSecurityUtil.setNamespace(element,
+                WSConstants.WSSE11_NS,
+                WSConstants.WSSE11_PREFIX);
+        if (signVal != null) {
+            String sv = Base64.encode(signVal,0);
+            element.setAttribute(VALUE, sv);
+        }
+
+    }
+
+    /**
+     * Returns the dom element of this <code>Timestamp</code> object.
+     *
+     * @return the <code>wsse:UsernameToken</code> element
+     */
+    public Element getElement() {
+        return this.element;
+    }
+
+    /**
+     * Returns the string representation of the token.
+     *
+     * @return a XML string representation
+     */
+    public String toString() {
+        return DOM2Writer.nodeToString((Node) this.element);
+    }
+    
+    /**
+     * Set wsu:Id attribute of this timestamp
+     * @param id
+     */
+    public void setID(String id) {
+        String prefix = WSSecurityUtil.setNamespace(this.element,
+                WSConstants.WSU_NS, WSConstants.WSU_PREFIX);
+        this.element.setAttributeNS(WSConstants.WSU_NS, prefix + ":Id", id);
+    }
+    
+    /**
+     * Returns the value of the wsu:Id attribute
+     * @return
+     */
+    public String getID() {
+        return this.element.getAttributeNS(WSConstants.WSU_NS, "Id");
+    }
+
+    /**
+     * @return Returns the signatureValue.
+     */
+    public byte[] getSignatureValue() {
+        return signatureValue;
+    }
+    
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: wss4j-dev-help@ws.apache.org