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