LDAPPasswordModify.java revision 29fa222166e7cbd6b5823421555aa647108eb00f
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * CDDL HEADER START
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * The contents of this file are subject to the terms of the
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * Common Development and Distribution License, Version 1.0 only
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * (the "License"). You may not use this file except in compliance
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * with the License.
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * You can obtain a copy of the license at
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * trunk/opends/resource/legal-notices/OpenDS.LICENSE
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * See the License for the specific language governing permissions
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob Halley * and limitations under the License.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * When distributing Covered Code, include this CDDL HEADER in each
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington * file and include the License file at
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley * add the following below this CDDL HEADER, with the fields enclosed
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * by brackets "[]" replaced with your own identifying * information:
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * Portions Copyright [yyyy] [name of copyright owner]
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * CDDL HEADER END
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff * Portions Copyright 2006 Sun Microsystems, Inc.
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graffimport java.util.concurrent.atomic.AtomicInteger;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.asn1.ASN1Element;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.asn1.ASN1OctetString;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.asn1.ASN1Reader;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.asn1.ASN1Sequence;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.asn1.ASN1Writer;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.ldap.LDAPMessage;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.ldap.LDAPResultCode;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.protocols.ldap.UnbindRequestProtocolOp;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.types.NullOutputStream;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.util.args.ArgumentException;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.util.args.ArgumentParser;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.util.args.BooleanArgument;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.util.args.FileBasedArgument;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.util.args.IntegerArgument;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport org.opends.server.util.args.StringArgument;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport static org.opends.server.extensions.ExtensionsConstants.*;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport static org.opends.server.messages.MessageHandler.*;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport static org.opends.server.messages.ToolMessages.*;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport static org.opends.server.util.ServerConstants.*;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graffimport static org.opends.server.util.StaticUtils.*;
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * This program provides a utility that uses the LDAP password modify extended
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * operation to change the password for a user. It exposes the three primary
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * options available for this operation, which are:
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * <LI>The user identity whose password should be changed.</LI>
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * <LI>The current password for the user.</LI>
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * <LI>The new password for the user.
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * All of these are optional components that may be included or omitted from the
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * The fully-qualified name of this class for debugging purposes.
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson "org.opends.server.tools.LDAPPasswordModify";
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * Parses the command-line arguments, establishes a connection to the
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * Directory Server, sends the password modify request, and reads the
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * @param args The command-line arguments provided to this program.
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson int returnCode = mainPasswordModify(args, true, System.out, System.err);
2c7e99b941c3f1ffa29f9034c710f358c09f13c9Michael Graff * Parses the command-line arguments, establishes a connection to the
2c7e99b941c3f1ffa29f9034c710f358c09f13c9Michael Graff * Directory Server, sends the password modify request, and reads the
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * @param args The command-line arguments provided to this program.
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * @return An integer value of zero if everything completed successfully, or
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * a nonzero value if an error occurred.
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson public static int mainPasswordModify(String[] args)
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson return mainPasswordModify(args, true, System.out, System.err);
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson * Parses the command-line arguments, establishes a connection to the
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * Directory Server, sends the password modify request, and reads the
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * @param args The command-line arguments provided to this
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * @param initializeServer Indicates whether to initialize the server.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * @param outStream The output stream to use for standard output.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * @param errStream The output stream to use for standard error.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * @return An integer value of zero if everything completed successfully, or
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * a nonzero value if an error occurred.
a2171e092382f8f8a72b1f73436ddf93918c7719Bob Halley public static int mainPasswordModify(String[] args, boolean initializeServer,
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley // Create the arguments that will be used by this program.
facb97777a972f6c8035ca3e762a6a9248c12897Bob Halley // Initialize the argument parser.
491b48ec3f3ef014312688776ddbd4eab8a2c10cMichael Graff String toolDescription = getMessage(MSGID_LDAPPWMOD_TOOL_DESCRIPTION);
13494a4d4bead37f22eb6c4779c73310109f7e4aJames Brister ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
ffea097efa5b9d6a0d5e8ed43d98c29de3fa5b8dMichael Graff ldapHost = new StringArgument("ldaphost", 'h', "ldapHost", false, false,
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff ldapPort = new IntegerArgument("ldapport", 'p', "ldapPort", false, false,
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff useSSL = new BooleanArgument("usessl", 'Z', "useSSL",
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley useStartTLS = new BooleanArgument("usestarttls", 'q', "useStartTLS",
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley bindDN = new StringArgument("binddn", 'D', "bindDN", false, false, true,
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley bindPW = new StringArgument("bindpw", 'w', "bindPassword", false, false,
491b48ec3f3ef014312688776ddbd4eab8a2c10cMichael Graff new FileBasedArgument("bindpwfile", 'j', "bindPasswordFile", false,
820ad97db480f58e1e4d0d3eeae73b2fb27b4f91Andreas Gustafsson authzID = new StringArgument("authzid", 'a', "authzID", false, false,
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson new BooleanArgument("providednforauthzid", 'A',"provideDNForAuthzID",
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley MSGID_LDAPPWMOD_DESCRIPTION_PROVIDE_DN_FOR_AUTHZID);
ea31416b4fcdf23732355a8002f93f29e3b3d2dbAndreas Gustafsson argParser.addArgument(provideDNForAuthzID);
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley newPW = new StringArgument("newpw", 'n', "newPassword", false, false,
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley newPWFile = new FileBasedArgument("newpwfile", 'N', "newPasswordFile",
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley new StringArgument("currentpw", 'c', "currentPassword", false, false,
9cda9dc86efa0dde8f906759c4e3279da028b5f4Bob Halley new FileBasedArgument("currentpwfile", 'C', "currentPasswordFile",
70eb7879553eaa57c391f07e439911bfdaff7124Bob Halley new BooleanArgument("blindtrust", 'X', "trustAllCertificates",
1922518d7f7b5e3e77b8e1c92569c98268b9c192Andreas Gustafsson MSGID_LDAPPWMOD_DESCRIPTION_BLIND_TRUST);
868f13e9490474f8f9f3ceb5494e704f5719dce1Bob Halley new StringArgument("sslkeystore", 'k', "sslKeyStore", false, false,
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley new FileBasedArgument("sslkeystorepin", 'K', "sslKeyStorePINFile",
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley new StringArgument("ssltruststore", 't', "sslTrustStore", false,
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley "sslTrustStorePINFile", false, false, "{file}", null, null,
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley showUsage = new BooleanArgument("help", 'H', "help",
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley int msgID = MSGID_LDAPPWMOD_CANNOT_INITIALIZE_ARGS;
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley String message = getMessage(msgID, ae.getMessage());
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley // Parse the command-line arguments provided to this program.
6d5dcd0dc9bdbd679282b1ffc47987d24c3a1346Bob Halley String message = getMessage(msgID, ae.getMessage());
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley // If the usage argument was provided, then we don't need to do anything
9fbc1afb8b08432e3a1adda1f41d5575620e9785Bob Halley // Make sure that the user didn't specify any conflicting arguments.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley if (bindPW.isPresent() && bindPWFile.isPresent())
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley String message = getMessage(msgID, bindPW.getLongIdentifier(),
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley String message = getMessage(msgID, newPW.getLongIdentifier(),
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington if (currentPW.isPresent() && currentPWFile.isPresent())
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington int msgID = MSGID_LDAPPWMOD_CONFLICTING_ARGS;
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington String message = getMessage(msgID, currentPW.getLongIdentifier(),
690a68b8112039e633e26f9216c0d463751e011aMichael Graff if (useSSL.isPresent() && useStartTLS.isPresent())
44aae046c38e796e581110b7ecdf4478167d684dBob Halley String message = getMessage(msgID, useSSL.getLongIdentifier(),
65c4736d9c0ebc6d9b1d991593b55566909da9cdBrian Wellington err.println(wrapText(message, MAX_LINE_WIDTH));
int port;
catch (Exception e)
if (initializeServer)
catch (Exception e)
pw));
catch (Exception e)
new UnbindRequestProtocolOp());
catch (Exception e)
new UnbindRequestProtocolOp());
new UnbindRequestProtocolOp());
catch (Exception e) {}
} catch (Exception e) {}
return resultCode;
catch (Exception e)
new UnbindRequestProtocolOp());
new UnbindRequestProtocolOp());
catch (Exception e) {}
} catch (Exception e) {}