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