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