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-2008 Sun Microsystems, Inc. 025 * Portions Copyright 2014 ForgeRock AS 026 */ 027package org.opends.server.api; 028import org.forgerock.i18n.LocalizableMessage; 029 030 031 032import java.util.List; 033import java.util.Set; 034 035import org.opends.server.admin.std.server.PasswordValidatorCfg; 036import org.forgerock.opendj.config.server.ConfigException; 037import org.opends.server.types.*; 038import org.forgerock.opendj.ldap.ByteString; 039import org.forgerock.i18n.LocalizableMessageBuilder; 040 041 042/** 043 * This class defines the set of methods and structures that must be 044 * implemented by a Directory Server module that may be used to 045 * determine whether a proposed password is acceptable for a user. 046 * 047 * @param <T> The type of configuration handled by this password 048 * validator. 049 */ 050@org.opends.server.types.PublicAPI( 051 stability=org.opends.server.types.StabilityLevel.UNCOMMITTED, 052 mayInstantiate=false, 053 mayExtend=true, 054 mayInvoke=false) 055public abstract class PasswordValidator 056 <T extends PasswordValidatorCfg> 057{ 058 /** 059 * Initializes this password validator based on the information in 060 * the provided configuration entry. 061 * 062 * @param configuration The configuration to use to initialize 063 * this password validator. 064 * 065 * @throws ConfigException If an unrecoverable problem arises in 066 * the process of performing the 067 * initialization. 068 * 069 * @throws InitializationException If a problem occurs during 070 * initialization that is not 071 * related to the server 072 * configuration. 073 */ 074 public abstract void initializePasswordValidator(T configuration) 075 throws ConfigException, InitializationException; 076 077 078 079 /** 080 * Indicates whether the provided configuration is acceptable for 081 * this password validator. It should be possible to call this 082 * method on an uninitialized password validator instance in order 083 * to determine whether the password validator would be able to use 084 * the provided configuration. 085 * <BR><BR> 086 * Note that implementations which use a subclass of the provided 087 * configuration class will likely need to cast the configuration 088 * to the appropriate subclass type. 089 * 090 * @param configuration The password validator configuration 091 * for which to make the determination. 092 * @param unacceptableReasons A list that may be used to hold the 093 * reasons that the provided 094 * configuration is not acceptable. 095 * 096 * @return {@code true} if the provided configuration is acceptable 097 * for this password validator, or {@code false} if not. 098 */ 099 public boolean isConfigurationAcceptable( 100 PasswordValidatorCfg configuration, 101 List<LocalizableMessage> unacceptableReasons) 102 { 103 // This default implementation does not perform any special 104 // validation. It should be overridden by password validator 105 // implementations that wish to perform more detailed validation. 106 return true; 107 } 108 109 110 111 /** 112 * Performs any finalization that might be required when this 113 * password validator is unloaded. No action is taken in the 114 * default implementation. 115 */ 116 public void finalizePasswordValidator() 117 { 118 // No action is required by default. 119 } 120 121 122 123 /** 124 * Indicates whether the provided password is acceptable for use by 125 * the specified user. If the password is determined to be 126 * unacceptable, then a human-readable explanation should be 127 * appended to the provided buffer. 128 * 129 * @param newPassword The proposed clear-text password that 130 * should be validated. 131 * @param currentPasswords The set of clear-text current passwords 132 * for the user (if available). Note that 133 * the current passwords may not always be 134 * available, and this may not comprise 135 * entire set of passwords currently 136 * for the user. 137 * @param operation The operation that is being used to set 138 * the password. It may be an add, a 139 * modify, or a password modify operation. 140 * @param userEntry The entry for the user whose password 141 * is being changed. 142 * @param invalidReason The buffer to which the human-readable 143 * explanation should be appended if it is 144 * determined that the password is not 145 * acceptable. 146 * 147 * @return {@code true} if the password is acceptable, or 148 * {@code false} if not. 149 */ 150 public abstract boolean passwordIsAcceptable(ByteString newPassword, 151 Set<ByteString> currentPasswords, 152 Operation operation, 153 Entry userEntry, 154 LocalizableMessageBuilder invalidReason); 155} 156