001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the License). You may not use this file except in
005: * compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * Header Notice in each file and include the License file
014: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
015: * If applicable, add the following below the CDDL Header,
016: * with the fields enclosed by brackets [] replaced by
017: * you own identifying information:
018: * "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
021: */
022:
023: /*
024: * SignatureConfirmationHeaderblock.java
025: *
026: * Created on January 20, 2006, 5:14 PM
027: *
028: * To change this template, choose Tools | Template Manager
029: * and open the template in the editor.
030: */
031:
032: package com.sun.xml.wss.core;
033:
034: import com.sun.xml.wss.impl.misc.SecurityHeaderBlockImpl;
035: import com.sun.xml.wss.impl.XMLUtil;
036: import com.sun.xml.wss.impl.MessageConstants;
037:
038: import org.w3c.dom.Node;
039: import org.w3c.dom.Attr;
040:
041: import javax.xml.soap.SOAPElement;
042: import javax.xml.soap.SOAPException;
043: import javax.xml.soap.Name;
044: import javax.xml.soap.SOAPFactory;
045:
046: import com.sun.xml.wss.XWSSecurityException;
047:
048: import java.util.Iterator;
049:
050: /**
051: * wsse11:SignatureConfirmation
052: *
053: * @author ashutosh.shahi@sun.com
054: */
055: public class SignatureConfirmationHeaderBlock extends
056: SecurityHeaderBlockImpl {
057:
058: private String signatureValue = null;
059: private String wsuId = null;
060:
061: /** Creates a new instance of SignatureConfirmationHeaderblock */
062: public SignatureConfirmationHeaderBlock(String wsuId,
063: String signatureValue) {
064: this .wsuId = wsuId;
065: this .signatureValue = signatureValue;
066: }
067:
068: public SignatureConfirmationHeaderBlock(SOAPElement element)
069: throws XWSSecurityException {
070:
071: if (!(MessageConstants.SIGNATURE_CONFIRMATION_LNAME
072: .equals(element.getLocalName()) && XMLUtil
073: .inWsse11NS(element))) {
074: throw new XWSSecurityException(
075: "Invalid SignatureConfirmation Header Block passed");
076: }
077:
078: setSOAPElement(element);
079:
080: String wsuId = getAttributeNS(MessageConstants.WSU_NS, "Id");
081: if (!"".equals(wsuId))
082: setId(wsuId);
083:
084: String signatureValue = getAttribute("Value");
085: try {
086: if (!"".equals(signatureValue)) {
087: setSignatureValue(signatureValue);
088: }
089: } catch (Exception ex) {
090: throw new XWSSecurityException(ex);
091: }
092:
093: Iterator children = getChildElements();
094: Node object = null;
095:
096: while (children.hasNext()) {
097:
098: object = (Node) children.next();
099: if (object.getNodeType() == Node.ELEMENT_NODE) {
100: throw new XWSSecurityException(
101: "Child Element Nodes not allowed inside SignatureConfirmation");
102: } else if (object.getNodeType() == Node.ATTRIBUTE_NODE) {
103: Attr attr = (Attr) object;
104: if (!(("Id".equals(attr.getLocalName()) && MessageConstants.WSU_NS
105: .equals(attr.getNamespaceURI())) || "Value"
106: .equals(attr.getLocalName()))) {
107: throw new XWSSecurityException("The attribute "
108: + attr.getLocalName()
109: + "not allowed in SignatureConfirmation");
110: }
111: }
112: }
113: }
114:
115: public SignatureConfirmationHeaderBlock(String wsuId) {
116:
117: this .wsuId = wsuId;
118: }
119:
120: public static SecurityHeaderBlock fromSoapElement(
121: SOAPElement element) throws XWSSecurityException {
122: return SecurityHeaderBlockImpl.fromSoapElement(element,
123: SignatureConfirmationHeaderBlock.class);
124: }
125:
126: public SOAPElement getAsSoapElement() throws XWSSecurityException {
127:
128: SOAPElement signConfirm;
129:
130: try {
131: SOAPFactory sFactory = getSoapFactory();
132: signConfirm = sFactory.createElement(
133: MessageConstants.SIGNATURE_CONFIRMATION_LNAME,
134: MessageConstants.WSSE11_PREFIX,
135: MessageConstants.WSSE11_NS);
136:
137: signConfirm.addNamespaceDeclaration(
138: MessageConstants.WSSE11_PREFIX,
139: MessageConstants.WSSE11_NS);
140:
141: try {
142: if (signatureValue != null) {
143: Name name = sFactory.createName("Value");
144: signConfirm.addAttribute(name, signatureValue);
145: }
146: } catch (Exception ex) {
147: throw new XWSSecurityException(ex);
148: }
149: if (wsuId != null) {
150: Name name = sFactory.createName("Id",
151: MessageConstants.WSU_PREFIX,
152: MessageConstants.WSU_NS);
153: signConfirm.addAttribute(name, wsuId);
154: }
155: } catch (SOAPException se) {
156: throw new XWSSecurityException(
157: "There was an error creating Signature Confirmation "
158: + se.getMessage());
159: }
160:
161: setSOAPElement(signConfirm);
162:
163: return signConfirm;
164: }
165:
166: public String getId() {
167: return this .wsuId;
168: }
169:
170: public void setId(String wsuId) {
171: this .wsuId = wsuId;
172: }
173:
174: public String getSignatureValue() {
175: return this .signatureValue;
176: }
177:
178: public void setSignatureValue(String signatureValue) {
179: this.signatureValue = signatureValue;
180: }
181:
182: }
|