001/*
002 * Copyright 2007-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2007-2018 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.experimental;
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-10.
034 */
035@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
036public enum DraftBeheraLDAPPasswordPolicy10WarningType
037{
038  /**
039   * The warning type used to indicate that the user's password will expire in
040   * the near future and provide the length of time until it does expire.
041   */
042  TIME_BEFORE_EXPIRATION("time before expiration"),
043
044
045
046  /**
047   * The warning type used to indicate that the user's password is expired but
048   * that the user may have grace logins remaining, or that a grace login was
049   * used in the associated bind.
050   */
051  GRACE_LOGINS_REMAINING("grace logins remaining");
052
053
054
055  // The human-readable name for this password policy warning type.
056  private final String name;
057
058
059
060  /**
061   * Creates a new password policy warning type with the provided name.
062   *
063   * @param  name The human-readable name for this warning type.
064   */
065  DraftBeheraLDAPPasswordPolicy10WarningType(final String name)
066  {
067    this.name = name;
068  }
069
070
071
072  /**
073   * Retrieves the human-readable name for this password policy warning type.
074   *
075   * @return  The human-readable name for this password policy warning type.
076   */
077  public String getName()
078  {
079    return name;
080  }
081
082
083
084  /**
085   * Retrieves the password policy warning type with the specified name.
086   *
087   * @param  name  The name of the password policy warning type to retrieve.  It
088   *               must not be {@code null}.
089   *
090   * @return  The requested password policy warning type, or {@code null} if no
091   *          such type is defined.
092   */
093  public static DraftBeheraLDAPPasswordPolicy10WarningType
094                     forName(final String name)
095  {
096    switch (StaticUtils.toLowerCase(name))
097    {
098      case "timebeforeexpiration":
099      case "time-before-expiration":
100      case "time_before_expiration":
101      case "time before expiration":
102        return TIME_BEFORE_EXPIRATION;
103      case "graceloginsremaining":
104      case "grace-logins-remaining":
105      case "grace_logins_remaining":
106      case "grace logins remaining":
107        return GRACE_LOGINS_REMAINING;
108      default:
109        return null;
110    }
111  }
112
113
114
115  /**
116   * Retrieves a string representation for this password policy warning type.
117   *
118   * @return  A string representation for this password policy warning type.
119   */
120  @Override()
121  public String toString()
122  {
123    return name;
124  }
125}