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 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2006-2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.api; 028 import org.opends.messages.Message; 029 030 031 032 import java.util.List; 033 034 import org.opends.server.admin.std.server.PasswordGeneratorCfg; 035 import org.opends.server.config.ConfigException; 036 import org.opends.server.types.ByteString; 037 import org.opends.server.types.DirectoryException; 038 import org.opends.server.types.Entry; 039 import org.opends.server.types.InitializationException; 040 041 042 043 /** 044 * This class defines a set of methods and structures that must be 045 * implemented by a Directory Server module that may be used to 046 * generate user passwords. The password generator is included as part 047 * of a password policy, and is used by the password modify extended 048 * operation to construct a new password for the user if that option 049 * is chosen. 050 * 051 * @param <T> The type of configuration handled by this password 052 * generator. 053 */ 054 @org.opends.server.types.PublicAPI( 055 stability=org.opends.server.types.StabilityLevel.UNCOMMITTED, 056 mayInstantiate=false, 057 mayExtend=true, 058 mayInvoke=false) 059 public abstract class PasswordGenerator 060 <T extends PasswordGeneratorCfg> 061 { 062 /** 063 * Initializes this password generator based on the information in 064 * the provided configuration entry. 065 * 066 * @param configuration The configuration to use to initialize 067 * this password validator. 068 * 069 * @throws ConfigException If an unrecoverable problem arises in 070 * the process of performing the 071 * initialization. 072 * 073 * @throws InitializationException If a problem occurs during 074 * initialization that is not 075 * related to the server 076 * configuration. 077 */ 078 public abstract void initializePasswordGenerator(T configuration) 079 throws ConfigException, InitializationException; 080 081 082 083 /** 084 * Indicates whether the provided configuration is acceptable for 085 * this password generator. It should be possible to call this 086 * method on an uninitialized password generator instance in order 087 * to determine whether the password generator would be able to use 088 * the provided configuration. 089 * <BR><BR> 090 * Note that implementations which use a subclass of the provided 091 * configuration class will likely need to cast the configuration 092 * to the appropriate subclass type. 093 * 094 * @param configuration The password generator configuration 095 * for which to make the determination. 096 * @param unacceptableReasons A list that may be used to hold the 097 * reasons that the provided 098 * configuration is not acceptable. 099 * 100 * @return {@code true} if the provided configuration is acceptable 101 * for this password generator, or {@code false} if not. 102 */ 103 public boolean isConfigurationAcceptable( 104 PasswordGeneratorCfg configuration, 105 List<Message> unacceptableReasons) 106 { 107 // This default implementation does not perform any special 108 // validation. It should be overridden by password generator 109 // implementations that wish to perform more detailed validation. 110 return true; 111 } 112 113 114 115 /** 116 * Performs any finalization work that may be necessary when this 117 * password generator is taken out of service. 118 */ 119 public void finalizePasswordGenerator() 120 { 121 // No action is performed by default. 122 } 123 124 125 126 /** 127 * Generates a password for the user whose account is contained in 128 * the specified entry. 129 * 130 * @param userEntry The entry for the user for whom the password 131 * is to be generated. 132 * 133 * @return The password that has been generated for the user. 134 * 135 * @throws DirectoryException If a problem occurs while attempting 136 * to generate the password. 137 */ 138 public abstract ByteString generatePassword(Entry userEntry) 139 throws DirectoryException; 140 } 141