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: EncryptableNameIdentifier.java,v 1.4 2008/06/25 05:46:46 qcheng Exp $ 026 * Portions Copyrighted 2014 ForgeRock AS 027 */ 028 029package com.sun.identity.federation.message.common; 030 031import org.w3c.dom.Element; 032import java.util.Date; 033 034import com.sun.identity.federation.common.FSException; 035import com.sun.identity.federation.common.IFSConstants; 036import com.sun.identity.federation.common.FSUtils; 037 038import com.sun.identity.saml.assertion.NameIdentifier; 039import com.sun.identity.shared.DateUtils; 040import com.sun.identity.shared.xml.XMLUtils; 041 042/** 043 * This class contains methods for encrypting the <code>NameIdentifier</code> 044 * object. 045 * 046 * @supported.all.api 047 * @deprecated since 12.0.0 048 */ 049@Deprecated 050public class EncryptableNameIdentifier { 051 052 private java.lang.String _nameQualifier = ""; 053 private java.lang.String _name = ""; 054 private java.lang.String _nonce = ""; 055 private java.lang.String _format = ""; 056 private java.util.Date _issueInstant = null; 057 058 059 /** 060 * Default Constructor. 061 */ 062 protected EncryptableNameIdentifier() {} 063 064 /** 065 * Constructor creates <code>EncryptableNameIdentifier</code> object. 066 * 067 * @param ni the <code>NameIdentifier</code> object to be encrypted. 068 * @throws FSException if there is an error. 069 */ 070 public EncryptableNameIdentifier(NameIdentifier ni) throws FSException { 071 if(ni == null) { 072 throw new FSException("nullInput", null) ; 073 } 074 _nameQualifier = ni.getNameQualifier(); 075 _name = ni.getName(); 076 if(_nameQualifier == null || _name == null) { 077 throw new FSException("nullInput", null) ; 078 } 079 _format = ni.getFormat(); 080 if(_format == null) { 081 throw new FSException("notValidFormat", null) ; 082 } 083 _nonce = FSUtils.generateID(); 084 _issueInstant = new Date(); 085 } 086 087 /** 088 * Consturctor creates <code>EncryptableNameIdentifier</code> object. 089 * 090 * @param name 091 * @param nameQualifier 092 * @param format 093 * @param issueInstant the Issue Instant 094 * @param nonce 095 * @throws FSException if there is an error. 096 */ 097 public EncryptableNameIdentifier(String name,String nameQualifier, 098 String format,Date issueInstant, 099 String nonce ) throws FSException { 100 101 if(name == null || nameQualifier == null || issueInstant == null || 102 format == null || nonce == null) { 103 throw new FSException("nullInput", null) ; 104 } 105 _name = name; 106 _nameQualifier = nameQualifier; 107 _format = format; 108 _nonce = nonce; 109 _issueInstant = issueInstant; 110 } 111 112 113 114 /** 115 * Constructs a <code>EncryptedNameIdentifer</code> element from 116 * the Document Element. 117 * 118 * @param nameIdentifier a <code>org.w3c.dom.Element</code> 119 * representing DOM tree for <code>EncryptableNameIdentifier</code> 120 * object 121 * @throws FSException if it could not process the 122 * <code>org.w3c.dom.Element</code> properly, implying that there 123 * is an error in the sender or in the element definition. 124 */ 125 public EncryptableNameIdentifier(org.w3c.dom.Element nameIdentifier) 126 throws FSException { 127 Element elt = (Element) nameIdentifier; 128 String eltName = elt.getLocalName(); 129 if (eltName == null) { 130 if (FSUtils.debug.messageEnabled()) { 131 FSUtils.debug.message("EncryptableNameIdentifier: local" + 132 " name missing"); 133 } 134 throw new FSException("nullInput", null) ; 135 } 136 if (!(eltName.equals("EncryptableNameIdentifier"))) { 137 if (FSUtils.debug.messageEnabled()) { 138 FSUtils.debug.message("EncryptableNameIdentifier: invalid"+ 139 " root element"); 140 } 141 throw new FSException("invalidElement", null) ; 142 } 143 String read = elt.getAttribute("NameQualifier"); 144 if (read != null) { 145 _nameQualifier = read; 146 } 147 read = elt.getAttribute("Format"); 148 if (read != null) { 149 _format = read; 150 } 151 152 read = elt.getAttribute("Nonce"); 153 if (read != null) { 154 _nonce = read; 155 } 156 157 read = elt.getAttribute("IssueInstant"); 158 if(read != null) { 159 try { 160 _issueInstant = DateUtils.stringToDate(read); 161 } catch (java.text.ParseException pe) { 162 if (FSUtils.debug.messageEnabled()) { 163 FSUtils.debug.message("EncryptableNameIdentifier: "+ 164 "Could not parse issue instant", pe); 165 } 166 throw new FSException("wrongInput", null) ; 167 } 168 } 169 read = XMLUtils.getElementValue(elt); 170 if ((read == null) || (read.length() == 0)) { 171 if (FSUtils.debug.messageEnabled()) { 172 FSUtils.debug.message("EncryptableNameIdentifier: null"+ 173 " input specified"); 174 } 175 throw new FSException("nullInput", null) ; 176 } else { 177 _name = read; 178 } 179 } 180 181 /** 182 * Returns value of the <code>Format</code> attribute. 183 * 184 * @return value of the <code>Format</code> attribute. 185 */ 186 public java.lang.String getFormat() { 187 return _format; 188 } 189 190 191 /** 192 * Sets the <code>Format</code> attribute. 193 * 194 * @param format the value of the <code>Format</code> attribute. 195 * @return true if the operation succeeds. 196 */ 197 public boolean setFormat(java.lang.String format ) { 198 // TODO do I need to restrict the format to those defined 199 // by SAML specification ? 200 if ((format == null) || (format.length() == 0)) { 201 return false; 202 } 203 _format = format; 204 return true; 205 } 206 207 /** 208 * Returns the <code>NameQualifier</code> attribute. 209 * 210 * @return the <code>nameQualifier</code>. 211 */ 212 public java.lang.String getNameQualifier() { 213 return _nameQualifier; 214 } 215 216 217 /** 218 * Sets <code>nameQualifier</code> attribute. 219 * 220 * @param nameQualifier the <code>nameQualifier</code> attribute. 221 * @return true if operation succeeds. 222 */ 223 public boolean setNameQualifier(java.lang.String nameQualifier ) { 224 if ((nameQualifier == null) || (nameQualifier.length() == 0)) { 225 return false; 226 } 227 _nameQualifier=nameQualifier; 228 return true; 229 } 230 231 /** 232 * Sets the name attribute. 233 * 234 * @param name name of the <code>nameQualifier</code>. 235 * @return true if operation succeeds. 236 */ 237 protected boolean setName(java.lang.String name ) { 238 if ((name == null) || (name.length() == 0)) { 239 return false; 240 } 241 _name = name; 242 return true; 243 } 244 245 /** 246 * Returns the name from <code>NameQualifier</code>. 247 * 248 * @return the name from <code>NameQualifier</code>. 249 */ 250 public java.lang.String getName() { 251 return _name; 252 } 253 254 /** 255 * Retunrs the nounce. 256 * 257 * @return the nounce. 258 */ 259 public java.lang.String getNonce() { 260 return _nonce; 261 } 262 263 /** 264 * Returns the Issue Instant. 265 * 266 * @return the Issue Instant. 267 */ 268 public java.util.Date getIssueInstant() { 269 return _issueInstant; 270 } 271 272 /** 273 * Returns a String representation of the element. 274 * 275 * @return A string containing the valid XML for this element 276 * By default name space name is prepended to the element name 277 * example <code><saml:EncryptableNameIdentifier></code>. 278 */ 279 public java.lang.String toString() { 280 // call toString() with includeNS true by default and declareNS false 281 String xml = this.toString(true, false); 282 return xml; 283 } 284 285 /** 286 * Returns String representation of the 287 * <code><EncryptableNameIdentifier></code> element. 288 * 289 * @param includeNS Determines whether or not the namespace qualifier is 290 * prepended to the Element when converted. 291 * @param declareNS Determines whether or not the namespace is declared 292 * within the Element. 293 * @return A string containing the valid XML for this element 294 */ 295 public java.lang.String toString(boolean includeNS, boolean declareNS) { 296 StringBuffer xml = new StringBuffer(3000); 297 String NS=""; 298 String appendNS=""; 299 if (declareNS) { 300 NS=IFSConstants.LIB_12_NAMESPACE_STRING; 301 } 302 if (includeNS) { 303 appendNS=IFSConstants.LIB_PREFIX; 304 } 305 306 String dateStr = null; 307 if(_issueInstant != null) { 308 dateStr = DateUtils.toUTCDateFormat(_issueInstant); 309 } 310 311 xml.append("<").append(appendNS).append("EncryptableNameIdentifier"). 312 append(NS); 313 if ((_nameQualifier != null) && (!(_nameQualifier.length() == 0))) { 314 xml.append(" ").append("NameQualifier").append("=\""). 315 append(_nameQualifier).append("\""); 316 } 317 if ((_format != null) && (!(_format.length() == 0))) { 318 xml.append(" ").append("Format").append("=\"").append(_format). 319 append("\""); 320 } 321 if ((_nonce != null) && (!(_nonce.length() == 0))) { 322 xml.append(" ").append("Nonce").append("=\"").append(_nonce). 323 append("\""); 324 } 325 if ((_issueInstant != null) && (dateStr.length() != 0)) { 326 xml.append(" ").append("IssueInstant").append("=\""). 327 append(dateStr).append("\""); 328 } 329 xml.append(">").append(_name); 330 xml.append("</").append(appendNS).append("EncryptableNameIdentifier"). 331 append(">"); 332 return xml.toString(); 333 } 334}
Copyright © 2010-2017, ForgeRock All Rights Reserved.