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 warnings that may be 028 * included in the password policy response control defined in 029 * draft-behera-ldap-password-policy. 030 */ 031public enum PasswordPolicyWarningType 032{ 033 /** 034 * The warning type that will be used to indicate that the password will 035 * expire in the near future and to provide the length of time in seconds 036 * until expiration. 037 */ 038 TIME_BEFORE_EXPIRATION((byte) 0x80, 039 INFO_PWPWARNTYPE_DESCRIPTION_TIME_BEFORE_EXPIRATION.get()), 040 041 /** 042 * The warning type that will be used to indicate that the user is 043 * authenticating using a grace login and to provide the number of grace 044 * logins that the user has left. 045 */ 046 GRACE_LOGINS_REMAINING((byte) 0x81, 047 INFO_PWPWARNTYPE_DESCRIPTION_GRACE_LOGINS_REMAINING.get()); 048 049 /** A lookup table for resolving a warning type from its BER type. */ 050 private static final Map<Byte, PasswordPolicyWarningType> TABLE = new HashMap<>(); 051 static 052 { 053 for (PasswordPolicyWarningType value : PasswordPolicyWarningType.values()) 054 { 055 TABLE.put(value.type, value); 056 } 057 } 058 059 /** The BER type to use for the associated element in the password policy control. */ 060 private final byte type; 061 /** The message ID for the description of this password policy error type. */ 062 private final LocalizableMessage description; 063 064 /** 065 * Creates a new instance of a password policy warning type with the provided 066 * BER type. 067 * 068 * @param type The BER type to use for the associated element in 069 * the password policy control. 070 * @param description The message for the description of this password 071 * policy error type. 072 */ 073 private PasswordPolicyWarningType(byte type, LocalizableMessage description) 074 { 075 this.type = type; 076 this.description = description; 077 } 078 079 /** 080 * Retrieves the BER type to use for the associated element in the password 081 * policy control. 082 * 083 * @return The BER type to use for the associated element in the password 084 * policy control. 085 */ 086 public byte getType() 087 { 088 return type; 089 } 090 091 /** 092 * Retrieves the password policy warning type for the provided BER type. 093 * 094 * @param type The BER type for which to retrieve the corresponding password 095 * policy warning type. 096 * 097 * @return The requested password policy warning type, or <CODE>null</CODE> 098 * if none of the defined warning types have the provided BER type. 099 */ 100 public static PasswordPolicyWarningType valueOf(byte type) 101 { 102 return TABLE.get(Byte.valueOf(type)); 103 } 104 105 /** 106 * Retrieves a string representation of this password policy warning type. 107 * 108 * @return A string representation of this password policy warning type. 109 */ 110 @Override 111 public String toString() 112 { 113 return description != null ? description.toString() : null; 114 } 115}