001/* 002 * Copyright 2007-2023 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2007-2023 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-2023 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 error 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 PasswordPolicyErrorType 064{ 065 /** 066 * The error type that indicates the user's password is expired. 067 */ 068 PASSWORD_EXPIRED("password expired", 0), 069 070 071 072 /** 073 * The error type that indicates the user's account is locked or disabled. 074 */ 075 ACCOUNT_LOCKED("account locked", 1), 076 077 078 079 /** 080 * The error type that indicates the user's password must be changed before 081 * any other operation will be allowed. 082 */ 083 CHANGE_AFTER_RESET("change after reset", 2), 084 085 086 087 /** 088 * The error type that indicates that user password changes aren't allowed. 089 */ 090 PASSWORD_MOD_NOT_ALLOWED("password mod not allowed", 3), 091 092 093 094 /** 095 * The error type that indicates the user must provide the current password 096 * when attempting to set a new one. 097 */ 098 MUST_SUPPLY_OLD_PASSWORD("must supply old password", 4), 099 100 101 102 /** 103 * The error type that indicates the proposed password is too weak to be 104 * acceptable. 105 */ 106 INSUFFICIENT_PASSWORD_QUALITY("insufficient password quality", 5), 107 108 109 110 /** 111 * The error type that indicates the proposed password is too short. 112 */ 113 PASSWORD_TOO_SHORT("password too short", 6), 114 115 116 117 /** 118 * The error type that indicates the user's password cannot be changed because 119 * it has not been long enough since it was last changed. 120 */ 121 PASSWORD_TOO_YOUNG("password too young", 7), 122 123 124 125 /** 126 * The error type that indicates the proposed password is already in the 127 * password history. 128 */ 129 PASSWORD_IN_HISTORY("password in history", 8); 130 131 132 133 // The numeric value associated with this password policy error type. 134 private final int value; 135 136 // The human-readable name for this password policy error type. 137 @NotNull private final String name; 138 139 140 141 /** 142 * Creates a new password policy error type with the provided information. 143 * 144 * @param name The human-readable name for this error type. 145 * @param value The numeric value associated with this error type. 146 */ 147 PasswordPolicyErrorType(@NotNull final String name, final int value) 148 { 149 this.name = name; 150 this.value = value; 151 } 152 153 154 155 /** 156 * Retrieves the human-readable name for this password policy error type. 157 * 158 * @return The human-readable name for this password policy error type. 159 */ 160 @NotNull() 161 public String getName() 162 { 163 return name; 164 } 165 166 167 168 /** 169 * Retrieves the integer value for this password policy error type. 170 * 171 * @return The integer value for this password policy error type. 172 */ 173 public int intValue() 174 { 175 return value; 176 } 177 178 179 180 /** 181 * Retrieves the password policy error type with the specified int value. 182 * 183 * @param intValue The numeric value associated with the error type. 184 * 185 * @return The associated error type, or {@code null} if there is no 186 * password policy error type with the specified set of values. 187 */ 188 @Nullable() 189 public static PasswordPolicyErrorType valueOf(final int intValue) 190 { 191 switch (intValue) 192 { 193 case 0: 194 return PASSWORD_EXPIRED; 195 196 case 1: 197 return ACCOUNT_LOCKED; 198 199 case 2: 200 return CHANGE_AFTER_RESET; 201 202 case 3: 203 return PASSWORD_MOD_NOT_ALLOWED; 204 205 case 4: 206 return MUST_SUPPLY_OLD_PASSWORD; 207 208 case 5: 209 return INSUFFICIENT_PASSWORD_QUALITY; 210 211 case 6: 212 return PASSWORD_TOO_SHORT; 213 214 case 7: 215 return PASSWORD_TOO_YOUNG; 216 217 case 8: 218 return PASSWORD_IN_HISTORY; 219 220 default: 221 return null; 222 } 223 } 224 225 226 227 /** 228 * Retrieves the password policy error type with the specified name. 229 * 230 * @param name The name of the password policy error type to retrieve. It 231 * must not be {@code null}. 232 * 233 * @return The requested password policy error type, or {@code null} if no 234 * such type is defined. 235 */ 236 @Nullable() 237 public static PasswordPolicyErrorType forName(@NotNull final String name) 238 { 239 switch (StaticUtils.toLowerCase(name)) 240 { 241 case "passwordexpired": 242 case "password-expired": 243 case "password_expired": 244 case "password expired": 245 return PASSWORD_EXPIRED; 246 case "accountlocked": 247 case "account-locked": 248 case "account_locked": 249 case "account locked": 250 return ACCOUNT_LOCKED; 251 case "changeafterreset": 252 case "change-after-reset": 253 case "change_after_reset": 254 case "change after reset": 255 return CHANGE_AFTER_RESET; 256 case "passwordmodnotallowed": 257 case "password-mod-not-allowed": 258 case "password_mod_not_allowed": 259 case "password mod not allowed": 260 return PASSWORD_MOD_NOT_ALLOWED; 261 case "mustsupplyoldpassword": 262 case "must-supply-old-password": 263 case "must_supply_old_password": 264 case "must supply old password": 265 return MUST_SUPPLY_OLD_PASSWORD; 266 case "insufficientpasswordquality": 267 case "insufficient-password-quality": 268 case "insufficient_password_quality": 269 case "insufficient password quality": 270 return INSUFFICIENT_PASSWORD_QUALITY; 271 case "passwordtooshort": 272 case "password-too-short": 273 case "password_too_short": 274 case "password too short": 275 return PASSWORD_TOO_SHORT; 276 case "passwordtooyoung": 277 case "password-too-young": 278 case "password_too_young": 279 case "password too young": 280 return PASSWORD_TOO_YOUNG; 281 case "passwordinhistory": 282 case "password-in-history": 283 case "password_in_history": 284 case "password in history": 285 return PASSWORD_IN_HISTORY; 286 default: 287 return null; 288 } 289 } 290 291 292 293 /** 294 * Retrieves a string representation for this password policy error type. 295 * 296 * @return A string representation for this password policy error type. 297 */ 298 @Override() 299 @NotNull() 300 public String toString() 301 { 302 return name; 303 } 304}