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: FSAccountFedInfo.java,v 1.4 2008/06/25 05:46:39 qcheng Exp $ 026 * 027 */ 028 029package com.sun.identity.federation.accountmgmt; 030 031import com.sun.identity.federation.common.IFSConstants; 032import com.sun.identity.federation.common.FSUtils; 033import com.sun.identity.saml.assertion.NameIdentifier; 034 035/** 036 * This class handles the information of federated user account. 037 * @supported.api 038 */ 039public class FSAccountFedInfo { 040 041 /** 042 * Specifies provider's (SP/IDP) ID. 043 * It will always be a remote provider's ID. 044 */ 045 private String providerID = ""; 046 047 /** 048 * Contains NameIdentifier sent to other side in federation process. 049 */ 050 private NameIdentifier localNameIdentifier = null; 051 052 /** 053 * Contains NameIdentifier received from other side in federation process. 054 */ 055 private NameIdentifier remoteNameIdentifier = null; 056 057 /** 058 * Represents user's federation status (Active/Inactive). 059 */ 060 private boolean isActive = true; 061 062 /** 063 * Represents the federation type 064 */ 065 private boolean isAffiliationFed = false; 066 067 /* 068 * Represents that in a specific federation remote deployement 069 * participated as SP or IDP. 070 */ 071 private boolean isRoleIDP = true; 072 073 /** 074 * Default Constructor. 075 */ 076 FSAccountFedInfo() { 077 } 078 079 /** 080 * Constructor. 081 * @param providerID Specifies the provider's (SP/IDP) ID. 082 * @param nameIdentifier Contains NameIdentifier sent/received 083 * in federation process. 084 * @param nameIdentifierType indicates if IdentifierType is of type 085 * LOCAL or REMOTE 086 * @param isRoleIDP Represents that in a specific federation remote 087 * deployement participated as SP or IDP. 088 * @throws FSAccountMgmtException if illegal argument passed. 089 */ 090 public FSAccountFedInfo( 091 String providerID, 092 NameIdentifier nameIdentifier, 093 int nameIdentifierType, 094 boolean isRoleIDP) 095 throws FSAccountMgmtException 096 { 097 if (nameIdentifierType == IFSConstants.LOCAL_NAME_IDENTIFIER) { 098 init(providerID, 099 nameIdentifier, 100 null, 101 isRoleIDP); 102 } else if (nameIdentifierType == IFSConstants.REMOTE_NAME_IDENTIFIER) { 103 init(providerID, 104 null, 105 nameIdentifier, 106 isRoleIDP); 107 } else { 108 FSUtils.debug.error("FSAccountFedInfo.Constructor() : Invalid" + 109 " Argument : Invalid Name Identifier Type"); 110 throw new FSAccountMgmtException( 111 IFSConstants.INVALID_NAME_IDENTIFIER_TYPE, null); 112 } 113 } 114 115 /** 116 * Constructor. 117 * @param providerID Specifies provider's (SP/IDP) ID. 118 * @param localNameIdentifier Contains NameIdentifier sent to other side 119 * in federation process. 120 * @param remoteNameIdentifier Contains NameIdentifier received from 121 * other side in federation process. 122 * @param isRoleIDP Represents that in a specific federation remote 123 * deployement participated as SP or IDP. 124 * @throws FSAccountMgmtException if illegal argument passed. 125 */ 126 public FSAccountFedInfo( 127 String providerID, 128 NameIdentifier localNameIdentifier, 129 NameIdentifier remoteNameIdentifier, 130 boolean isRoleIDP) 131 throws FSAccountMgmtException 132 { 133 init(providerID, 134 localNameIdentifier, 135 remoteNameIdentifier, 136 isRoleIDP); 137 } 138 139 /** 140 * Initializes the account federation information object. 141 * @param providerID Specifies provider's (SP/IDP) ID. 142 * Always Remote provider. 143 * @param localNameIdentifier Contains NameIdentifier sent to other side 144 * in federation process. 145 * @param remoteNameIdentifier Contains NameIdentifier received from 146 * other side in federation process. 147 * @param isRoleIDP Represents that in a specific federation remote 148 * deployement participated as SP or IDP. 149 * @throws FSAccountMgmtException if illegal argument passed. 150 */ 151 private void init( 152 String providerID, 153 NameIdentifier localNameIdentifier, 154 NameIdentifier remoteNameIdentifier, 155 boolean isRoleIDP) 156 throws FSAccountMgmtException 157 { 158 if ((providerID == null) || (providerID.length() <= 0)) { 159 FSUtils.debug.error( 160 "FSAccountFedInfo.init(): Invalid Argument: providerID is " + 161 providerID); 162 throw new 163 FSAccountMgmtException(IFSConstants.NULL_PROVIDER_ID, null); 164 } 165 166 if (localNameIdentifier == null && remoteNameIdentifier == null) { 167 FSUtils.debug.error("FSAccountFedInfo.Constructor(): Invalid " + 168 "Argument: both NameIdentifiers are null"); 169 throw new FSAccountMgmtException( 170 IFSConstants.NULL_NAME_IDENTIFIER, null); 171 } 172 173 this.providerID = providerID; 174 this.localNameIdentifier = localNameIdentifier; 175 this.remoteNameIdentifier = remoteNameIdentifier; 176 this.isRoleIDP = isRoleIDP; 177 this.isActive = true; 178 179 if (FSUtils.debug.messageEnabled()) { 180 FSUtils.debug.message("FSAccountFedInfo.init() : " + 181 "providerID :: " + this.providerID + 182 ", isRoleIDP :: " + this.isRoleIDP); 183 if (localNameIdentifier != null ) { 184 FSUtils.debug.message( 185 "FSAccountFedInfo.init() : localNameIdentifier" + 186 this.localNameIdentifier.toString()); 187 } 188 if (remoteNameIdentifier != null ) { 189 FSUtils.debug.message( 190 "FSAccountFedInfo.init() : remoteNameIdentifier" + 191 this.remoteNameIdentifier.toString()); 192 } 193 } 194 } 195 196 /** 197 * Returns provider's (SP/IDP) ID. 198 * @return remote provider's id 199 * @supported.api 200 */ 201 public String getProviderID() { 202 return this.providerID; 203 } 204 205 /** 206 * Sets provider's ID. 207 * @param providerID - remote provider's id 208 */ 209 void setProviderID(String providerID) { 210 this.providerID = providerID; 211 } 212 213 /** 214 * Sets value in local field. 215 * @param localNameIdentifier Contains NameIdentifier sent to other 216 * side in federation process. 217 */ 218 public void setLocalNameIdentifier( 219 NameIdentifier localNameIdentifier) 220 { 221 this.localNameIdentifier = localNameIdentifier; 222 } 223 224 /** 225 * Returns local NameIdentifier sent to other side(SP/IDP). 226 * @return local NameIdentifier sent to other side 227 * @supported.api 228 */ 229 public NameIdentifier getLocalNameIdentifier() { 230 return this.localNameIdentifier; 231 } 232 233 /** 234 * Sets value in local field. 235 * @param remoteNameIdentifier Contains NameIdentifier received from 236 * other side in federation process. 237 */ 238 public void setRemoteNameIdentifier( 239 NameIdentifier remoteNameIdentifier) 240 { 241 this.remoteNameIdentifier = remoteNameIdentifier; 242 } 243 244 /** 245 * Returns remote NameIdentifier received from other side(SP/IDP). 246 * @return remote NameIdentifier received from other side 247 * @supported.api 248 */ 249 public NameIdentifier getRemoteNameIdentifier() { 250 return this.remoteNameIdentifier; 251 } 252 253 /** 254 * Sets Federation Status as active. 255 */ 256 public void activateFedStatus() { 257 this.isActive = true; 258 } 259 260 /** 261 * Sets Federation Status as Inactive. 262 */ 263 public void deActivateFedStatus() { 264 this.isActive = false; 265 } 266 267 /** 268 * Returns true/false if Federation Status is Active/Inactive. 269 * @return true/false if Federation Status is Active/Inactive. 270 */ 271 public boolean isFedStatusActive() { 272 return this.isActive; 273 } 274 275 /** 276 * Represents that in a specific federation remote 277 * deployement participated as SP or IDP. 278 * @return true if in a specific federation remote 279 * deployement participated as IDP. 280 * And returns false if as SP. 281 * @supported.api 282 */ 283 public boolean isRoleIDP() { 284 return this.isRoleIDP; 285 } 286 287 /** 288 * Represents that in a specific federation remote 289 * deployement participated as SP or IDP. 290 * @param isRoleIDP Represents that in a specific federation remote 291 * deployement participated as SP or IDP. 292 */ 293 void setRole(boolean isRoleIDP) { 294 this.isRoleIDP = isRoleIDP; 295 } 296 297 /** 298 * Sets the affiliation flag. 299 * @param isAffiliationFed true if the federation is affiliation type. 300 */ 301 public void setAffiliation(boolean isAffiliationFed) { 302 this.isAffiliationFed = isAffiliationFed; 303 } 304 305 /** 306 * Gets the affiliation federation type. 307 * @return true if the federation is of affiliation type. 308 * @supported.api 309 */ 310 public boolean getAffiliation() { 311 return isAffiliationFed; 312 } 313}