001/*
002 * Copyright 2007-2019 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2019 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk.unboundidds.controls;
022
023
024
025import com.unboundid.util.StaticUtils;
026import com.unboundid.util.ThreadSafety;
027import com.unboundid.util.ThreadSafetyLevel;
028
029
030
031/**
032 * This enum defines a set of warning types that may be included in the password
033 * policy response control as defined in draft-behera-ldap-password-policy.
034 * <BR>
035 * <BLOCKQUOTE>
036 *   <B>NOTE:</B>  This class, and other classes within the
037 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
038 *   supported for use against Ping Identity, UnboundID, and
039 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
040 *   for proprietary functionality or for external specifications that are not
041 *   considered stable or mature enough to be guaranteed to work in an
042 *   interoperable way with other types of LDAP servers.
043 * </BLOCKQUOTE>
044 */
045@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
046public enum PasswordPolicyWarningType
047{
048  /**
049   * The warning type used to indicate that the user's password will expire in
050   * the near future and provide the length of time until it does expire.
051   */
052  TIME_BEFORE_EXPIRATION("time before expiration"),
053
054
055
056  /**
057   * The warning type used to indicate that the user's password is expired but
058   * that the user may have grace logins remaining, or that a grace login was
059   * used in the associated bind.
060   */
061  GRACE_LOGINS_REMAINING("grace logins remaining");
062
063
064
065  // The human-readable name for this password policy warning type.
066  private final String name;
067
068
069
070  /**
071   * Creates a new password policy warning type with the provided name.
072   *
073   * @param  name The human-readable name for this warning type.
074   */
075  PasswordPolicyWarningType(final String name)
076  {
077    this.name = name;
078  }
079
080
081
082  /**
083   * Retrieves the human-readable name for this password policy warning type.
084   *
085   * @return  The human-readable name for this password policy warning type.
086   */
087  public String getName()
088  {
089    return name;
090  }
091
092
093
094  /**
095   * Retrieves the password policy warning type with the specified name.
096   *
097   * @param  name  The name of the password policy warning type to retrieve.  It
098   *               must not be {@code null}.
099   *
100   * @return  The requested password policy warning type, or {@code null} if no
101   *          such type is defined.
102   */
103  public static PasswordPolicyWarningType forName(final String name)
104  {
105    switch (StaticUtils.toLowerCase(name))
106    {
107      case "timebeforeexpiration":
108      case "time-before-expiration":
109      case "time_before_expiration":
110      case "time before expiration":
111        return TIME_BEFORE_EXPIRATION;
112      case "graceloginsremaining":
113      case "grace-logins-remaining":
114      case "grace_logins_remaining":
115      case "grace logins remaining":
116        return GRACE_LOGINS_REMAINING;
117      default:
118        return null;
119    }
120  }
121
122
123
124  /**
125   * Retrieves a string representation for this password policy warning type.
126   *
127   * @return  A string representation for this password policy warning type.
128   */
129  @Override()
130  public String toString()
131  {
132    return name;
133  }
134}