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: IDPEntry.java,v 1.2 2008/06/25 05:46:47 qcheng Exp $
026 * Portions Copyrighted 2014 ForgeRock AS
027 */
028
029
030package com.sun.identity.federation.message.common;
031
032import org.w3c.dom.Element;
033import org.w3c.dom.Node;
034import org.w3c.dom.NodeList;
035
036import com.sun.identity.shared.xml.XMLUtils;
037import com.sun.identity.saml.common.SAMLUtils;
038import com.sun.identity.federation.common.FSUtils;
039import com.sun.identity.federation.common.IFSConstants;
040
041/**
042 * This class defines methods to set/retrieve single identity provider
043 * information trusted by the request issuer to authenticate the presenter.
044 *
045 * @supported.all.api
046 * @deprecated since 12.0.0
047 */
048@Deprecated
049
050public class IDPEntry {
051    public static final int LIB_TYPE_IDP = 0;
052    public static final int LIB_TYPE_BROKER = 1;
053    
054    private String providerID = null;
055    private String providerName = null;
056    private String location = null;
057    
058    /**
059     * Default Constructor.
060     */
061    public IDPEntry() {
062    }
063    
064    /**
065     * Constructor creates <code>IDPEntry</code> object.
066     *
067     * @param providerID the Identity Provider identifier.
068     * @param providerName the Identity Provider name.
069     * @param location
070     */
071    public IDPEntry(String providerID,String providerName,String location) {
072        this.providerID = providerID;
073        this.providerName = providerName;
074        this.location = location;
075    }
076    
077    /**
078     * Returns the value of <code>ProviderID</code> attribute.
079     *
080     * @return the value of <code>ProviderID</code> attribute.
081     * @see #setProviderID(String)
082     */
083    
084    public String getProviderID() {
085        return providerID;
086    }
087    
088    /**
089     * Sets the value of <code>ProviderID</code> attribute.
090     *
091     * @param providerID the value of <code>ProviderID</code> attribute.
092     * @see #getProviderID
093     */
094    public void setProviderID(String providerID) {
095        this.providerID = providerID;
096    }
097    
098    /**
099     * Returns the Identity Provider Name.
100     *
101     * @return the Identity Provider Name.
102     * @see #setProviderName(String)
103     */
104    public String getProviderName() {
105        return providerName;
106    }
107    
108    /**
109     * Sets the Identity Provider Name.
110     *
111     * @param providerName the Identity Provider Name.
112     * @see #getProviderName
113     */
114    public void setProviderName(String providerName) {
115        this.providerName = providerName;
116    }
117    
118    /**
119     * Returns the location URI of the Identity Provider.
120     *
121     * @return the location URI of the Identity Provider.
122     * @see #setLocation(String)
123     */
124    public String getLocation() {
125        return location;
126    }
127    
128    /**
129     * Sets the location URI of the Identity Provider.
130     *
131     * @param location the location URI of the Identity Provider.
132     * @see #getLocation
133     */
134    public void setLocation(String location) {
135        this.location = location;
136    }
137    
138    /**
139     * Returns the string representation of this object.
140     * This method translates the response to an XML document string.
141     *
142     * @return An XML String representing the response. NOTE: this is a
143     *         complete SAML response xml string with ResponseID,
144     *         MajorVersion, etc.
145     */
146    
147    public String toXMLString() throws FSMsgException {
148        return toXMLString(true, true);
149    }
150    
151    /**
152     * Returns a String representation of this object.
153     *
154     * @param includeNS  Determines whether or not the namespace qualifier
155     *        is prepended to the Element when converted
156     * @param declareNS Determines whether or not the namespace is declared
157     *        within the Element.
158     * @return a string containing the valid XML for this element
159     * @throws FSMsgException if there is an error converting
160     *         this object ot a string.
161     */
162    
163    public String toXMLString(boolean includeNS,boolean declareNS)
164    throws FSMsgException {
165        return toXMLString(includeNS, declareNS, false);
166    }
167    /**
168     * Returns a String representation of this object.
169     *
170     * @param includeNS Determines whether or not the namespace qualifier
171     *        is prepended to the Element when converted
172     * @param declareNS Determines whether or not the namespace is declared
173     *        within the Element.
174     * @param includeHeader Determines whether the output include the xml
175     *        declaration header.
176     * @return a string containing the valid XML for this element
177     * @throws FSMsgException if there is an error converting
178     *         this object ot a string.
179     */
180    
181    public String toXMLString(boolean includeNS,boolean declareNS,
182            boolean includeHeader) throws FSMsgException {
183        StringBuffer xml = new StringBuffer(300);
184        if (includeHeader) {
185            xml.append("<?xml version=\"1.0\" encoding=\"").
186                    append(IFSConstants.DEFAULT_ENCODING).append("\" ?>\n");
187        }
188        String prefix = "";
189        String uri = "";
190        if (includeNS) {
191            prefix = IFSConstants.LIB_PREFIX;
192        }
193        if (declareNS) {
194            uri = IFSConstants.LIB_NAMESPACE_STRING;
195        }
196        
197        xml.append("<").append(prefix).append("IDPEntry").append(uri).
198                append(">\n");
199        
200        if(providerID != null){
201            xml.append("<").append(prefix).append("ProviderID").append(">")
202                    .append(providerID)
203                    .append("</").append(prefix).append("ProviderID")
204                    .append(">\n");
205        }
206        
207        if(providerName != null){
208            xml.append("<").append(prefix).append("ProviderName").append(">")
209                    .append(providerName)
210                    .append("</").append(prefix).append("ProviderName")
211                    .append(">\n");
212        }
213        
214        if(location != null){
215            xml.append("<").append(prefix).append("Loc").append(">").
216                    append(location).
217                    append("</").append(prefix).append("Loc").append(">\n");
218        }
219        
220        xml.append("</").append(prefix).append("IDPEntry").append(">\n");
221        
222        return xml.toString();
223    }
224    
225    /**
226     * Constructor creates <code>IDPEntry</code> Object from
227     * Document Element.
228     *
229     * @param root Document Element of <code>IDPEntry<code> object.
230     * @throws FSMsgException if <code>IDPEntry<code> cannot be created.
231     */
232    
233    public IDPEntry(Element root) throws FSMsgException {
234        if (root == null) {
235            SAMLUtils.debug.message("IDPEntry.parseXML: null input.");
236            throw new FSMsgException("nullInput",null);
237        }
238        String tag = null;
239        if (((tag = root.getLocalName()) == null) ||
240                (!tag.equals("IDPEntry"))) {
241            FSUtils.debug.message("IDPEntry.parseXML: wrong input.");
242            throw new FSMsgException("wrongInput",null);
243        }
244        NodeList nl = root.getChildNodes();
245        Node child;
246        String nodeName;
247        int length = nl.getLength();
248        for (int i = 0; i < length; i++) {
249            child = nl.item(i);
250            if ((nodeName = child.getLocalName()) != null) {
251                if (nodeName.equals("ProviderID")) {
252                    if (providerID != null) {
253                        if (FSUtils.debug.messageEnabled()) {
254                            FSUtils.debug.message("IDPEntry(Element): should"
255                                    + "contain only one ProviderID");
256                        }
257                        throw new FSMsgException("wrongInput",null);
258                    }
259                    providerID = XMLUtils.getElementValue((Element) child);
260                } else if (nodeName.equals("ProviderName")) {
261                    if (providerName != null) {
262                        if (FSUtils.debug.messageEnabled()) {
263                            FSUtils.debug.message("IDPEntry(Element): should"
264                                    + "contain only one ProviderName");
265                        }
266                        throw new FSMsgException("wrongInput",null);
267                    }
268                    providerName = XMLUtils.getElementValue((Element) child);
269                } else if (nodeName.equals("Loc")) {
270                    if (location != null) {
271                        if (FSUtils.debug.messageEnabled()) {
272                            FSUtils.debug.message("IDPEntry(Element): should"
273                                    + "contain only one Loc");
274                        }
275                        throw new FSMsgException("wrongInput",null);
276                    }
277                    location = XMLUtils.getElementValue((Element) child);
278                }
279            }
280        }
281    }
282}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.