| | |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.admin.server.ConfigurationChangeListener; |
| | | import org.opends.server.admin.std.meta.PluginCfgDefn; |
| | | import org.opends.server.admin.std.server.PasswordPolicyImportPluginCfg; |
| | |
| | | import org.opends.server.core.SubentryPasswordPolicy; |
| | | import org.opends.server.schema.AuthPasswordSyntax; |
| | | import org.opends.server.schema.UserPasswordSyntax; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.LDIFImportConfig; |
| | | import org.opends.server.types.SubEntry; |
| | | |
| | | /** |
| | | * This class implements a Directory Server plugin that performs various |
| | |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | |
| | | |
| | | /** The attribute type used to specify the password policy for an entry. */ |
| | | private AttributeType customPolicyAttribute; |
| | | |
| | | /** |
| | | * The set of attribute types defined in the schema with the auth password |
| | | * syntax. |
| | | */ |
| | | /** The set of attribute types defined in the schema with the auth password syntax. */ |
| | | private AttributeType[] authPasswordTypes; |
| | | |
| | | /** |
| | | * The set of attribute types defined in the schema with the user password |
| | | * syntax. |
| | | */ |
| | | /** The set of attribute types defined in the schema with the user password syntax. */ |
| | | private AttributeType[] userPasswordTypes; |
| | | |
| | | /** |
| | | * The set of password storage schemes to use for the various password |
| | | * policies defined in the server. |
| | | */ |
| | | private HashMap<DN,PasswordStorageScheme<?>[]> schemesByPolicy; |
| | | |
| | | private Map<DN, PasswordStorageScheme<?>[]> schemesByPolicy; |
| | | /** The default password storage schemes for auth password attributes. */ |
| | | private PasswordStorageScheme<?>[] defaultAuthPasswordSchemes; |
| | | |
| | | /** The default password storage schemes for user password attributes. */ |
| | | private PasswordStorageScheme<?>[] defaultUserPasswordSchemes; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new instance of this Directory Server plugin. Every plugin must |
| | | * implement a default constructor (it is the only one that will be used to |
| | |
| | | |
| | | customPolicyAttribute = DirectoryServer.getAttributeType(OP_ATTR_PWPOLICY_POLICY_DN); |
| | | |
| | | |
| | | // Make sure that the plugin has been enabled for the appropriate types. |
| | | for (PluginType t : pluginTypes) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Get the set of default password storage schemes for auth password |
| | | // attributes. |
| | | PasswordPolicy defaultPolicy = DirectoryServer.getDefaultPasswordPolicy(); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Get the set of default password storage schemes for user password |
| | | // attributes. |
| | | Set<DN> userSchemeDNs = |
| | |
| | | HashSet<AttributeType> userPWTypes = new HashSet<>(); |
| | | for (AttributeType t : DirectoryServer.getAttributeTypes()) |
| | | { |
| | | if (t.getSyntax().getOID().equals(SYNTAX_AUTH_PASSWORD_OID)) |
| | | if (SYNTAX_AUTH_PASSWORD_OID.equals(t.getSyntax().getOID())) |
| | | { |
| | | authPWTypes.add(t); |
| | | } |
| | | else if (t.getSyntax().getOID().equals(SYNTAX_USER_PASSWORD_OID)) |
| | | else if (SYNTAX_USER_PASSWORD_OID.equals(t.getSyntax().getOID())) |
| | | { |
| | | userPWTypes.add(t); |
| | | } |
| | | } |
| | | |
| | | |
| | | // Get the set of password policies defined in the server and get the |
| | | // attribute types associated with them. |
| | | HashMap<DN,PasswordStorageScheme<?>[]> schemeMap = new HashMap<>(); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | AttributeType[] authTypesArray = new AttributeType[authPWTypes.size()]; |
| | | AttributeType[] userTypesArray = new AttributeType[userPWTypes.size()]; |
| | | authPWTypes.toArray(authTypesArray); |
| | |
| | | builder.add(value); |
| | | } |
| | | } |
| | | else if (!UserPasswordSyntax.isEncoded(value)) |
| | | { |
| | | try |
| | | { |
| | | for (PasswordStorageScheme<?> s : schemes) |
| | | { |
| | | builder.add(s.encodePasswordWithScheme(value)); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.traceException(e); |
| | | |
| | | logger.error(ERR_PLUGIN_PWPIMPORT_ERROR_ENCODING_PASSWORD, policy.getPasswordAttribute() |
| | | .getNameOrOID(), entry.getName(), stackTraceToSingleLineString(e)); |
| | | gotError = true; |
| | | break; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (!UserPasswordSyntax.isEncoded(value)) |
| | | { |
| | | try |
| | | { |
| | | for (PasswordStorageScheme<?> s : schemes) |
| | | { |
| | | builder.add(s.encodePasswordWithScheme(value)); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.traceException(e); |
| | | |
| | | logger.error(ERR_PLUGIN_PWPIMPORT_ERROR_ENCODING_PASSWORD, |
| | | policy.getPasswordAttribute().getNameOrOID(), entry.getName(), |
| | | stackTraceToSingleLineString(e)); |
| | | gotError = true; |
| | | break; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | builder.add(value); |
| | | } |
| | | builder.add(value); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Iterate through the list of auth password attributes. If any of them |
| | | // are present and their values are not encoded, then encode them with all |
| | | // appropriate schemes. |
| | | for (AttributeType t : authPasswordTypes) |
| | | { |
| | | attrList = entry.getAttribute(t); |
| | | if (attrList.isEmpty()) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | for (Attribute a : attrList) |
| | | for (Attribute a : entry.getAttribute(t)) |
| | | { |
| | | AttributeBuilder builder = new AttributeBuilder(a, true); |
| | | boolean gotError = false; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Iterate through the list of user password attributes. If any of them |
| | | // are present and their values are not encoded, then encode them with all |
| | | // appropriate schemes. |
| | | for (AttributeType t : userPasswordTypes) |
| | | { |
| | | attrList = entry.getAttribute(t); |
| | | if (attrList.isEmpty()) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | for (Attribute a : attrList) |
| | | for (Attribute a : entry.getAttribute(t)) |
| | | { |
| | | AttributeBuilder builder = new AttributeBuilder(a, true); |
| | | boolean gotError = false; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | return PluginResult.ImportLDIF.continueEntryProcessing(); |
| | | } |
| | | |
| | |
| | | // This is the only acceptable type. |
| | | break; |
| | | |
| | | |
| | | default: |
| | | unacceptableReasons.add(ERR_PLUGIN_PWPIMPORT_INVALID_PLUGIN_TYPE.get(pluginType)); |
| | | configAcceptable = false; |
| | | } |
| | | } |
| | | |
| | | |
| | | // Get the set of default password storage schemes for auth password |
| | | // attributes. |
| | | Set<DN> authSchemeDNs = |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Get the set of default password storage schemes for user password |
| | | // attributes. |
| | | Set<DN> userSchemeDNs = |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | return configAcceptable; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Get the set of default password storage schemes for user password |
| | | // attributes. |
| | | PasswordStorageScheme<?>[] defaultUserSchemes; |