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