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