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: AbstractRequest.java,v 1.2 2008/06/25 05:47:36 qcheng Exp $
026 *
027 */
028
029
030package com.sun.identity.saml.protocol;
031
032import com.sun.identity.saml.common.SAMLConstants;
033import com.sun.identity.saml.common.SAMLException;
034
035import java.util.ArrayList;
036import java.util.Collections;
037import java.util.Date;
038import java.util.List;
039
040import org.w3c.dom.Element;
041
042/**
043 * This <code>AbstractRequest</code> class is an abstract base class for all
044 * SAML Request in <code>samlp</code> namespace. It corresponds to
045 * <code>RequestAbstractType</code> in SAML protocol schema.
046 *
047 * @supported.all.api
048 */
049public abstract class AbstractRequest {
050
051    /*
052     * data members
053     */
054
055    protected List      respondWiths    = Collections.EMPTY_LIST;
056    protected Element   signature       = null;
057    protected String    requestID       = null;
058    protected int       majorVersion    = SAMLConstants.PROTOCOL_MAJOR_VERSION;
059    protected int       minorVersion    = SAMLConstants.PROTOCOL_MINOR_VERSION;
060    protected Date      issueInstant    = null;
061    protected boolean   signed          = false;
062    protected boolean   valid           = true;
063
064    /*
065     * Default constructor.
066     */
067    protected AbstractRequest() {
068    }
069
070    /**
071     * Return whether the object is signed or not.
072     *
073     * @return true if the object is signed; false otherwise.
074     */
075    public boolean isSigned() {
076        return signed;
077    }
078
079    /**
080     * Return whether the signature on the object is valid or not.
081     * @return true if the signature is valid; false otherwise.
082     */
083    public boolean isSignatureValid() {
084        return valid;
085    }
086
087    /**
088     *  An abstract method to sign the object.
089     *
090     *  @throws SAMLException If could not sign the object.
091     */
092    public abstract void signXML() throws SAMLException;
093
094    /**
095     * Gets 0 or more of <code>RespondWith</code> in the Request.
096     *
097     * @return A List of Strings.
098     */
099    public List getRespondWith() {
100        return respondWiths;
101    }
102
103    /**
104     * Adds a <code>RespondWith</code> to the Request.
105     *
106     * @param respondWith A String that needs to be added to the Request.
107     * @return true if the operation is successful.
108     */
109    public boolean addRespondWith(String respondWith) {
110        if (signed) {
111            return false;
112        }
113        if ((respondWith == null) || (respondWith.length() == 0)) {
114            return false;
115        } else {
116            if ((respondWiths == null) ||
117                (respondWiths == Collections.EMPTY_LIST)) {
118                respondWiths = new ArrayList();
119            }
120            respondWiths.add(respondWith);
121            return true;
122        }
123    }
124
125    /**
126     * Gets 0 or 1 of Signature in the Request.
127     * @return The signature Element the Request contains. It returns null if
128     *          the Request has no signature.
129     */
130    public Element getSignature() {
131        return signature;
132    }
133
134    /**
135     * Set the signature for the Request 
136     * @param elem <code>ds:Signature</code> element
137     * @return true if the operation succeeds.
138     */
139    public boolean setSignature(Element elem) {
140        if (signed) {
141            return false;
142        }
143        if (elem == null) {
144            return false;
145        } else {
146            signature = elem;
147            signed = true;
148            return true;
149        }
150    }
151
152    /**
153     * Gets the <code>RequestID</code> of the Request.
154     * @return the <code>RequestID</code> of the Request.
155     */
156    public String getRequestID() {
157        return requestID;
158    }
159
160    /**
161     * Set the <code>RequestID</code> of the Request.
162     * @param requestID A String that is the <code>RequestID</code> attribute of
163     *        the Request.
164     * @return true if the operation is successful.
165     */
166    public boolean setRequestID(String requestID) {
167        if (signed) {
168            return false;
169        }
170        if ((requestID == null) || (requestID.length() == 0)) {
171            return false;
172        }
173        this.requestID = requestID;
174        return true;
175    }
176
177    /**
178     * Returns the <code>MajorVersion</code> of the Request.
179     *
180     * @return The <code>MajorVersion</code> of the Request.
181     */
182    public int getMajorVersion() {
183        return majorVersion;
184    }
185
186    /**
187     * Returns the <code>MinorVersion</code> of the Request.
188     *
189     * @return The <code>MinorVersion</code> of the request.
190     */
191    public int getMinorVersion() {
192        return minorVersion;
193    }
194    
195    /**
196     * Sets the <code>MajorVersion</code> of the Request.
197     *
198     * @param majorVersion the intended major version for SAML Request
199     */
200    public void setMajorVersion(int majorVersion) {
201        this.majorVersion = majorVersion;
202    }
203
204    /**
205     * Sets the <code>MinorVersion</code> of the Request.
206     *
207     * @param minorVersion the intended minor version for SAML Request
208     */
209    public void setMinorVersion(int minorVersion) {
210        this.minorVersion = minorVersion;
211    }
212
213    /**
214     * Returns the <code>IssueInstant</code> of the Request.
215     *
216     * @return the <code>IssueInstant</code> of the Request.
217     */
218    public Date getIssueInstant() {
219        return issueInstant;
220    }
221
222    /**
223     * Set the <code>IssueInstant</code> of the Request.
224     *
225     * @param issueInstant a Date object representing the time when the Request
226     *        is issued.
227     * @return true if the operation succeeds.
228     */
229    public boolean setIssueInstant(Date issueInstant) {
230        if (signed) {
231            return false;
232        }
233        if (issueInstant == null) {
234            return false;
235        }
236        this.issueInstant = issueInstant;
237        return true;
238   }
239}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.