001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: ConsentHeader.java,v 1.2 2008/06/25 05:47:22 qcheng Exp $
026 *
027 */
028
029
030package com.sun.identity.liberty.ws.soapbinding; 
031
032import com.sun.identity.shared.DateUtils;
033import com.sun.identity.shared.xml.XMLUtils;
034import com.sun.identity.saml.common.SAMLUtils;
035
036import java.text.ParseException;
037
038import java.util.Date;
039
040import org.w3c.dom.Document;
041import org.w3c.dom.Element;
042
043/**
044 * The <code>ConsentHeader</code> class represents <code>Consent</code> element
045 * defined in SOAP binding schema.
046 *
047 * @supported.all.api
048 */
049public class ConsentHeader {   
050
051    private String uri = null;
052    private Date timestamp = null;
053    private String id = null;
054    private Boolean mustUnderstand = null;
055    private String actor = null;
056
057    /**
058     * Constructor
059     *
060     * @param uri the Consent URI .
061     */
062    public ConsentHeader(String uri) {
063        this.uri = uri;
064    }
065
066    /**
067     * Constructor
068     *
069     * @param consentElement the Document Element.
070     * @throws SOAPBindingException if an error occurs while parsing
071     *                                 the Consent element
072     */
073    ConsentHeader(Element consentElement) throws SOAPBindingException {
074        uri = XMLUtils.getNodeAttributeValue(
075            consentElement, SOAPBindingConstants.ATTR_URI);
076        id = XMLUtils.getNodeAttributeValue(
077            consentElement, SOAPBindingConstants.ATTR_id);
078        String str = XMLUtils.getNodeAttributeValueNS(
079            consentElement,SOAPBindingConstants.NS_SOAP,
080            SOAPBindingConstants.ATTR_MUSTUNDERSTAND);
081        if (str != null && str.length() > 0) {
082            try {
083                mustUnderstand = Utils.StringToBoolean(str);
084            } catch (Exception pe) {
085                String msg = Utils.bundle.getString("invalidMustUnderstand");
086                Utils.debug.error("ConsentHeader: " + msg, pe);
087                throw new SOAPBindingException(msg);
088            }
089        }
090
091        str = XMLUtils.getNodeAttributeValue(
092                                     consentElement,
093                                     SOAPBindingConstants.ATTR_TIMESTAMP);
094        if (str != null && str.length() > 0) {
095            try {
096                timestamp = DateUtils.stringToDate(str);
097            } catch (ParseException pe) {
098                String msg = Utils.bundle.getString("invalidTimestamp");
099                Utils.debug.error("ConsentHeader: " + msg, pe);
100                throw new SOAPBindingException(msg);
101            }
102        }
103        actor = XMLUtils.getNodeAttributeValueNS(
104                                              consentElement,
105                                              SOAPBindingConstants.NS_SOAP,
106                                              SOAPBindingConstants.ATTR_ACTOR);
107    }
108
109    /**
110     * Returns value of <code>uri</code> attribute.
111     *
112     * @return value of <code>uri</code> attribute.
113     */
114    public String getUri() {
115        return uri;
116    }
117
118    /**
119     * Returns value of <code>timestamp</code> attribute.
120     *
121     * @return value of <code>timestamp</code> attribute
122     */
123    public Date getTimestamp() {
124        return timestamp;
125    }
126
127    /**
128     * Returns value of <code>id</code> attribute.
129     *
130     * @return value of <code>id</code> attribute.
131     */
132    public String getId() {
133        return id;
134    }
135
136    /**
137     * Returns value of </code>mustUnderstand</code> attribute.
138     * @return value of </code>mustUnderstand</code> attribute
139     */
140    public Boolean getMustUnderstand() {
141        return mustUnderstand;
142    }
143
144    /**
145     * Returns value of <code>actor</code> attribute.
146     * @return value of <code>actor</code> attribute
147     */
148    public String getActor() {
149        return actor;
150    }
151
152    /**
153     * Sets value of <code>uri</code> attribute.
154     *
155     * @param uri value of <code>uri</code> attribute
156     */
157    public void setUri(String uri) {
158        this.uri = uri;
159    }
160
161    /**
162     * Sets value of <code>mustUnderstand</code> attribute.
163     *
164     * @param mustUnderstand value of <code>mustUnderstand</code> attribute.
165     */
166    public void setMustUnderstand(Boolean mustUnderstand) {
167        this.mustUnderstand = mustUnderstand;
168    }
169
170    /**
171     * Sets value of <code>actor</code> attribute.
172     *
173     * @param actor value of <code>actor</code> attribute
174     */
175    public void setActor(String actor) {
176        this.actor = actor;
177    }
178
179    /**
180     * Sets the value of the signFlag. The default value is
181     * false.
182     *
183     * @param signFlag the boolean value.
184     */
185    public void setSignFlag(boolean signFlag) {
186        if (signFlag) {
187            id = SAMLUtils.generateID();
188        } else {
189            id = null;
190        }
191    }
192
193    /**
194     * Converts this header to <code>org.w3c.dom.Element</code> and add to
195     * parent Header Element.
196     *
197     * @param headerE parent Header Element
198     */
199    void addToParent(Element headerE) {
200        Document doc = headerE.getOwnerDocument();
201        Element consentHeaderE = doc.createElementNS(
202                SOAPBindingConstants.NS_SOAP_BINDING,
203                SOAPBindingConstants.PTAG_CONSENT);
204        headerE.appendChild(consentHeaderE);
205        
206        consentHeaderE.setAttributeNS(null, SOAPBindingConstants.ATTR_URI,uri);
207        
208        if (timestamp != null) {
209            consentHeaderE.setAttributeNS(null,
210                    SOAPBindingConstants.ATTR_TIMESTAMP,
211                    DateUtils.toUTCDateFormat(timestamp));
212        }
213        if (id != null) {
214            consentHeaderE.setAttributeNS(null, SOAPBindingConstants.ATTR_id,
215                    id);
216        }
217        if (mustUnderstand != null) {
218            consentHeaderE.setAttributeNS(SOAPBindingConstants.NS_SOAP,
219                    SOAPBindingConstants.PATTR_MUSTUNDERSTAND,
220                    Utils.BooleanToString(mustUnderstand));
221        }
222        if (actor != null) {
223            consentHeaderE.setAttributeNS(SOAPBindingConstants.NS_SOAP,
224                    SOAPBindingConstants.PATTR_ACTOR,
225                    actor);
226        }
227    }
228}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.