001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2009 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027package org.opends.server.controls; 028 029import static org.opends.messages.ProtocolMessages.*; 030 031import java.util.HashMap; 032import java.util.Map; 033 034import org.forgerock.i18n.LocalizableMessage; 035 036/** 037 * This enumeration defines the set of password policy warnings that may be 038 * included in the password policy response control defined in 039 * draft-behera-ldap-password-policy. 040 */ 041public enum PasswordPolicyWarningType 042{ 043 /** 044 * The warning type that will be used to indicate that the password will 045 * expire in the near future and to provide the length of time in seconds 046 * until expiration. 047 */ 048 TIME_BEFORE_EXPIRATION((byte) 0x80, 049 INFO_PWPWARNTYPE_DESCRIPTION_TIME_BEFORE_EXPIRATION.get()), 050 051 /** 052 * The warning type that will be used to indicate that the user is 053 * authenticating using a grace login and to provide the number of grace 054 * logins that the user has left. 055 */ 056 GRACE_LOGINS_REMAINING((byte) 0x81, 057 INFO_PWPWARNTYPE_DESCRIPTION_GRACE_LOGINS_REMAINING.get()); 058 059 /** A lookup table for resolving a warning type from its BER type. */ 060 private static final Map<Byte, PasswordPolicyWarningType> TABLE = new HashMap<>(); 061 static 062 { 063 for (PasswordPolicyWarningType value : PasswordPolicyWarningType.values()) 064 { 065 TABLE.put(value.type, value); 066 } 067 } 068 069 /** The BER type to use for the associated element in the password policy control. */ 070 private final byte type; 071 /** The message ID for the description of this password policy error type. */ 072 private final LocalizableMessage description; 073 074 /** 075 * Creates a new instance of a password policy warning type with the provided 076 * BER type. 077 * 078 * @param type The BER type to use for the associated element in 079 * the password policy control. 080 * @param description The message for the description of this password 081 * policy error type. 082 */ 083 private PasswordPolicyWarningType(byte type, LocalizableMessage description) 084 { 085 this.type = type; 086 this.description = description; 087 } 088 089 /** 090 * Retrieves the BER type to use for the associated element in the password 091 * policy control. 092 * 093 * @return The BER type to use for the associated element in the password 094 * policy control. 095 */ 096 public byte getType() 097 { 098 return type; 099 } 100 101 /** 102 * Retrieves the password policy warning type for the provided BER type. 103 * 104 * @param type The BER type for which to retrieve the corresponding password 105 * policy warning type. 106 * 107 * @return The requested password policy warning type, or <CODE>null</CODE> 108 * if none of the defined warning types have the provided BER type. 109 */ 110 public static PasswordPolicyWarningType valueOf(byte type) 111 { 112 return TABLE.get(Byte.valueOf(type)); 113 } 114 115 /** 116 * Retrieves a string representation of this password policy warning type. 117 * 118 * @return A string representation of this password policy warning type. 119 */ 120 @Override 121 public String toString() 122 { 123 return description != null ? description.toString() : null; 124 } 125}