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