PasswordPolicyImportPlugin.java revision 1638
5826N/A/*
5826N/A * CDDL HEADER START
5826N/A *
5826N/A * The contents of this file are subject to the terms of the
5826N/A * Common Development and Distribution License, Version 1.0 only
5826N/A * (the "License"). You may not use this file except in compliance
5826N/A * with the License.
5826N/A *
5826N/A * You can obtain a copy of the license at
5826N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
6982N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
6982N/A * See the License for the specific language governing permissions
5826N/A * and limitations under the License.
5826N/A *
5826N/A * When distributing Covered Code, include this CDDL HEADER in each
5826N/A * file and include the License file at
6982N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
6982N/A * add the following below this CDDL HEADER, with the fields enclosed
6982N/A * by brackets "[]" replaced with your own identifying information:
6982N/A * Portions Copyright [yyyy] [name of copyright owner]
5826N/A *
5826N/A * CDDL HEADER END
5826N/A *
5826N/A *
5826N/A * Portions Copyright 2006-2007 Sun Microsystems, Inc.
5826N/A */
5826N/Apackage org.opends.server.plugins;
5826N/A
5826N/A
5826N/A
5826N/Aimport java.util.ArrayList;
5826N/Aimport java.util.HashMap;
5826N/Aimport java.util.HashSet;
5826N/Aimport java.util.Iterator;
5826N/Aimport java.util.LinkedHashSet;
5826N/Aimport java.util.List;
5826N/Aimport java.util.Set;
5826N/Aimport java.util.concurrent.CopyOnWriteArrayList;
5826N/A
5826N/Aimport org.opends.server.admin.server.ConfigurationChangeListener;
5826N/Aimport org.opends.server.admin.std.meta.PluginCfgDefn;
5826N/Aimport org.opends.server.admin.std.server.PasswordPolicyImportPluginCfg;
5826N/Aimport org.opends.server.api.Backend;
5826N/Aimport org.opends.server.api.ImportTaskListener;
5826N/Aimport org.opends.server.api.PasswordStorageScheme;
5826N/Aimport org.opends.server.api.plugin.DirectoryServerPlugin;
5826N/Aimport org.opends.server.api.plugin.LDIFPluginResult;
5826N/Aimport org.opends.server.api.plugin.PluginType;
5826N/Aimport org.opends.server.config.ConfigException;
5826N/Aimport org.opends.server.core.DirectoryServer;
5826N/Aimport org.opends.server.core.PasswordPolicy;
5826N/Aimport org.opends.server.loggers.debug.DebugTracer;
5826N/Aimport org.opends.server.schema.AuthPasswordSyntax;
5826N/Aimport org.opends.server.schema.UserPasswordSyntax;
5826N/Aimport org.opends.server.types.Attribute;
5826N/Aimport org.opends.server.types.AttributeType;
5826N/Aimport org.opends.server.types.AttributeValue;
5826N/Aimport org.opends.server.types.ByteString;
5826N/Aimport org.opends.server.types.ConfigChangeResult;
5826N/Aimport org.opends.server.types.DebugLogLevel;
5826N/Aimport org.opends.server.types.DirectoryException;
5826N/Aimport org.opends.server.types.DN;
5826N/Aimport org.opends.server.types.Entry;
5826N/Aimport org.opends.server.types.ErrorLogCategory;
5826N/Aimport org.opends.server.types.ErrorLogSeverity;
5826N/Aimport org.opends.server.types.LDIFImportConfig;
5826N/Aimport org.opends.server.types.ResultCode;
5826N/A
5826N/Aimport static org.opends.server.config.ConfigConstants.*;
5826N/Aimport static org.opends.server.extensions.ExtensionsConstants.*;
5826N/Aimport static org.opends.server.loggers.ErrorLogger.*;
5826N/Aimport static org.opends.server.loggers.debug.DebugLogger.*;
5826N/Aimport static org.opends.server.messages.MessageHandler.*;
5826N/Aimport static org.opends.server.messages.PluginMessages.*;
5826N/Aimport static org.opends.server.schema.SchemaConstants.*;
5826N/Aimport static org.opends.server.util.StaticUtils.*;
5826N/A
5826N/A
5826N/A
5826N/A/**
5826N/A * This class implements a Directory Server plugin that performs various
5826N/A * password policy processing during an LDIF import. In particular, it ensures
5826N/A * that all of the password values are properly encoded before they are stored.
5826N/A */
5826N/Apublic final class PasswordPolicyImportPlugin
5826N/A extends DirectoryServerPlugin<PasswordPolicyImportPluginCfg>
5826N/A implements ConfigurationChangeListener<PasswordPolicyImportPluginCfg>,
5826N/A ImportTaskListener
5826N/A{
5826N/A /**
5826N/A * The tracer object for the debug logger.
5826N/A */
5826N/A private static final DebugTracer TRACER = getTracer();
5826N/A
5826N/A
5826N/A
5826N/A // The attribute type used to specify the password policy for an entry.
5826N/A private AttributeType customPolicyAttribute;
5826N/A
5826N/A // The set of attribute types defined in the schema with the auth password
5826N/A // syntax.
5826N/A private AttributeType[] authPasswordTypes;
5826N/A
5826N/A // The set of attribute types defined in the schema with the user password
5826N/A // syntax.
5826N/A private AttributeType[] userPasswordTypes;
5826N/A
5826N/A // The set of password storage schemes to use for the various password
5826N/A // policies defined in the server.
5826N/A private HashMap<DN,PasswordStorageScheme[]> schemesByPolicy;
5826N/A
5826N/A // The default password storage schemes for auth password attributes.
5826N/A private PasswordStorageScheme[] defaultAuthPasswordSchemes;
5826N/A
5826N/A // The default password storage schemes for user password attributes.
5826N/A private PasswordStorageScheme[] defaultUserPasswordSchemes;
5826N/A
5826N/A
5826N/A
5826N/A /**
5826N/A * Creates a new instance of this Directory Server plugin. Every plugin must
5826N/A * implement a default constructor (it is the only one that will be used to
5826N/A * create plugins defined in the configuration), and every plugin constructor
5826N/A * must call {@code super()} as its first element.
5826N/A */
5826N/A public PasswordPolicyImportPlugin()
5826N/A {
5826N/A super();
5826N/A }
5826N/A
5826N/A
5826N/A
5826N/A /**
5826N/A * {@inheritDoc}
5826N/A */
5826N/A @Override()
5826N/A public final void initializePlugin(Set<PluginType> pluginTypes,
5826N/A PasswordPolicyImportPluginCfg configuration)
5826N/A throws ConfigException
5826N/A {
5826N/A configuration.addPasswordPolicyImportChangeListener(this);
5826N/A
5826N/A customPolicyAttribute =
5826N/A DirectoryServer.getAttributeType(OP_ATTR_PWPOLICY_POLICY_DN, true);
5826N/A
5826N/A
5826N/A // Make sure that the plugin has been enabled for the appropriate types.
5826N/A for (PluginType t : pluginTypes)
5826N/A {
5826N/A switch (t)
5826N/A {
5826N/A case LDIF_IMPORT:
5826N/A // This is the only acceptable type.
5826N/A break;
5826N/A
5826N/A
5826N/A default:
5826N/A int msgID = MSGID_PLUGIN_PWPIMPORT_INVALID_PLUGIN_TYPE;
5826N/A String message = getMessage(msgID, t.toString());
5826N/A throw new ConfigException(msgID, message);
5826N/A }
5826N/A }
5826N/A
5826N/A
5826N/A // Get the set of default password storage schemes for auth password
5826N/A // attributes.
5826N/A PasswordPolicy defaultPolicy = DirectoryServer.getDefaultPasswordPolicy();
5826N/A Set<String> authSchemesSet =
5826N/A configuration.getDefaultAuthPasswordStorageScheme();
5826N/A if ((authSchemesSet == null) || authSchemesSet.isEmpty())
5826N/A {
5826N/A if (defaultPolicy.usesAuthPasswordSyntax())
5826N/A {
5826N/A CopyOnWriteArrayList<PasswordStorageScheme> schemeList =
5826N/A defaultPolicy.getDefaultStorageSchemes();
5826N/A defaultAuthPasswordSchemes =
5826N/A new PasswordStorageScheme[schemeList.size()];
5826N/A schemeList.toArray(defaultAuthPasswordSchemes);
5826N/A }
5826N/A else
5826N/A {
5826N/A defaultAuthPasswordSchemes = new PasswordStorageScheme[1];
5826N/A defaultAuthPasswordSchemes[0] =
5826N/A DirectoryServer.getAuthPasswordStorageScheme(
5826N/A AUTH_PASSWORD_SCHEME_NAME_SALTED_SHA_1);
5826N/A if (defaultAuthPasswordSchemes[0] == null)
5826N/A {
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_NO_DEFAULT_AUTH_SCHEMES;
5826N/A String message = getMessage(msgID,
5826N/A AUTH_PASSWORD_SCHEME_NAME_SALTED_SHA_1);
5826N/A throw new ConfigException(msgID, message);
5826N/A }
5826N/A }
5826N/A }
5826N/A else
5826N/A {
5826N/A defaultAuthPasswordSchemes =
5826N/A new PasswordStorageScheme[authSchemesSet.size()];
5826N/A int i=0;
5826N/A for (String schemeName : authSchemesSet)
5826N/A {
5826N/A defaultAuthPasswordSchemes[i] =
5826N/A DirectoryServer.getAuthPasswordStorageScheme(schemeName);
5826N/A if (defaultAuthPasswordSchemes[i] == null)
5826N/A {
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_INVALID_DEFAULT_AUTH_SCHEME;
5826N/A String message = getMessage(msgID, schemeName);
5826N/A throw new ConfigException(msgID, message);
5826N/A }
5826N/A i++;
5826N/A }
5826N/A }
5826N/A
5826N/A
5826N/A // Get the set of default password storage schemes for user password
5826N/A // attributes.
5826N/A Set<String> userSchemeSet =
5826N/A configuration.getDefaultUserPasswordStorageScheme();
5826N/A if ((userSchemeSet == null) || userSchemeSet.isEmpty())
5826N/A {
5826N/A if (! defaultPolicy.usesAuthPasswordSyntax())
5826N/A {
5826N/A CopyOnWriteArrayList<PasswordStorageScheme> schemeList =
5826N/A defaultPolicy.getDefaultStorageSchemes();
5826N/A defaultUserPasswordSchemes =
5826N/A new PasswordStorageScheme[schemeList.size()];
5826N/A schemeList.toArray(defaultUserPasswordSchemes);
5826N/A }
5826N/A else
5826N/A {
5826N/A defaultUserPasswordSchemes = new PasswordStorageScheme[1];
5826N/A defaultUserPasswordSchemes[0] =
5826N/A DirectoryServer.getPasswordStorageScheme(
5826N/A toLowerCase(STORAGE_SCHEME_NAME_SALTED_SHA_1));
5826N/A if (defaultUserPasswordSchemes[0] == null)
5826N/A {
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_NO_DEFAULT_USER_SCHEMES;
5826N/A String message = getMessage(msgID, STORAGE_SCHEME_NAME_SALTED_SHA_1);
5826N/A throw new ConfigException(msgID, message);
5826N/A }
5826N/A }
5826N/A }
5826N/A else
5826N/A {
5826N/A defaultUserPasswordSchemes =
5826N/A new PasswordStorageScheme[userSchemeSet.size()];
5826N/A int i=0;
5826N/A for (String schemeName : userSchemeSet)
5826N/A {
5826N/A defaultUserPasswordSchemes[i] =
5826N/A DirectoryServer.getPasswordStorageScheme(toLowerCase(schemeName));
5826N/A if (defaultUserPasswordSchemes[i] == null)
5826N/A {
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_INVALID_DEFAULT_USER_SCHEME;
5826N/A String message = getMessage(msgID, schemeName);
5826N/A throw new ConfigException(msgID, message);
5826N/A }
5826N/A i++;
5826N/A }
5826N/A }
5826N/A
5826N/A processImportBegin(null, null);
5826N/A }
5826N/A
5826N/A
5826N/A
5826N/A /**
5826N/A * {@inheritDoc}
5826N/A */
5826N/A public void processImportBegin(Backend backend, LDIFImportConfig config)
5826N/A {
5826N/A // Find the set of attribute types with the auth password and user password
5826N/A // syntax defined in the schema.
5826N/A HashSet<AttributeType> authPWTypes = new HashSet<AttributeType>();
5826N/A HashSet<AttributeType> userPWTypes = new HashSet<AttributeType>();
5826N/A for (AttributeType t : DirectoryServer.getAttributeTypes().values())
5826N/A {
5826N/A if (t.getSyntaxOID().equals(SYNTAX_AUTH_PASSWORD_OID))
5826N/A {
5826N/A authPWTypes.add(t);
5826N/A }
5826N/A else if (t.getSyntaxOID().equals(SYNTAX_USER_PASSWORD_OID))
5826N/A {
5826N/A userPWTypes.add(t);
5826N/A }
5826N/A }
5826N/A
5826N/A
5826N/A // Get the set of password policies defined in the server and get the
5826N/A // attribute types associated with them.
5826N/A HashMap<DN,PasswordStorageScheme[]> schemeMap =
5826N/A new HashMap<DN,PasswordStorageScheme[]>();
5826N/A for (PasswordPolicy p : DirectoryServer.getPasswordPolicies())
5826N/A {
5826N/A CopyOnWriteArrayList<PasswordStorageScheme> schemeList =
5826N/A p.getDefaultStorageSchemes();
5826N/A PasswordStorageScheme[] schemeArray =
5826N/A new PasswordStorageScheme[schemeList.size()];
5826N/A schemeList.toArray(schemeArray);
5826N/A schemeMap.put(p.getConfigEntryDN(), schemeArray);
5826N/A }
5826N/A
5826N/A
5826N/A AttributeType[] authTypesArray = new AttributeType[authPWTypes.size()];
5826N/A AttributeType[] userTypesArray = new AttributeType[userPWTypes.size()];
5826N/A authPWTypes.toArray(authTypesArray);
5826N/A userPWTypes.toArray(userTypesArray);
5826N/A
5826N/A schemesByPolicy = schemeMap;
5826N/A authPasswordTypes = authTypesArray;
5826N/A userPasswordTypes = userTypesArray;
5826N/A }
5826N/A
5826N/A
5826N/A
5826N/A /**
5826N/A * {@inheritDoc}
5826N/A */
5826N/A public void processImportEnd(Backend backend, LDIFImportConfig config,
5826N/A boolean successful)
5826N/A {
5826N/A // No implementation is required.
5826N/A }
5826N/A
5826N/A
5826N/A
5826N/A /**
5826N/A * {@inheritDoc}
5826N/A */
5826N/A @Override()
5826N/A public final LDIFPluginResult doLDIFImport(LDIFImportConfig importConfig,
5826N/A Entry entry)
5826N/A {
5826N/A // Create a list that we will use to hold new encoded values.
5826N/A ArrayList<ByteString> encodedValueList = new ArrayList<ByteString>();
5826N/A
5826N/A
5826N/A // See if the entry explicitly states the password policy that it should
5826N/A // use. If so, then only use it to perform the encoding.
5826N/A List<Attribute> attrList = entry.getAttribute(customPolicyAttribute);
5826N/A if (attrList != null)
5826N/A {
5826N/A DN policyDN = null;
5826N/A PasswordPolicy policy = null;
5826N/ApolicyLoop:
5826N/A for (Attribute a : attrList)
5826N/A {
5826N/A for (AttributeValue v : a.getValues())
5826N/A {
5826N/A try
5826N/A {
5826N/A policyDN = DN.decode(v.getValue());
5826N/A policy = DirectoryServer.getPasswordPolicy(policyDN);
5826N/A if (policy == null)
5826N/A {
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_NO_SUCH_POLICY;
5826N/A String message = getMessage(msgID, String.valueOf(entry.getDN()),
5826N/A String.valueOf(policyDN));
5826N/A logError(ErrorLogCategory.PLUGIN, ErrorLogSeverity.SEVERE_WARNING,
5826N/A message, msgID);
5826N/A }
5826N/A break policyLoop;
5826N/A }
5826N/A catch (DirectoryException de)
5826N/A {
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_CANNOT_DECODE_POLICY_DN;
5826N/A String message = getMessage(msgID, String.valueOf(entry.getDN()),
5826N/A de.getErrorMessage());
5826N/A logError(ErrorLogCategory.PLUGIN, ErrorLogSeverity.SEVERE_WARNING,
5826N/A message, msgID);
5826N/A break policyLoop;
5826N/A }
5826N/A }
5826N/A }
5826N/A
5826N/A if (policy != null)
5826N/A {
5826N/A PasswordStorageScheme[] schemes = schemesByPolicy.get(policyDN);
5826N/A if (schemes != null)
5826N/A {
5826N/A attrList = entry.getAttribute(policy.getPasswordAttribute());
5826N/A if (attrList == null)
5826N/A {
5826N/A return LDIFPluginResult.SUCCESS;
5826N/A }
5826N/A
5826N/A for (Attribute a : attrList)
5826N/A {
5826N/A encodedValueList.clear();
5826N/A
5826N/A LinkedHashSet<AttributeValue> values = a.getValues();
5826N/A Iterator<AttributeValue> iterator = values.iterator();
5826N/A while (iterator.hasNext())
5826N/A {
5826N/A AttributeValue v = iterator.next();
5826N/A ByteString value = v.getValue();
5826N/A
5826N/A if (policy.usesAuthPasswordSyntax())
5826N/A {
5826N/A if (! AuthPasswordSyntax.isEncoded(value))
5826N/A {
5826N/A try
5826N/A {
5826N/A for (PasswordStorageScheme s : schemes)
5826N/A {
5826N/A encodedValueList.add(s.encodeAuthPassword(value));
5826N/A }
5826N/A
5826N/A iterator.remove();
5826N/A }
5826N/A catch (Exception e)
5826N/A {
5826N/A if (debugEnabled())
5826N/A {
5826N/A TRACER.debugCaught(DebugLogLevel.ERROR, e);
5826N/A }
5826N/A
5826N/A int msgID = MSGID_PLUGIN_PWPIMPORT_ERROR_ENCODING_PASSWORD;
5826N/A String message = getMessage(msgID,
5826N/A policy.getPasswordAttribute().getNameOrOID(),
5826N/A String.valueOf(entry.getDN()),
5826N/A stackTraceToSingleLineString(e));
5826N/A logError(ErrorLogCategory.PLUGIN,
5826N/A ErrorLogSeverity.SEVERE_ERROR, message, msgID);
5826N/A
5826N/A encodedValueList.clear();
5826N/A break;
5826N/A }
5826N/A }
5826N/A }
5826N/A else
5826N/A {
5826N/A if (! UserPasswordSyntax.isEncoded(value))
5826N/A {
5826N/A try
5826N/A {
5826N/A for (PasswordStorageScheme s : schemes)
5826N/A {
5826N/A encodedValueList.add(s.encodePasswordWithScheme(value));
5826N/A }
5826N/A
5826N/A iterator.remove();
5826N/A }
5826N/A catch (Exception e)
5826N/A {
5826N/A if (debugEnabled())
5826N/A {
5826N/A TRACER.debugCaught(DebugLogLevel.ERROR, e);
5826N/A }
5826N/A
5826N/A int msgID = MSGID_PLUGIN_PWPIMPORT_ERROR_ENCODING_PASSWORD;
5826N/A String message = getMessage(msgID,
5826N/A policy.getPasswordAttribute().getNameOrOID(),
5826N/A String.valueOf(entry.getDN()),
5826N/A stackTraceToSingleLineString(e));
5826N/A logError(ErrorLogCategory.PLUGIN,
5826N/A ErrorLogSeverity.SEVERE_ERROR, message, msgID);
5826N/A
5826N/A encodedValueList.clear();
5826N/A break;
5826N/A }
5826N/A }
5826N/A }
5826N/A }
5826N/A
5826N/A for (ByteString s : encodedValueList)
5826N/A {
5826N/A values.add(new AttributeValue(policy.getPasswordAttribute(), s));
5826N/A }
5826N/A }
5826N/A
5826N/A return LDIFPluginResult.SUCCESS;
5826N/A }
5826N/A }
5826N/A }
5826N/A
5826N/A
5826N/A // Iterate through the list of auth password attributes. If any of them
5826N/A // are present and their values are not encoded, then encode them with all
5826N/A // appropriate schemes.
5826N/A for (AttributeType t : authPasswordTypes)
5826N/A {
5826N/A attrList = entry.getAttribute(t);
5826N/A if ((attrList == null) || attrList.isEmpty())
5826N/A {
5826N/A continue;
5826N/A }
5826N/A
5826N/A for (Attribute a : attrList)
5826N/A {
5826N/A encodedValueList.clear();
5826N/A
5826N/A LinkedHashSet<AttributeValue> values = a.getValues();
5826N/A Iterator<AttributeValue> iterator = values.iterator();
5826N/A while (iterator.hasNext())
5826N/A {
5826N/A AttributeValue v = iterator.next();
5826N/A ByteString value = v.getValue();
5826N/A if (! AuthPasswordSyntax.isEncoded(value))
5826N/A {
5826N/A try
5826N/A {
5826N/A for (PasswordStorageScheme s : defaultAuthPasswordSchemes)
5826N/A {
5826N/A encodedValueList.add(s.encodeAuthPassword(value));
5826N/A }
5826N/A
5826N/A iterator.remove();
5826N/A }
5826N/A catch (Exception e)
5826N/A {
5826N/A if (debugEnabled())
5826N/A {
5826N/A TRACER.debugCaught(DebugLogLevel.ERROR, e);
5826N/A }
5826N/A
5826N/A int msgID = MSGID_PLUGIN_PWPIMPORT_ERROR_ENCODING_PASSWORD;
5826N/A String message = getMessage(msgID, t.getNameOrOID(),
5826N/A String.valueOf(entry.getDN()),
5826N/A stackTraceToSingleLineString(e));
5826N/A logError(ErrorLogCategory.PLUGIN, ErrorLogSeverity.SEVERE_ERROR,
5826N/A message, msgID);
5826N/A
5826N/A encodedValueList.clear();
5826N/A break;
5826N/A }
5826N/A }
5826N/A }
5826N/A
5826N/A for (ByteString s : encodedValueList)
5826N/A {
5826N/A values.add(new AttributeValue(t, s));
5826N/A }
5826N/A }
5826N/A }
5826N/A
5826N/A
5826N/A // Iterate through the list of user password attributes. If any of them
5826N/A // are present and their values are not encoded, then encode them with all
5826N/A // appropriate schemes.
5826N/A for (AttributeType t : userPasswordTypes)
5826N/A {
5826N/A attrList = entry.getAttribute(t);
5826N/A if ((attrList == null) || attrList.isEmpty())
5826N/A {
5826N/A continue;
5826N/A }
5826N/A
5826N/A for (Attribute a : attrList)
5826N/A {
5826N/A encodedValueList.clear();
5826N/A
5826N/A LinkedHashSet<AttributeValue> values = a.getValues();
5826N/A Iterator<AttributeValue> iterator = values.iterator();
5826N/A while (iterator.hasNext())
5826N/A {
5826N/A AttributeValue v = iterator.next();
5826N/A ByteString value = v.getValue();
5826N/A if (! UserPasswordSyntax.isEncoded(value))
5826N/A {
5826N/A try
5826N/A {
5826N/A for (PasswordStorageScheme s : defaultUserPasswordSchemes)
5826N/A {
5826N/A encodedValueList.add(s.encodePasswordWithScheme(value));
5826N/A }
5826N/A
5826N/A iterator.remove();
5826N/A }
5826N/A catch (Exception e)
5826N/A {
5826N/A if (debugEnabled())
5826N/A {
5826N/A TRACER.debugCaught(DebugLogLevel.ERROR, e);
5826N/A }
5826N/A
5826N/A int msgID = MSGID_PLUGIN_PWPIMPORT_ERROR_ENCODING_PASSWORD;
5826N/A String message = getMessage(msgID, t.getNameOrOID(),
5826N/A String.valueOf(entry.getDN()),
5826N/A stackTraceToSingleLineString(e));
5826N/A logError(ErrorLogCategory.PLUGIN, ErrorLogSeverity.SEVERE_ERROR,
5826N/A message, msgID);
5826N/A
5826N/A encodedValueList.clear();
5826N/A break;
5826N/A }
5826N/A }
5826N/A }
5826N/A
5826N/A for (ByteString s : encodedValueList)
5826N/A {
5826N/A values.add(new AttributeValue(t, s));
5826N/A }
5826N/A }
5826N/A }
5826N/A
5826N/A
5826N/A return LDIFPluginResult.SUCCESS;
5826N/A }
5826N/A
5826N/A
5826N/A
5826N/A /**
5826N/A * {@inheritDoc}
5826N/A */
5826N/A public boolean isConfigurationChangeAcceptable(
5826N/A PasswordPolicyImportPluginCfg configuration,
5826N/A List<String> unacceptableReasons)
5826N/A {
5826N/A boolean configAcceptable = true;
5826N/A
5826N/A // Ensure that the set of plugin types contains only LDIF import.
5826N/A for (PluginCfgDefn.PluginType pluginType : configuration.getPluginType())
5826N/A {
5826N/A switch (pluginType)
5826N/A {
5826N/A case LDIFIMPORT:
5826N/A // This is the only acceptable type.
5826N/A break;
5826N/A
5826N/A
5826N/A default:
5826N/A int msgID = MSGID_PLUGIN_PWPIMPORT_INVALID_PLUGIN_TYPE;
5826N/A String message = getMessage(msgID, pluginType.toString());
5826N/A unacceptableReasons.add(message);
5826N/A configAcceptable = false;
5826N/A }
5826N/A }
5826N/A
5826N/A
5826N/A // Get the set of default password storage schemes for auth password
5826N/A // attributes.
5826N/A Set<String> authSchemesSet =
5826N/A configuration.getDefaultAuthPasswordStorageScheme();
5826N/A if ((authSchemesSet == null) || authSchemesSet.isEmpty())
5826N/A {
5826N/A PasswordStorageScheme[] defaultAuthSchemes = new PasswordStorageScheme[1];
5826N/A defaultAuthSchemes[0] =
5826N/A DirectoryServer.getAuthPasswordStorageScheme(
5826N/A AUTH_PASSWORD_SCHEME_NAME_SALTED_SHA_1);
5826N/A if (defaultAuthSchemes[0] == null)
5826N/A {
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_NO_DEFAULT_AUTH_SCHEMES;
5826N/A String message = getMessage(msgID,
5826N/A AUTH_PASSWORD_SCHEME_NAME_SALTED_SHA_1);
5826N/A unacceptableReasons.add(message);
5826N/A configAcceptable = false;
5826N/A }
5826N/A }
5826N/A else
5826N/A {
5826N/A PasswordStorageScheme[] defaultAuthSchemes =
5826N/A new PasswordStorageScheme[authSchemesSet.size()];
5826N/A int i=0;
5826N/A for (String schemeName : authSchemesSet)
5826N/A {
5826N/A defaultAuthSchemes[i] =
5826N/A DirectoryServer.getAuthPasswordStorageScheme(schemeName);
5826N/A if (defaultAuthSchemes[i] == null)
5826N/A {
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_INVALID_DEFAULT_AUTH_SCHEME;
5826N/A String message = getMessage(msgID, schemeName);
5826N/A unacceptableReasons.add(message);
5826N/A configAcceptable = false;
5826N/A }
5826N/A i++;
5826N/A }
5826N/A }
5826N/A
5826N/A
5826N/A // Get the set of default password storage schemes for user password
5826N/A // attributes.
5826N/A Set<String> userSchemeSet =
5826N/A configuration.getDefaultUserPasswordStorageScheme();
5826N/A if ((userSchemeSet == null) || userSchemeSet.isEmpty())
5826N/A {
5826N/A PasswordStorageScheme[] defaultUserSchemes = new PasswordStorageScheme[1];
5826N/A defaultUserSchemes[0] =
5826N/A DirectoryServer.getPasswordStorageScheme(
5826N/A toLowerCase(STORAGE_SCHEME_NAME_SALTED_SHA_1));
5826N/A if (defaultUserSchemes[0] == null)
5826N/A {
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_NO_DEFAULT_USER_SCHEMES;
5826N/A String message = getMessage(msgID, STORAGE_SCHEME_NAME_SALTED_SHA_1);
5826N/A unacceptableReasons.add(message);
5826N/A configAcceptable = false;
5826N/A }
5826N/A }
5826N/A else
5826N/A {
5826N/A PasswordStorageScheme[] defaultUserSchemes =
5826N/A new PasswordStorageScheme[userSchemeSet.size()];
5826N/A int i=0;
5826N/A for (String schemeName : userSchemeSet)
5826N/A {
5826N/A defaultUserSchemes[i] =
5826N/A DirectoryServer.getPasswordStorageScheme(toLowerCase(schemeName));
5826N/A if (defaultUserSchemes[i] == null)
5826N/A {
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_INVALID_DEFAULT_USER_SCHEME;
5826N/A String message = getMessage(msgID, schemeName);
5826N/A unacceptableReasons.add(message);
5826N/A configAcceptable = false;
5826N/A }
5826N/A i++;
5826N/A }
5826N/A }
5826N/A
5826N/A
5826N/A return configAcceptable;
5826N/A }
5826N/A
5826N/A
5826N/A
5826N/A /**
5826N/A * {@inheritDoc}
5826N/A */
5826N/A public ConfigChangeResult applyConfigurationChange(
5826N/A PasswordPolicyImportPluginCfg configuration)
5826N/A {
5826N/A ResultCode resultCode = ResultCode.SUCCESS;
5826N/A boolean adminActionRequired = false;
5826N/A ArrayList<String> messages = new ArrayList<String>();
5826N/A
5826N/A
5826N/A // Get the set of default password storage schemes for auth password
5826N/A // attributes.
5826N/A PasswordPolicy defaultPolicy = DirectoryServer.getDefaultPasswordPolicy();
5826N/A PasswordStorageScheme[] defaultAuthSchemes;
5826N/A Set<String> authSchemesSet =
5826N/A configuration.getDefaultAuthPasswordStorageScheme();
5826N/A if ((authSchemesSet == null) || authSchemesSet.isEmpty())
5826N/A {
5826N/A if (defaultPolicy.usesAuthPasswordSyntax())
5826N/A {
5826N/A CopyOnWriteArrayList<PasswordStorageScheme> schemeList =
5826N/A defaultPolicy.getDefaultStorageSchemes();
5826N/A defaultAuthSchemes =
5826N/A new PasswordStorageScheme[schemeList.size()];
5826N/A schemeList.toArray(defaultAuthSchemes);
5826N/A }
5826N/A else
5826N/A {
5826N/A defaultAuthSchemes = new PasswordStorageScheme[1];
5826N/A defaultAuthSchemes[0] =
5826N/A DirectoryServer.getAuthPasswordStorageScheme(
5826N/A AUTH_PASSWORD_SCHEME_NAME_SALTED_SHA_1);
5826N/A if (defaultAuthSchemes[0] == null)
5826N/A {
5826N/A resultCode = DirectoryServer.getServerErrorResultCode();
5826N/A
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_NO_DEFAULT_AUTH_SCHEMES;
5826N/A messages.add(getMessage(msgID,
5826N/A AUTH_PASSWORD_SCHEME_NAME_SALTED_SHA_1));
5826N/A }
5826N/A }
5826N/A }
5826N/A else
5826N/A {
5826N/A defaultAuthSchemes = new PasswordStorageScheme[authSchemesSet.size()];
5826N/A int i=0;
5826N/A for (String schemeName : authSchemesSet)
5826N/A {
5826N/A defaultAuthSchemes[i] =
5826N/A DirectoryServer.getAuthPasswordStorageScheme(schemeName);
5826N/A if (defaultAuthSchemes[i] == null)
5826N/A {
5826N/A resultCode = DirectoryServer.getServerErrorResultCode();
5826N/A
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_INVALID_DEFAULT_AUTH_SCHEME;
5826N/A messages.add(getMessage(msgID, schemeName));
5826N/A }
5826N/A i++;
5826N/A }
5826N/A }
5826N/A
5826N/A
5826N/A // Get the set of default password storage schemes for user password
5826N/A // attributes.
5826N/A PasswordStorageScheme[] defaultUserSchemes;
5826N/A Set<String> userSchemeSet =
5826N/A configuration.getDefaultUserPasswordStorageScheme();
5826N/A if ((userSchemeSet == null) || userSchemeSet.isEmpty())
5826N/A {
5826N/A if (! defaultPolicy.usesAuthPasswordSyntax())
5826N/A {
5826N/A CopyOnWriteArrayList<PasswordStorageScheme> schemeList =
5826N/A defaultPolicy.getDefaultStorageSchemes();
5826N/A defaultUserSchemes =
5826N/A new PasswordStorageScheme[schemeList.size()];
5826N/A schemeList.toArray(defaultUserSchemes);
5826N/A }
5826N/A else
5826N/A {
5826N/A defaultUserSchemes = new PasswordStorageScheme[1];
5826N/A defaultUserSchemes[0] = DirectoryServer.getPasswordStorageScheme(
5826N/A toLowerCase(STORAGE_SCHEME_NAME_SALTED_SHA_1));
5826N/A if (defaultUserSchemes[0] == null)
5826N/A {
5826N/A resultCode = DirectoryServer.getServerErrorResultCode();
5826N/A
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_NO_DEFAULT_USER_SCHEMES;
5826N/A messages.add(getMessage(msgID, STORAGE_SCHEME_NAME_SALTED_SHA_1));
5826N/A }
5826N/A }
5826N/A }
5826N/A else
5826N/A {
5826N/A defaultUserSchemes = new PasswordStorageScheme[userSchemeSet.size()];
5826N/A int i=0;
5826N/A for (String schemeName : userSchemeSet)
5826N/A {
5826N/A defaultUserSchemes[i] =
5826N/A DirectoryServer.getPasswordStorageScheme(toLowerCase(schemeName));
5826N/A if (defaultUserSchemes[i] == null)
5826N/A {
5826N/A resultCode = DirectoryServer.getServerErrorResultCode();
5826N/A
5826N/A int msgID = MSGID_PLUGIN_PWIMPORT_INVALID_DEFAULT_USER_SCHEME;
5826N/A messages.add(getMessage(msgID, schemeName));
5826N/A }
5826N/A i++;
5826N/A }
5826N/A }
5826N/A
5826N/A return new ConfigChangeResult(resultCode, adminActionRequired, messages);
5826N/A }
5826N/A}
5826N/A
5826N/A