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