001/*
002 * Copyright 2015-2022 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2015-2022 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-2022 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.controls;
037
038
039
040import com.unboundid.util.NotNull;
041import com.unboundid.util.Nullable;
042import com.unboundid.util.StaticUtils;
043import com.unboundid.util.ThreadSafety;
044import com.unboundid.util.ThreadSafetyLevel;
045
046
047
048/**
049 * This enum defines the set of response types that can be used in the
050 * password validation details response control.
051 * <BR>
052 * <BLOCKQUOTE>
053 *   <B>NOTE:</B>  This class, and other classes within the
054 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
055 *   supported for use against Ping Identity, UnboundID, and
056 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
057 *   for proprietary functionality or for external specifications that are not
058 *   considered stable or mature enough to be guaranteed to work in an
059 *   interoperable way with other types of LDAP servers.
060 * </BLOCKQUOTE>
061 */
062@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
063public enum PasswordValidationDetailsResponseType
064{
065  /**
066   * The response type that indicates that the server was able to perform
067   * validation against the proposed password, and that the response includes
068   * a set of validation results.
069   */
070  VALIDATION_DETAILS((byte) 0xA0),
071
072
073
074  /**
075   * The response type that indicates that the server was unable to provide
076   * validation results because the associated request did not include any
077   * password.
078   */
079  NO_PASSWORD_PROVIDED((byte) 0x81),
080
081
082
083  /**
084   * The response type that indicates that the server was unable to provide
085   * validation results because the associated request included multiple
086   * passwords.
087   */
088  MULTIPLE_PASSWORDS_PROVIDED((byte) 0x82),
089
090
091
092  /**
093   * The response type that indicates that the server encountered a problem with
094   * the request that caused processing to end before any password validation
095   * was attempted.
096   */
097  NO_VALIDATION_ATTEMPTED((byte) 0x83);
098
099
100
101  // The BER type that will be used for this response type in an encoded
102  // password validation details response control.
103  private final byte berType;
104
105
106
107  /**
108   * Creates a new password validation details response type with the provided
109   * BER type.
110   *
111   * @param  berType  The BER type that will be used for this response type in
112   *                  an encoded password validation details response control.
113   */
114  PasswordValidationDetailsResponseType(final byte berType)
115  {
116    this.berType = berType;
117  }
118
119
120
121  /**
122   * Retrieves the BER type that will be used for this response type in an
123   * encoded password validation details response control.
124   *
125   * @return  The BER type that will be used for this response type in an
126   *          encoded password validation details response control.
127   */
128  public byte getBERType()
129  {
130    return berType;
131  }
132
133
134
135  /**
136   * Retrieves the password validation details response type with the specified
137   * BER type.
138   *
139   * @param  berType  The BER type for the password validation details response
140   *                  type to retrieve.
141   *
142   * @return  The password validation details response type with the specified
143   *          BER type, or {@code null} if there is no response type with the
144   *          specified BER type.
145   */
146  @Nullable()
147  public static PasswordValidationDetailsResponseType forBERType(
148                     final byte berType)
149  {
150    for (final PasswordValidationDetailsResponseType t : values())
151    {
152      if (t.berType == berType)
153      {
154        return t;
155      }
156    }
157
158    return null;
159  }
160
161
162
163  /**
164   * Retrieves the password validation details response type with the specified
165   * name.
166   *
167   * @param  name  The name of the password validation details response type to
168   *               retrieve.  It must not be {@code null}.
169   *
170   * @return  The requested password validation details response type, or
171   *          {@code null} if no such type is defined.
172   */
173  @Nullable()
174  public static PasswordValidationDetailsResponseType forName(
175                     @NotNull final String name)
176  {
177    switch (StaticUtils.toLowerCase(name))
178    {
179      case "validationdetails":
180      case "validation-details":
181      case "validation_details":
182        return VALIDATION_DETAILS;
183      case "nopasswordprovided":
184      case "no-password-provided":
185      case "no_password_provided":
186        return NO_PASSWORD_PROVIDED;
187      case "multiplepasswordsprovided":
188      case "multiple-passwords-provided":
189      case "multiple_passwords_provided":
190        return MULTIPLE_PASSWORDS_PROVIDED;
191      case "novalidationattempted":
192      case "no-validation-attempted":
193      case "no_validation_attempted":
194        return NO_VALIDATION_ATTEMPTED;
195      default:
196        return null;
197    }
198  }
199}