001/*
002 * Copyright 2007-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2007-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) 2007-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.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 a set of warning types that may be included in the password
050 * policy response control as defined in draft-behera-ldap-password-policy.
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 PasswordPolicyWarningType
064{
065  /**
066   * The warning type used to indicate that the user's password will expire in
067   * the near future and provide the length of time until it does expire.
068   */
069  TIME_BEFORE_EXPIRATION("time before expiration"),
070
071
072
073  /**
074   * The warning type used to indicate that the user's password is expired but
075   * that the user may have grace logins remaining, or that a grace login was
076   * used in the associated bind.
077   */
078  GRACE_LOGINS_REMAINING("grace logins remaining");
079
080
081
082  // The human-readable name for this password policy warning type.
083  @NotNull private final String name;
084
085
086
087  /**
088   * Creates a new password policy warning type with the provided name.
089   *
090   * @param  name The human-readable name for this warning type.
091   */
092  PasswordPolicyWarningType(@NotNull final String name)
093  {
094    this.name = name;
095  }
096
097
098
099  /**
100   * Retrieves the human-readable name for this password policy warning type.
101   *
102   * @return  The human-readable name for this password policy warning type.
103   */
104  @NotNull()
105  public String getName()
106  {
107    return name;
108  }
109
110
111
112  /**
113   * Retrieves the password policy warning type with the specified name.
114   *
115   * @param  name  The name of the password policy warning type to retrieve.  It
116   *               must not be {@code null}.
117   *
118   * @return  The requested password policy warning type, or {@code null} if no
119   *          such type is defined.
120   */
121  @Nullable()
122  public static PasswordPolicyWarningType forName(@NotNull final String name)
123  {
124    switch (StaticUtils.toLowerCase(name))
125    {
126      case "timebeforeexpiration":
127      case "time-before-expiration":
128      case "time_before_expiration":
129      case "time before expiration":
130        return TIME_BEFORE_EXPIRATION;
131      case "graceloginsremaining":
132      case "grace-logins-remaining":
133      case "grace_logins_remaining":
134      case "grace logins remaining":
135        return GRACE_LOGINS_REMAINING;
136      default:
137        return null;
138    }
139  }
140
141
142
143  /**
144   * Retrieves a string representation for this password policy warning type.
145   *
146   * @return  A string representation for this password policy warning type.
147   */
148  @Override()
149  @NotNull()
150  public String toString()
151  {
152    return name;
153  }
154}