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: IDPProvidedNameIdentifier.java,v 1.2 2008/06/25 05:46:47 qcheng Exp $
026 * Portions Copyrighted 2014 ForgeRock AS
027 */
028
029package com.sun.identity.federation.message.common;
030
031import com.sun.identity.federation.common.FSUtils;
032import com.sun.identity.federation.common.IFSConstants;
033import com.sun.identity.saml.assertion.NameIdentifier;
034import com.sun.identity.saml.common.SAMLException;
035import com.sun.identity.shared.xml.XMLUtils;
036import org.w3c.dom.Element;
037
038/**
039 * This class has methods to create the <code>NameIdentifier</code>
040 * object provided by the Identity Provider.
041 *
042 * @supported.all.api
043 * @deprecated since 12.0.0
044 */
045@Deprecated
046public class IDPProvidedNameIdentifier extends NameIdentifier {
047
048    protected int minorVersion = IFSConstants.FF_11_PROTOCOL_MINOR_VERSION;
049
050    /**
051     * Constructor creates <code>IDPProvidedNameIdentifier</code> object.
052     *
053     * @param name the Identity Provider name.
054     * @param nameQualifier 
055     * @param format
056     * @throws SAMLException on error.
057     */
058    public IDPProvidedNameIdentifier(String name,String nameQualifier,
059            String format) throws SAMLException {                
060                super(name, nameQualifier, format);                
061        }
062    
063    /**
064     * Constructor creates <code>IDPProvidedNameIdentifier</code> object
065     * from Document Element.
066     *
067     * @param idpProvidedNameIdentifierElement the Document Element.
068     * @throws FSMsgException on error.
069     */
070    public IDPProvidedNameIdentifier(Element idpProvidedNameIdentifierElement)
071                                     throws FSMsgException {
072        FSUtils.debug.message("IDPProvidedNameIdentifier(Element):  Called");
073        Element elt = (Element) idpProvidedNameIdentifierElement;
074        String eltName = elt.getLocalName();
075        if (eltName == null)  {
076            if (FSUtils.debug.messageEnabled()) {
077                FSUtils.debug.message("IDPProvidedNameIdentifier(Element): "
078                        + "local name missing");
079            }
080            throw new FSMsgException("nullInput",null) ;
081        }
082        if (!(eltName.equals("IDPProvidedNameIdentifier")))  {
083            if (FSUtils.debug.messageEnabled()) {
084                FSUtils.debug.message("IDPProvidedNameIdentifier(Element: "
085                        + "invalid root element");
086            }
087            throw new FSMsgException("invalidElement",null) ;
088        }
089        String read = elt.getAttribute("NameQualifier");
090        if (read != null) {
091            setNameQualifier(read);
092        }
093        read = elt.getAttribute("Format");
094        if (read != null) {
095            setFormat(read);
096        }
097        read = XMLUtils.getElementValue(elt);
098        if ((read == null) || (read.length() == 0)) {
099            if (FSUtils.debug.messageEnabled()) {
100                FSUtils.debug.message("IDPProvidedNameIdentifier(Element: "
101                        + "null input specified");
102            }
103            throw new FSMsgException("nullInput",null) ;
104        } else {
105            setName(read);
106        }
107    }
108    
109    /**
110     * Constructor creates <code> IDPProvidedNameIdentifier</code> object.
111     *
112     * @param securityDomain
113     * @param name
114     * @throws FSMsgException on error.
115     */
116    public IDPProvidedNameIdentifier(
117            String securityDomain, String name
118            ) throws FSMsgException {
119        if (name== null || name.length() == 0 )  {
120            if (FSUtils.debug.messageEnabled()) {
121                FSUtils.debug.message("IDPProvidedNameIdentifier: "
122                        + "null input specified");
123            }
124            throw new FSMsgException("nullInput",null) ;
125        }
126        setName(name);
127        if(securityDomain==null)
128            setNameQualifier("");
129        else
130            setNameQualifier(securityDomain);
131    }
132       
133    /**
134     * Sets the <code>MinorVersion</code> attribute.
135     *
136     * @param version the <code>MinorVersion</code> attribute.
137     * @see #getMinorVersion()
138     */
139    public void setMinorVersion(int version) {
140        minorVersion = version;
141    }
142        
143    /**
144     * Returns the <code>MinorVersion</code> attribute.
145     *
146     * @return the <code>MinorVersion</code> attribute.
147     * @see #setMinorVersion(int)
148     */
149    public int getMinorVersion() {
150        return minorVersion;
151    }
152    
153    /**
154     * Returns the string representation of this object.
155     *
156     * @return a string containing the valid <code>XML</code> for this element
157     * @throws FSMsgException if there is an error creating
158     *         <code>XML</code> string from this object.
159     */
160    public String toXMLString() throws FSMsgException {
161        String xml = this.toXMLString(true, false);
162        return xml;
163    }
164    /**
165     * Returns the string representation of this object.
166     *
167     * @param includeNS determines whether or not the namespace qualifier
168     *        is prepended to the Element when converted
169     * @param declareNS : Determines whether or not the namespace is declared
170     *        within the Element.
171     * @return a string containing the valid <code>XML</code> for this element
172     * @throws FSMsgException if there is an error creating
173     *         <code>XML</code> string from this object.
174     */
175    public String  toXMLString(
176            boolean includeNS, boolean declareNS
177            ) throws FSMsgException {
178        StringBuffer xml = new StringBuffer(3000);
179        String NS="";
180        String appendNS="";
181        if (declareNS) {
182            if(minorVersion == IFSConstants.FF_12_PROTOCOL_MINOR_VERSION) {
183                NS = IFSConstants.LIB_12_NAMESPACE_STRING;
184            } else {
185                NS=IFSConstants.LIB_NAMESPACE_STRING;
186            }
187        }
188        if (includeNS) appendNS=IFSConstants.LIB_PREFIX;
189        xml.append("<").append(appendNS).append("IDPProvidedNameIdentifier").
190                append(" ").append(NS).append(" ");
191        if ((getNameQualifier() != null) && 
192                     (!(getNameQualifier().length() == 0))) {
193            xml.append("NameQualifier").append("=\"")
194               .append(getNameQualifier())
195               .append("\"").append(" ");
196        }
197        if ((getFormat() != null) && (!(getFormat().length() == 0))) {
198            xml.append("Format").append("=\"").append(getFormat())
199               .append("\"").append(" ");
200        }
201        if ((getName() != null) && (!(getName().length() == 0))) {
202            xml.append(">").append(getName());
203            xml.append("</").append(appendNS)
204               .append("IDPProvidedNameIdentifier").append(">\n");
205        }
206           return xml.toString();
207    }    
208}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.