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