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