a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The contents of this file are subject to the terms
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * of the Common Development and Distribution License
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * (the License). You may not use this file except in
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * compliance with the License.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * You can obtain a copy of the License at
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * See the License for the specific language governing
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * permission and limitations under the License.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * When distributing Covered Code, include this CDDL
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Header Notice in each file and include the License file
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * If applicable, add the following below the CDDL Header,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * with the fields enclosed by brackets [] replaced by
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * your own identifying information:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * $Id: StatusCodeImpl.java,v 1.2 2008/06/25 05:48:00 qcheng Exp $
07e35e8870f0a772252336889d391265a5485e4eSachiko Wallace * Portions copyright 2014 ForgeRock AS.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml2.common.SAML2Constants;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml2.common.SAML2Exception;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml2.common.SAML2SDKUtils;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml2.protocol.StatusCode;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml2.protocol.ProtocolFactory;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * This class defines methods for <code>StatusCode</code> element.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterpublic class StatusCodeImpl implements StatusCode {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructs the <code>StatusCode</code> Object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructs the <code>StatusCode</code> Object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param element the Document Element of <code>StatusCode</code> object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws SAML2Exception if <code>StatusCode</code> cannot be created.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public StatusCodeImpl(Element element) throws SAML2Exception {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructs the <code>StatusCode</code> Object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param xmlString the XML String representation of this object.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws SAML2Exception if <code>StatusCode</code> cannot be created.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public StatusCodeImpl(String xmlString) throws SAML2Exception {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster XMLUtils.toDOMDocument(xmlString,SAML2SDKUtils.debug);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAML2SDKUtils.bundle.getString("errorObtainingElement"));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster parseElement(xmlDocument.getDocumentElement());
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns the value of the statusCode property.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return the value of the statusCode property
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @see #setStatusCode(StatusCode)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Sets the value of the statusCode property.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param value the value of the statusCode property to be set
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws SAML2Exception if the object is immutable
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @see #getStatusCode
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public void setStatusCode(StatusCode value) throws SAML2Exception {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAML2SDKUtils.bundle.getString("objectImmutable"));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns the status code value of the value property.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return the value of the value property
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @see #setValue(String)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Sets the status code value of the value property.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param value the value of the value property to be set
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @exception SAML2Exception if the object is immutable
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @see #getValue
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public void setValue(java.lang.String value) throws SAML2Exception {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAML2SDKUtils.bundle.getString("objectImmutable"));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns the <code>StatusCode</code> in an XML document String format
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * based on the <code>StatusCode</code> schema described above.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return An XML String representing the <code>StatusCode</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws SAML2Exception if some error occurs during conversion to
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code>String</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public String toXMLString() throws SAML2Exception {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return toXMLString(true,false);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns the <code>StatusCode</code> in an XML document String format
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * based on the <code>StatusCode</code> schema described above.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param includeNSPrefix Determines whether or not the namespace qualifier
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * is prepended to the Element when converted
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param declareNS Determines whether or not the namespace is declared
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * within the Element.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return A XML String representing the <code>StatusCode</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws SAML2Exception if some error occurs during conversion to
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code>String</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public String toXMLString(boolean includeNSPrefix,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((statusCodeValue != null) && (statusCodeValue.length() != 0)) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster StringBuffer xmlString = new StringBuffer(500);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster xmlString.append(SAML2Constants.PROTOCOL_PREFIX);
07e35e8870f0a772252336889d391265a5485e4eSachiko Wallace xmlString.append(SAML2Constants.STATUS_CODE);
07e35e8870f0a772252336889d391265a5485e4eSachiko Wallace xmlString.append(SAML2Constants.PROTOCOL_DECLARE_STR);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster .append(statusCode.toXMLString(includeNSPrefix,declareNS));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Makes this object immutable.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((statusCode != null) && (statusCode.isMutable())) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns value true if object is mutable.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return true if object is mutable.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* Parses the <code>StatusCode</code> Element. */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster private void parseElement(Element element) throws SAML2Exception {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ProtocolFactory protoFactory = ProtocolFactory.getInstance();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster statusCodeValue = element.getAttribute(SAML2Constants.VALUE);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((nList != null) && (nList.getLength() > 0)) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (cName.equals(SAML2Constants.STATUS_CODE)) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster protoFactory.createStatusCode((Element)childNode);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* validates the required attribute Value */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster void validateStatusCodeValue(String statusCodeValue) throws SAML2Exception {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((statusCodeValue == null) || (statusCodeValue.length() == 0)) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAML2SDKUtils.debug.message("statusCodeValue is required");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAML2SDKUtils.bundle.getString("missingStatusCodeValue"));