001/* 002 * Copyright 2015-2019 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2015-2019 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.sdk.unboundidds.extensions; 022 023 024 025import java.io.Serializable; 026 027import com.unboundid.util.NotMutable; 028import com.unboundid.util.ThreadSafety; 029import com.unboundid.util.ThreadSafetyLevel; 030import com.unboundid.util.Validator; 031 032 033 034/** 035 * This class provides a data structure with information about a one-time 036 * password delivery mechanism that is supported by the Directory Server and may 037 * or may not be supported for a particular user. 038 * <BR> 039 * <BLOCKQUOTE> 040 * <B>NOTE:</B> This class, and other classes within the 041 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 042 * supported for use against Ping Identity, UnboundID, and 043 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 044 * for proprietary functionality or for external specifications that are not 045 * considered stable or mature enough to be guaranteed to work in an 046 * interoperable way with other types of LDAP servers. 047 * </BLOCKQUOTE> 048 */ 049@NotMutable() 050@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 051public final class SupportedOTPDeliveryMechanismInfo 052 implements Serializable 053{ 054 /** 055 * The serial version UID for this serializable class. 056 */ 057 private static final long serialVersionUID = -6315998976212985213L; 058 059 060 061 // Indicates whether the delivery mechanism is supported for the user targeted 062 // by the get supported OTP delivery mechanisms extended request. 063 private final Boolean isSupported; 064 065 // The name of the OTP delivery mechanism. 066 private final String deliveryMechanism; 067 068 // An optional recipient ID that may be used for the target user in 069 // conjunction with the delivery mechanism. 070 private final String recipientID; 071 072 073 074 /** 075 * Creates a new supported OTP delivery mechanism info object with the 076 * provided information. 077 * 078 * @param deliveryMechanism The name of the one-time password delivery 079 * mechanism to which this object corresponds. 080 * @param isSupported Indicates whether the specified delivery 081 * mechanism is expected to be supported for the 082 * target user. This may be {@code true} (to 083 * indicate that the delivery mechanism is expected 084 * to be supported for the target user, 085 * {@code false} if the delivery mechanism is not 086 * supported for the target user, or {@code null} 087 * if it cannot be determined whether the delivery 088 * mechanism is supported for the target user. 089 * @param recipientID An optional recipient ID that can be used in 090 * conjunction with the delivery mechanism if it 091 * is supported for the user (e.g., it may be an 092 * email address for an email-based delivery 093 * mechanism or a mobile phone number for an 094 * SMS-based delivery mechanism). This may be 095 * {@code null} if the delivery mechanism is not 096 * supported or if no recipient ID is applicable. 097 */ 098 public SupportedOTPDeliveryMechanismInfo(final String deliveryMechanism, 099 final Boolean isSupported, 100 final String recipientID) 101 { 102 Validator.ensureNotNull(deliveryMechanism); 103 104 this.deliveryMechanism = deliveryMechanism; 105 this.isSupported = isSupported; 106 this.recipientID = recipientID; 107 } 108 109 110 111 /** 112 * Retrieves the name of the one-time password delivery mechanism to which 113 * this object corresponds. 114 * 115 * @return The name of the one-time password delivery mechanism to which this 116 * object corresponds. 117 */ 118 public String getDeliveryMechanism() 119 { 120 return deliveryMechanism; 121 } 122 123 124 125 /** 126 * Retrieves information about whether the one-time password delivery 127 * mechanism is supported for the target user. 128 * 129 * @return {@code true} if the delivery mechanism is expected to be supported 130 * for the user, {@code false} if the delivery mechanism is not 131 * supported for the user, or {@code null} if it cannot be determined 132 * whether the delivery mechanism is supported for the target user. 133 */ 134 public Boolean isSupported() 135 { 136 return isSupported; 137 } 138 139 140 141 /** 142 * Retrieves the recipient ID, if any, that may be used for the target user 143 * in conjunction with the associated delivery mechanism. If a recipient ID 144 * is available, then its format may vary based on the type of delivery 145 * mechanism. 146 * 147 * @return The recipient ID that may be used for the target user in 148 * conjunction with the associated delivery mechanism, or 149 * {@code null} if there is no recipient ID associated with the 150 * delivery mechanism, or if the delivery mechanism is not expected 151 * to be supported for the target user. 152 */ 153 public String getRecipientID() 154 { 155 return recipientID; 156 } 157 158 159 160 /** 161 * Retrieves a hash code for this supported OTP delivery mechanism info 162 * object. 163 * 164 * @return A hash code for this supported OTP delivery mechanism info object. 165 */ 166 @Override() 167 public int hashCode() 168 { 169 int hc = deliveryMechanism.hashCode(); 170 171 if (isSupported == null) 172 { 173 hc += 2; 174 } 175 else if (isSupported) 176 { 177 hc++; 178 } 179 180 if (recipientID != null) 181 { 182 hc += recipientID.hashCode(); 183 } 184 185 return hc; 186 } 187 188 189 190 /** 191 * Indicates whether the provided object is considered equal to this supported 192 * OTP delivery mechanism info object. 193 * 194 * @param o The object for which to make the determination. 195 * 196 * @return {@code true} if the provided object is an equivalent supported OTP 197 * delivery mechanism info object, or {@code false} if not. 198 */ 199 @Override() 200 public boolean equals(final Object o) 201 { 202 if (o == this) 203 { 204 return true; 205 } 206 207 if (! (o instanceof SupportedOTPDeliveryMechanismInfo)) 208 { 209 return false; 210 } 211 212 final SupportedOTPDeliveryMechanismInfo i = 213 (SupportedOTPDeliveryMechanismInfo) o; 214 if (! deliveryMechanism.equals(i.deliveryMechanism)) 215 { 216 return false; 217 } 218 219 if (isSupported == null) 220 { 221 if (i.isSupported != null) 222 { 223 return false; 224 } 225 } 226 else 227 { 228 if (! isSupported.equals(i.isSupported)) 229 { 230 return false; 231 } 232 } 233 234 if (recipientID == null) 235 { 236 return (i.recipientID == null); 237 } 238 else 239 { 240 return recipientID.equals(i.recipientID); 241 } 242 } 243 244 245 246 /** 247 * Retrieves a string representation of this supported OTP delivery mechanism 248 * info object. 249 * 250 * @return A string representation of this supported OTP delivery mechanism 251 * object. 252 */ 253 @Override() 254 public String toString() 255 { 256 final StringBuilder buffer = new StringBuilder(); 257 toString(buffer); 258 return buffer.toString(); 259 } 260 261 262 263 /** 264 * Appends a string representation of this supported OTP delivery mechanism 265 * info object to the provided buffer. 266 * 267 * @param buffer The buffer to which the information should be appended. 268 */ 269 public void toString(final StringBuilder buffer) 270 { 271 buffer.append("SupportedOTPDeliveryMechanismInfo(mechanism='"); 272 buffer.append(deliveryMechanism); 273 buffer.append('\''); 274 275 if (isSupported != null) 276 { 277 buffer.append(", isSupported="); 278 buffer.append(isSupported); 279 } 280 281 if (recipientID != null) 282 { 283 buffer.append(", recipientID='"); 284 buffer.append(recipientID); 285 buffer.append('\''); 286 } 287 buffer.append(')'); 288 } 289}