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: FSIDPList.java,v 1.2 2008/06/25 05:46:44 qcheng Exp $ 026 * Portions Copyrighted 2014 ForgeRock AS. 027 */ 028 029package com.sun.identity.federation.message; 030 031import com.sun.identity.federation.common.IFSConstants; 032import com.sun.identity.federation.message.common.FSMsgException; 033import com.sun.identity.federation.message.common.IDPEntries; 034import com.sun.identity.federation.message.common.GetComplete; 035import com.sun.identity.federation.common.FSUtils; 036 037import java.util.List; 038import java.util.Collections; 039import java.util.Iterator; 040import java.util.ArrayList; 041 042import org.w3c.dom.Element; 043import org.w3c.dom.Node; 044import org.w3c.dom.NodeList; 045 046/** 047 * This class has methods to construct an object or 048 * message representing a list of trusted Identity Providers. 049 * 050 * @supported.all.api 051 * @deprecated since 12.0.0 052 */ 053@Deprecated 054public class FSIDPList { 055 private List getCompleteList = null; 056 /** 057 * <code>IDPEntries</code> object. 058 */ 059 public IDPEntries idpEntries = null; 060 private int minorVersion = IFSConstants.FF_11_PROTOCOL_MINOR_VERSION; 061 062 /** 063 * Default Constructor. 064 */ 065 public FSIDPList() { 066 } 067 068 /** 069 * Constructor creates <code>FSIDPList</code> object from 070 * Document Element. 071 * 072 * @param root the Document Element object. 073 * @throws FSMsgException if there is an error creating 074 * the object. 075 */ 076 public FSIDPList(Element root) throws FSMsgException { 077 if (root == null) { 078 FSUtils.debug.message("FSIDPList.parseXML: null input."); 079 throw new FSMsgException("nullInput",null); 080 } 081 String ns = root.getNamespaceURI(); 082 if (ns == null) { 083 FSUtils.debug.error("FSIDPList(Element):No namespace"); 084 throw new FSMsgException("wrongInput",null); 085 } 086 087 if (ns.equals(IFSConstants.FF_12_XML_NS)) { 088 minorVersion = IFSConstants.FF_12_PROTOCOL_MINOR_VERSION; 089 } 090 091 String tag = null; 092 if (((tag = root.getLocalName()) == null) || 093 (!tag.equals(IFSConstants.IDP_LIST))) { 094 FSUtils.debug.message("FSIDPList.parseXML: wrong input."); 095 throw new FSMsgException("wrongInput",null); 096 } 097 098 NodeList nl = root.getChildNodes(); 099 Node child; 100 String childName; 101 int length = nl.getLength(); 102 for (int i = 0; i < length; i++) { 103 child = nl.item(i); 104 if ((childName = child.getLocalName()) != null) { 105 if (childName.equals(IFSConstants.GET_COMPLETE)) { 106 if ((getCompleteList == null) || 107 (getCompleteList == Collections.EMPTY_LIST)) { 108 getCompleteList = new ArrayList(); 109 } 110 getCompleteList.add(new GetComplete((Element)child)); 111 }else if (childName.equals(IFSConstants.IDP_ENTRIES)) { 112 idpEntries = new IDPEntries((Element) child); 113 } 114 } 115 } 116 } 117 118 /** 119 * Constructor creates <code>FSIDPList</code> from <code>IDPEntries</code> 120 * object and a list of <code>GetComplete</code> objects. 121 * 122 * @param idpEntries the <code>IDPEntries</code> object. 123 * @param getCompleteList list of <code>GetComplete</code> objects. 124 */ 125 public FSIDPList(IDPEntries idpEntries, List getCompleteList) { 126 this.idpEntries = idpEntries; 127 this.getCompleteList = getCompleteList; 128 } 129 130 /** 131 * Sets the value of <code>MinorVersion</code> attribute. 132 * 133 * @param minorVersion the value of <code>MinorVersion</code> attribute 134 * in the assertion. 135 * @see #setMinorVersion(int) 136 */ 137 public void setMinorVersion(int minorVersion) { 138 this.minorVersion = minorVersion; 139 } 140 141 /** 142 * Returns the value of <code>MinorVersion</code> attribute. 143 * 144 * @return the value of <code>MinorVersion</code> attribute. 145 * @see #setMinorVersion(int) 146 */ 147 public int getMinorVersion() { 148 return minorVersion; 149 } 150 151 /** 152 * Returns <code>IDPEntries</code> object. 153 * 154 * @return the <code>IDPEntries</code> object. 155 * @see #setIDPEntries(IDPEntries) 156 */ 157 public IDPEntries getIDPEntries() { 158 return idpEntries; 159 } 160 161 /** 162 * Returns list of <code>GetComplete</code> objects. 163 * 164 * @return list of <code>GetComplete</code> objects. 165 * @see #setGetCompleteList(List) 166 */ 167 public List getGetCompleteList() { 168 return getCompleteList; 169 } 170 171 /** 172 * Sets <code>IDPEntries</code> object. 173 * 174 * @param idpEntries <code>IDPEntries</code> object. 175 * @see #getIDPEntries 176 */ 177 public void setIDPEntries(IDPEntries idpEntries) { 178 this.idpEntries = idpEntries; 179 } 180 181 /** 182 * Sets list of <code>GetComplete</code> objects. 183 * 184 * @param getCompleteList list of <code>GetComplete</code> objects. 185 * @see #setGetCompleteList(List) 186 */ 187 public void setGetCompleteList(List getCompleteList) { 188 this.getCompleteList = getCompleteList; 189 } 190 191 /** 192 * Returns a <code>XML</code> string representation of this object. 193 * 194 * @return XML String representing this object. 195 * @throws FSMsgException if there is an error creating 196 * the XML string or if the required elements to create 197 * the string do not conform to the schema. 198 */ 199 200 public String toXMLString() throws FSMsgException { 201 return toXMLString(true, true); 202 } 203 204 /** 205 * Creates a String representation of this object. 206 * 207 * @param includeNS : Determines whether or not the namespace qualifier 208 * is prepended to the Element when converted 209 * @param declareNS : Determines whether or not the namespace is declared 210 * within the Element. 211 * @return string containing the valid XML for this element. 212 * @throws FSMsgException if there is an error. 213 */ 214 public String toXMLString(boolean includeNS, boolean declareNS) 215 throws FSMsgException { 216 return toXMLString(includeNS, declareNS, false); 217 } 218 219 /** 220 * Creates a String representation of this element. 221 * 222 * @param includeNS Determines whether or not the namespace qualifier 223 * is prepended to the Element when converted 224 * @param declareNS Determines whether or not the namespace is declared 225 * within the Element. 226 * @param includeHeader Determines whether the output include the xml 227 * declaration header. 228 * @return A string containing the valid XML for this element. 229 * @throws FSMsgException if there is an error. 230 */ 231 public String toXMLString(boolean includeNS,boolean declareNS, 232 boolean includeHeader) throws FSMsgException { 233 234 StringBuffer xml = new StringBuffer(300); 235 if (includeHeader) { 236 xml.append(IFSConstants.XML_PREFIX) 237 .append(IFSConstants.DEFAULT_ENCODING) 238 .append(IFSConstants.QUOTE) 239 .append(IFSConstants.SPACE) 240 .append(IFSConstants.QUESTION_MARK) 241 .append(IFSConstants.RIGHT_ANGLE); 242 } 243 String prefix = ""; 244 String uri = ""; 245 if (includeNS) { 246 prefix = IFSConstants.LIB_PREFIX; 247 } 248 if (declareNS) { 249 if(minorVersion == IFSConstants.FF_12_PROTOCOL_MINOR_VERSION) { 250 uri = IFSConstants.LIB_12_NAMESPACE_STRING; 251 } else { 252 uri = IFSConstants.LIB_NAMESPACE_STRING; 253 } 254 } 255 xml.append(IFSConstants.LEFT_ANGLE) 256 .append(prefix) 257 .append(IFSConstants.IDP_LIST) 258 .append(uri) 259 .append(IFSConstants.RIGHT_ANGLE); 260 261 if (idpEntries != null){ 262 xml.append(idpEntries.toXMLString(true, false)); 263 } 264 265 if ((this.getCompleteList != null) && 266 (getCompleteList != Collections.EMPTY_LIST)){ 267 Iterator i = getCompleteList.iterator(); 268 while (i.hasNext()) { 269 xml.append((String)i.next()); 270 } 271 } 272 xml.append(IFSConstants.START_END_ELEMENT) 273 .append(prefix) 274 .append(IFSConstants.IDP_LIST) 275 .append(IFSConstants.RIGHT_ANGLE); 276 277 return xml.toString(); 278 } 279}