001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2006-2009 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2015 ForgeRock AS. 016 */ 017package org.opends.server.controls; 018 019import static org.opends.messages.ProtocolMessages.*; 020 021import java.util.HashMap; 022import java.util.Map; 023 024import org.forgerock.i18n.LocalizableMessage; 025 026/** 027 * This enumeration defines the set of password policy errors that may be 028 * included in the password policy response control defined in 029 * draft-behera-ldap-password-policy. 030 */ 031public enum PasswordPolicyErrorType 032{ 033 /** 034 * The error type that will be used to indicate that the user's password is 035 * expired. 036 */ 037 PASSWORD_EXPIRED(0, 038 INFO_PWPERRTYPE_DESCRIPTION_PASSWORD_EXPIRED.get()), 039 040 041 042 /** 043 * The error type that will be used to indicate that the user's account is 044 * locked. 045 */ 046 ACCOUNT_LOCKED(1, 047 INFO_PWPERRTYPE_DESCRIPTION_ACCOUNT_LOCKED.get()), 048 049 050 051 /** 052 * The error type that will be used to indicate that the user's password must 053 * be changed because it has been administratively reset. 054 */ 055 CHANGE_AFTER_RESET(2, 056 INFO_PWPERRTYPE_DESCRIPTION_CHANGE_AFTER_RESET.get()), 057 058 059 060 /** 061 * The error type that will be used to indicate that user password changes are 062 * not allowed. 063 */ 064 PASSWORD_MOD_NOT_ALLOWED( 065 3, 066 INFO_PWPERRTYPE_DESCRIPTION_PASSWORD_MOD_NOT_ALLOWED.get()), 067 068 069 070 /** 071 * The error type that will be used to indicate that the user's current 072 * password must be provided in order to choose a new password. 073 */ 074 MUST_SUPPLY_OLD_PASSWORD( 075 4, 076 INFO_PWPERRTYPE_DESCRIPTION_MUST_SUPPLY_OLD_PASSWORD.get()), 077 078 079 080 /** 081 * The error type that will be used to indicate that the provided password is 082 * not acceptable according to the configured password validators. 083 */ 084 INSUFFICIENT_PASSWORD_QUALITY( 085 5, 086 INFO_PWPERRTYPE_DESCRIPTION_INSUFFICIENT_PASSWORD_QUALITY.get()), 087 088 089 090 /** 091 * The error type that will be used to indicate that the provided password is 092 * too short. 093 */ 094 PASSWORD_TOO_SHORT(6, 095 INFO_PWPERRTYPE_DESCRIPTION_PASSWORD_TOO_SHORT.get()), 096 097 098 099 /** 100 * The error type that will be used to indicate that the user's password is 101 * too young (i.e., it was changed too recently to allow it to be changed 102 * again). 103 */ 104 PASSWORD_TOO_YOUNG(7, 105 INFO_PWPERRTYPE_DESCRIPTION_PASSWORD_TOO_YOUNG.get()), 106 107 108 109 /** 110 * The error type that will be used to indicate that the provided password is 111 * in the user's password history. 112 */ 113 PASSWORD_IN_HISTORY(8, 114 INFO_PWPERRTYPE_DESCRIPTION_PASSWORD_IN_HISTORY.get()); 115 116 117 118 /** A lookup table for resolving an error type from its integer value. */ 119 private static final Map<Integer, PasswordPolicyErrorType> TABLE = new HashMap<>(); 120 static 121 { 122 for (PasswordPolicyErrorType type : PasswordPolicyErrorType.values()) 123 { 124 TABLE.put(type.value, type); 125 TABLE.put(type.value, type); 126 } 127 } 128 129 130 131 /** 132 * The integer value associated with the error type to use in the associated 133 * enumerated element in the password policy response control. 134 */ 135 private int value; 136 137 /** The message ID for the description of this password policy error type. */ 138 private LocalizableMessage description; 139 140 141 142 /** 143 * Creates a new instance of a password policy error type with the provided 144 * value. 145 * 146 * @param value The integer value associated with the error type to 147 * use in the associated enumerated element in the 148 * password policy response control. 149 * @param description The message for the description of this password 150 * policy error type. 151 */ 152 private PasswordPolicyErrorType(int value, LocalizableMessage description) 153 { 154 this.value = value; 155 this.description = description; 156 } 157 158 159 160 /** 161 * Retrieves the integer value associated with the error type to use in the 162 * associated enumerated element in the password policy response control. 163 * 164 * @return The integer value associated with the error type to use in the 165 * associated enumerated element in the password policy response 166 * control. 167 */ 168 public int intValue() 169 { 170 return value; 171 } 172 173 174 175 /** 176 * Retrieves the password policy error type for the provided integer value. 177 * 178 * @param value The value for which to retrieve the corresponding error 179 * type. 180 * 181 * @return The requested password policy error type, or <CODE>null</CODE> if 182 * the provided value does not match any error types. 183 */ 184 public static PasswordPolicyErrorType valueOf(int value) 185 { 186 return TABLE.get(Integer.valueOf(value)); 187 } 188 189 190 191 /** 192 * Retrieves a string representation of this password policy error type. 193 * 194 * @return A string representation of this password policy error type. 195 */ 196 @Override 197 public String toString() 198 { 199 return description.toString(); 200 } 201} 202