001/* 002 * Copyright 2010-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2010-2020 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2010-2020 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.util; 037 038 039 040import java.io.OutputStream; 041import java.io.PrintStream; 042 043import com.unboundid.ldap.listener.InMemoryDirectoryServerTool; 044import com.unboundid.ldap.sdk.ResultCode; 045import com.unboundid.ldap.sdk.Version; 046import com.unboundid.ldap.sdk.examples.AuthRate; 047import com.unboundid.ldap.sdk.examples.Base64Tool; 048import com.unboundid.ldap.sdk.examples.IdentifyReferencesToMissingEntries; 049import com.unboundid.ldap.sdk.examples.IdentifyUniqueAttributeConflicts; 050import com.unboundid.ldap.sdk.examples.IndentLDAPFilter; 051import com.unboundid.ldap.sdk.examples.LDAPCompare; 052import com.unboundid.ldap.sdk.examples.LDAPDebugger; 053import com.unboundid.ldap.sdk.examples.LDAPModify; 054import com.unboundid.ldap.sdk.examples.LDAPSearch; 055import com.unboundid.ldap.sdk.examples.ModRate; 056import com.unboundid.ldap.sdk.examples.SearchRate; 057import com.unboundid.ldap.sdk.examples.SearchAndModRate; 058import com.unboundid.ldap.sdk.examples.ValidateLDIF; 059import com.unboundid.ldap.sdk.persist.GenerateSchemaFromSource; 060import com.unboundid.ldap.sdk.persist.GenerateSourceFromSchema; 061import com.unboundid.ldap.sdk.transformations.TransformLDIF; 062import com.unboundid.util.ssl.TLSCipherSuiteSelector; 063import com.unboundid.util.ssl.cert.ManageCertificates; 064 065 066 067/** 068 * This class provides an entry point that may be used to launch other tools 069 * provided as part of the LDAP SDK. This is primarily a convenience for 070 * someone who just has the jar file and none of the scripts, since you can run 071 * "<CODE>java -jar unboundid-ldapsdk.jar {tool-name} {tool-args}</CODE>" 072 * in order to invoke any of the example tools. Running just 073 * "<CODE>java -jar unboundid-ldapsdk.jar</CODE>" will display version 074 * information about the LDAP SDK. 075 * <BR><BR> 076 * The tool names are case-insensitive. Supported tool names include: 077 * <UL> 078 * <LI>authrate -- Launch the {@link AuthRate} tool.</LI> 079 * <LI>base64 -- Launch the {@link Base64Tool} tool.</LI> 080 * <LI>generate-schema-from-source -- Launch the 081 * {@link GenerateSchemaFromSource} tool.</LI> 082 * <LI>generate-source-from-schema -- Launch the 083 * {@link GenerateSourceFromSchema} tool.</LI> 084 * <LI>identify-references-to-missing-entries -- Launch the 085 * {@link IdentifyReferencesToMissingEntries} tool.</LI> 086 * <LI>identify-unique-attribute-conflicts -- Launch the 087 * {@link IdentifyUniqueAttributeConflicts} tool.</LI> 088 * <LI>indent-ldap-filter -- Launch the {@link IndentLDAPFilter} tool.</LI> 089 * <LI>in-memory-directory-server -- Launch the 090 * {@link InMemoryDirectoryServerTool} tool.</LI> 091 * <LI>ldapcompare -- Launch the {@link LDAPCompare} tool.</LI> 092 * <LI>ldapmodify -- Launch the {@link LDAPModify} tool.</LI> 093 * <LI>ldapsearch -- Launch the {@link LDAPSearch} tool.</LI> 094 * <LI>ldap-debugger -- Launch the {@link LDAPDebugger} tool.</LI> 095 * <LI>manage-certificates -- Launch the {@link ManageCertificates} tool.</LI> 096 * <LI>modrate -- Launch the {@link ModRate} tool.</LI> 097 * <LI>searchrate -- Launch the {@link SearchRate} tool.</LI> 098 * <LI>search-and-mod-rate -- Launch the {@link SearchAndModRate} tool.</LI> 099 * <LI>tls-cipher-suite-selector -- Launch the {@link TLSCipherSuiteSelector} 100 * tool.</LI> 101 * <LI>transform-ldif -- Launch the {@link TransformLDIF} tool.</LI> 102 * <LI>validate-ldif -- Launch the {@link ValidateLDIF} tool.</LI> 103 * <LI>version -- Display version information for the LDAP SDK.</LI> 104 * </UL> 105 */ 106@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 107public final class Launcher 108{ 109 /** 110 * Prevent this utility class from being externally instantiated. 111 */ 112 private Launcher() 113 { 114 // No implementation required. 115 } 116 117 118 119 /** 120 * Parses the command-line arguments and performs any appropriate processing 121 * for this program. 122 * 123 * @param args The command-line arguments provided to this program. 124 */ 125 public static void main(final String... args) 126 { 127 main(System.out, System.err, args); 128 } 129 130 131 132 /** 133 * Parses the command-line arguments and performs any appropriate processing 134 * for this program. 135 * 136 * @param outStream The output stream to which standard out should be 137 * written. It may be {@code null} if output should be 138 * suppressed. 139 * @param errStream The output stream to which standard error should be 140 * written. It may be {@code null} if error messages 141 * should be suppressed. 142 * @param args The command-line arguments provided to this program. 143 * 144 * @return A result code with information about the status of processing. 145 */ 146 public static ResultCode main(final OutputStream outStream, 147 final OutputStream errStream, 148 final String... args) 149 { 150 151 152 if ((args == null) || (args.length == 0) || 153 args[0].equalsIgnoreCase("version")) 154 { 155 if (outStream != null) 156 { 157 final PrintStream out = new PrintStream(outStream); 158 for (final String line : Version.getVersionLines()) 159 { 160 out.println(line); 161 } 162 } 163 164 return ResultCode.SUCCESS; 165 } 166 167 final String firstArg = StaticUtils.toLowerCase(args[0]); 168 final String[] remainingArgs = new String[args.length - 1]; 169 System.arraycopy(args, 1, remainingArgs, 0, remainingArgs.length); 170 171 if (firstArg.equals("authrate")) 172 { 173 return AuthRate.main(remainingArgs, outStream, errStream); 174 } 175 else if (firstArg.equals("base64")) 176 { 177 return Base64Tool.main(System.in, outStream, errStream, remainingArgs); 178 } 179 else if (firstArg.equals("identify-references-to-missing-entries")) 180 { 181 return IdentifyReferencesToMissingEntries.main(remainingArgs, outStream, 182 errStream); 183 } 184 else if (firstArg.equals("identify-unique-attribute-conflicts")) 185 { 186 return IdentifyUniqueAttributeConflicts.main(remainingArgs, outStream, 187 errStream); 188 } 189 else if (firstArg.equals("indent-ldap-filter")) 190 { 191 return IndentLDAPFilter.main(outStream, errStream, remainingArgs); 192 } 193 else if (firstArg.equals("in-memory-directory-server")) 194 { 195 return InMemoryDirectoryServerTool.main(remainingArgs, outStream, 196 errStream); 197 } 198 else if (firstArg.equals("generate-schema-from-source")) 199 { 200 return GenerateSchemaFromSource.main(remainingArgs, outStream, errStream); 201 } 202 else if (firstArg.equals("generate-source-from-schema")) 203 { 204 return GenerateSourceFromSchema.main(remainingArgs, outStream, errStream); 205 } 206 else if (firstArg.equals("ldapcompare")) 207 { 208 return LDAPCompare.main(remainingArgs, outStream, errStream); 209 } 210 else if (firstArg.equals("ldapmodify")) 211 { 212 return LDAPModify.main(remainingArgs, outStream, errStream); 213 } 214 else if (firstArg.equals("ldapsearch")) 215 { 216 return LDAPSearch.main(remainingArgs, outStream, errStream); 217 } 218 else if (firstArg.equals("ldap-debugger")) 219 { 220 return LDAPDebugger.main(remainingArgs, outStream, errStream); 221 } 222 else if (firstArg.equals("manage-certificates")) 223 { 224 return ManageCertificates.main(System.in, outStream, errStream, 225 remainingArgs); 226 } 227 else if (firstArg.equals("modrate")) 228 { 229 return ModRate.main(remainingArgs, outStream, errStream); 230 } 231 else if (firstArg.equals("searchrate")) 232 { 233 return SearchRate.main(remainingArgs, outStream, errStream); 234 } 235 else if (firstArg.equals("search-and-mod-rate")) 236 { 237 return SearchAndModRate.main(remainingArgs, outStream, errStream); 238 } 239 else if (firstArg.equals("tls-cipher-suite-selector")) 240 { 241 return TLSCipherSuiteSelector.main(outStream, errStream, remainingArgs); 242 } 243 else if (firstArg.equals("transform-ldif")) 244 { 245 return TransformLDIF.main(outStream, errStream, remainingArgs); 246 } 247 else if (firstArg.equals("validate-ldif")) 248 { 249 return ValidateLDIF.main(remainingArgs, outStream, errStream); 250 } 251 else 252 { 253 if (errStream != null) 254 { 255 final PrintStream err = new PrintStream(errStream); 256 err.println("Unrecognized tool name '" + args[0] + '\''); 257 err.println("Supported tool names include:"); 258 err.println(" authrate"); 259 err.println(" base64"); 260 err.println(" generate-schema-from-source"); 261 err.println(" generate-source-from-schema"); 262 err.println(" identify-references-to-missing-entries"); 263 err.println(" identify-unique-attribute-conflicts"); 264 err.println(" indent-ldap-filter"); 265 err.println(" in-memory-directory-server"); 266 err.println(" ldapcompare"); 267 err.println(" ldapmodify"); 268 err.println(" ldapsearch"); 269 err.println(" ldap-debugger"); 270 err.println(" manage-certificates"); 271 err.println(" modrate"); 272 err.println(" searchrate"); 273 err.println(" search-and-mod-rate"); 274 err.println(" tls-cipher-suite-selector"); 275 err.println(" transform-ldif"); 276 err.println(" validate-ldif"); 277 err.println(" version"); 278 } 279 280 return ResultCode.PARAM_ERROR; 281 } 282 } 283}