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: SubjectLocality.java,v 1.2 2008/06/25 05:47:33 qcheng Exp $ 026 * 027 */ 028 029package com.sun.identity.saml.assertion; 030 031import org.w3c.dom.*; 032import com.sun.identity.saml.common.SAMLUtilsCommon; 033import com.sun.identity.saml.common.SAMLConstants; 034import com.sun.identity.saml.common.SAMLException; 035import com.sun.identity.saml.common.SAMLRequesterException; 036 037/** 038 *The <code>SubjectLocality</code> element specifies the DNS domain name 039 *and IP address for the system entity that performed the authentication. 040 *It exists as part of <code>AuthenticationStatement</code> element. 041 *@supported.all.api 042 */ 043public class SubjectLocality { 044 static SAMLConstants sc; 045 046 private java.lang.String _ipAddress=null; 047 private java.lang.String _dnsAddress=null; 048 049 050 /** 051 *Default Constructor 052 */ 053 public SubjectLocality() {} 054 055 /** 056 * Constructs an instance of <code>SubjectLocality</code> from an existing 057 * XML block. 058 * 059 * @param localityElement A <code>org.w3c.dom.Element</code> representing 060 * DOM tree for <code>SubjectLocality</code> object. 061 * @exception SAMLException if it could not process the Element properly, 062 * implying that there is an error in the sender or in the 063 * element definition. 064 */ 065 public SubjectLocality(org.w3c.dom.Element localityElement) 066 throws SAMLException 067 { 068 Element elt = (Element) localityElement; 069 String eltName = elt.getLocalName(); 070 if (eltName == null) { 071 if (SAMLUtilsCommon.debug.messageEnabled()) { 072 SAMLUtilsCommon.debug.message("SubjectLocality: local name " 073 + "missing"); 074 } 075 throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString 076 ("nullInput")) ; 077 } 078 if (!(eltName.equals("SubjectLocality"))) 079 throw new SAMLException("invalidElement") ; 080 String read = elt.getAttribute("IPAddress"); 081 if ((read != null) && (read.length() != 0)) { 082 _ipAddress= read; 083 } 084 read = elt.getAttribute("DNSAddress"); 085 if ((read != null) && (read.length() != 0)) { 086 _dnsAddress=read; 087 } 088 } 089 090 /** 091 * Constructs an instance of <code>SubjectLocality</code>. 092 * 093 * @param ipAddress String representing the IP Address of the entity 094 * that was authenticated. 095 * @param dnsAddress String representing the DNS Address of the entity that 096 * was authenticated. As per SAML specification they are both 097 * optional, so values can be null. 098 */ 099 public SubjectLocality(String ipAddress,String dnsAddress) { 100 if (ipAddress == null) { 101 _ipAddress = ""; 102 } else { 103 _ipAddress = ipAddress; 104 } 105 if (dnsAddress == null) { 106 _dnsAddress = ""; 107 } else { 108 _dnsAddress = dnsAddress; 109 } 110 } 111 112 /** 113 * Returns the IP address from <code>SubjectLocality</code> locality 114 * 115 * @return A String representation of IP address. 116 */ 117 public java.lang.String getIPAddress() { 118 return _ipAddress; 119 } 120 121 /** 122 * Sets the DNS address for <code>SubjectLocality></code> locality. 123 * 124 * @param dnsAddress A String representation of DNS address. 125 * @return true indicating the success of the operation. 126 */ 127 public boolean setDNSAddress(java.lang.String dnsAddress) { 128 if ((dnsAddress == null) || (dnsAddress.length() == 0)) { 129 SAMLUtilsCommon.debug.message("DNS Address is null"); 130 return false; 131 } 132 _dnsAddress = dnsAddress; 133 return true; 134 } 135 136 /** 137 * Sets the IP address for <code>SubjectLocality</code> locality. 138 * 139 * @param ipAddress A String representation of IP address. 140 * @return true indicating the success of the operation. 141 */ 142 public boolean setIPAddress(java.lang.String ipAddress) { 143 if ((ipAddress == null) || (ipAddress.length() == 0)) { 144 SAMLUtilsCommon.debug.message("IP Address is null"); 145 return false; 146 } 147 _ipAddress = ipAddress; 148 return true; 149 } 150 151 /** 152 * Returns the DNS address from <code>SubjectLocality</code> locality 153 * 154 * @return A String representation of DNS address. 155 */ 156 public java.lang.String getDNSAddress() { 157 return _dnsAddress; 158 } 159 160 /** 161 * Returns a String representation of the element. 162 * 163 * @return A string containing the valid XML for this element 164 * By default name space name is prepended to the element name 165 * example <code><saml:SubjectLocality></code>. 166 */ 167 public java.lang.String toString() { 168 // call toString() with includeNS true by default and declareNS false 169 String xml = this.toString(true, false); 170 return xml; 171 } 172 173 /** 174 * Returns a String representation of the 175 * <code><SubjectLocality></code> element. 176 * 177 * @param includeNS Determines whether or not the namespace qualifier is 178 * prepended to the Element when converted 179 * @param declareNS Determines whether or not the namespace is declared 180 * within the Element. 181 * @return A string containing the valid XML for this element 182 */ 183 public java.lang.String toString(boolean includeNS, boolean declareNS) { 184 StringBuffer xml = new StringBuffer(3000); 185 String NS=""; 186 String appendNS=""; 187 if (declareNS) NS=sc.assertionDeclareStr; 188 if (includeNS) appendNS="saml:"; 189 xml.append("<").append(appendNS).append("SubjectLocality"). 190 append(" ").append(NS).append(" "); 191 if ((_ipAddress != null) && !(_ipAddress.length() == 0)) 192 xml.append("IPAddress").append("=\"").append(_ipAddress). 193 append("\"").append(" "); 194 if ((_dnsAddress != null) && !(_dnsAddress.length() == 0)) 195 xml.append("DNSAddress").append("=\"").append(_dnsAddress). 196 append("\"").append(" "); 197 xml.append(sc.END_ELEMENT); 198 return xml.toString(); 199 } 200} 201
Copyright © 2010-2017, ForgeRock All Rights Reserved.