001/*
002 * Copyright 2008-2022 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-2022 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) 2008-2022 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.ldap.sdk.examples;
037
038
039
040import java.io.OutputStream;
041import java.text.SimpleDateFormat;
042import java.util.Date;
043import java.util.LinkedHashMap;
044import java.util.List;
045
046import com.unboundid.ldap.sdk.Control;
047import com.unboundid.ldap.sdk.DereferencePolicy;
048import com.unboundid.ldap.sdk.Filter;
049import com.unboundid.ldap.sdk.LDAPConnection;
050import com.unboundid.ldap.sdk.LDAPException;
051import com.unboundid.ldap.sdk.ResultCode;
052import com.unboundid.ldap.sdk.SearchRequest;
053import com.unboundid.ldap.sdk.SearchResult;
054import com.unboundid.ldap.sdk.SearchResultEntry;
055import com.unboundid.ldap.sdk.SearchResultListener;
056import com.unboundid.ldap.sdk.SearchResultReference;
057import com.unboundid.ldap.sdk.SearchScope;
058import com.unboundid.ldap.sdk.Version;
059import com.unboundid.util.Debug;
060import com.unboundid.util.LDAPCommandLineTool;
061import com.unboundid.util.NotNull;
062import com.unboundid.util.Nullable;
063import com.unboundid.util.StaticUtils;
064import com.unboundid.util.ThreadSafety;
065import com.unboundid.util.ThreadSafetyLevel;
066import com.unboundid.util.WakeableSleeper;
067import com.unboundid.util.args.ArgumentException;
068import com.unboundid.util.args.ArgumentParser;
069import com.unboundid.util.args.BooleanArgument;
070import com.unboundid.util.args.ControlArgument;
071import com.unboundid.util.args.DNArgument;
072import com.unboundid.util.args.IntegerArgument;
073import com.unboundid.util.args.ScopeArgument;
074
075
076
077/**
078 * This class provides a simple tool that can be used to search an LDAP
079 * directory server.  Some of the APIs demonstrated by this example include:
080 * <UL>
081 *   <LI>Argument Parsing (from the {@code com.unboundid.util.args}
082 *       package)</LI>
083 *   <LI>LDAP Command-Line Tool (from the {@code com.unboundid.util}
084 *       package)</LI>
085 *   <LI>LDAP Communication (from the {@code com.unboundid.ldap.sdk}
086 *       package)</LI>
087 * </UL>
088 * <BR><BR>
089 * All of the necessary information is provided using
090 * command line arguments.  Supported arguments include those allowed by the
091 * {@link LDAPCommandLineTool} class, as well as the following additional
092 * arguments:
093 * <UL>
094 *   <LI>"-b {baseDN}" or "--baseDN {baseDN}" -- specifies the base DN to use
095 *       for the search.  This must be provided.</LI>
096 *   <LI>"-s {scope}" or "--scope {scope}" -- specifies the scope to use for the
097 *       search.  The scope value should be one of "base", "one", "sub", or
098 *       "subord".  If this isn't specified, then a scope of "sub" will be
099 *       used.</LI>
100 *   <LI>"-R" or "--followReferrals" -- indicates that the tool should follow
101 *       any referrals encountered while searching.</LI>
102 *   <LI>"-t" or "--terse" -- indicates that the tool should generate minimal
103 *       output beyond the search results.</LI>
104 *   <LI>"-i {millis}" or "--repeatIntervalMillis {millis}" -- indicates that
105 *       the search should be periodically repeated with the specified delay
106 *       (in milliseconds) between requests.</LI>
107 *   <LI>"-n {count}" or "--numSearches {count}" -- specifies the total number
108 *       of times that the search should be performed.  This may only be used in
109 *       conjunction with the "--repeatIntervalMillis" argument.  If
110 *       "--repeatIntervalMillis" is used without "--numSearches", then the
111 *       searches will continue to be repeated until the tool is
112 *       interrupted.</LI>
113 *   <LI>"--bindControl {control}" -- specifies a control that should be
114 *       included in the bind request sent by this tool before performing any
115 *       search operations.</LI>
116 *   <LI>"-J {control}" or "--control {control}" -- specifies a control that
117 *       should be included in the search request(s) sent by this tool.</LI>
118 * </UL>
119 * In addition, after the above named arguments are provided, a set of one or
120 * more unnamed trailing arguments must be given.  The first argument should be
121 * the string representation of the filter to use for the search.  If there are
122 * any additional trailing arguments, then they will be interpreted as the
123 * attributes to return in matching entries.  If no attribute names are given,
124 * then the server should return all user attributes in matching entries.
125 * <BR><BR>
126 * Note that this class implements the SearchResultListener interface, which
127 * will be notified whenever a search result entry or reference is returned from
128 * the server.  Whenever an entry is received, it will simply be printed
129 * displayed in LDIF.
130 *
131 * @see  com.unboundid.ldap.sdk.unboundidds.tools.LDAPSearch
132 */
133@ThreadSafety(level=ThreadSafetyLevel.NOT_THREADSAFE)
134public final class LDAPSearch
135       extends LDAPCommandLineTool
136       implements SearchResultListener
137{
138  /**
139   * The date formatter that should be used when writing timestamps.
140   */
141  @NotNull private static final SimpleDateFormat DATE_FORMAT =
142       new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss.SSS");
143
144
145
146  /**
147   * The serial version UID for this serializable class.
148   */
149  private static final long serialVersionUID = 7465188734621412477L;
150
151
152
153  // The argument parser used by this program.
154  @Nullable private ArgumentParser parser;
155
156  // Indicates whether the search should be repeated.
157  private boolean repeat;
158
159  // The argument used to indicate whether to follow referrals.
160  @Nullable private BooleanArgument followReferrals;
161
162  // The argument used to indicate whether to use terse mode.
163  @Nullable private BooleanArgument terseMode;
164
165  // The argument used to specify any bind controls that should be used.
166  @Nullable private ControlArgument bindControls;
167
168  // The argument used to specify any search controls that should be used.
169  @Nullable private ControlArgument searchControls;
170
171  // The number of times to perform the search.
172  @Nullable private IntegerArgument numSearches;
173
174  // The interval in milliseconds between repeated searches.
175  @Nullable private IntegerArgument repeatIntervalMillis;
176
177  // The argument used to specify the base DN for the search.
178  @Nullable private DNArgument baseDN;
179
180  // The argument used to specify the scope for the search.
181  @Nullable private ScopeArgument scopeArg;
182
183
184
185  /**
186   * Parse the provided command line arguments and make the appropriate set of
187   * changes.
188   *
189   * @param  args  The command line arguments provided to this program.
190   */
191  public static void main(@NotNull final String[] args)
192  {
193    final ResultCode resultCode = main(args, System.out, System.err);
194    if (resultCode != ResultCode.SUCCESS)
195    {
196      System.exit(resultCode.intValue());
197    }
198  }
199
200
201
202  /**
203   * Parse the provided command line arguments and make the appropriate set of
204   * changes.
205   *
206   * @param  args       The command line arguments provided to this program.
207   * @param  outStream  The output stream to which standard out should be
208   *                    written.  It may be {@code null} if output should be
209   *                    suppressed.
210   * @param  errStream  The output stream to which standard error should be
211   *                    written.  It may be {@code null} if error messages
212   *                    should be suppressed.
213   *
214   * @return  A result code indicating whether the processing was successful.
215   */
216  @NotNull()
217  public static ResultCode main(@NotNull final String[] args,
218                                @Nullable final OutputStream outStream,
219                                @Nullable final OutputStream errStream)
220  {
221    final LDAPSearch ldapSearch = new LDAPSearch(outStream, errStream);
222    return ldapSearch.runTool(args);
223  }
224
225
226
227  /**
228   * Creates a new instance of this tool.
229   *
230   * @param  outStream  The output stream to which standard out should be
231   *                    written.  It may be {@code null} if output should be
232   *                    suppressed.
233   * @param  errStream  The output stream to which standard error should be
234   *                    written.  It may be {@code null} if error messages
235   *                    should be suppressed.
236   */
237  public LDAPSearch(@Nullable final OutputStream outStream,
238                    @Nullable final OutputStream errStream)
239  {
240    super(outStream, errStream);
241  }
242
243
244
245  /**
246   * Retrieves the name for this tool.
247   *
248   * @return  The name for this tool.
249   */
250  @Override()
251  @NotNull()
252  public String getToolName()
253  {
254    return "ldapsearch";
255  }
256
257
258
259  /**
260   * Retrieves the description for this tool.
261   *
262   * @return  The description for this tool.
263   */
264  @Override()
265  @NotNull()
266  public String getToolDescription()
267  {
268    return "Search an LDAP directory server.";
269  }
270
271
272
273  /**
274   * Retrieves the version string for this tool.
275   *
276   * @return  The version string for this tool.
277   */
278  @Override()
279  @NotNull()
280  public String getToolVersion()
281  {
282    return Version.NUMERIC_VERSION_STRING;
283  }
284
285
286
287  /**
288   * Retrieves the minimum number of unnamed trailing arguments that are
289   * required.
290   *
291   * @return  One, to indicate that at least one trailing argument (representing
292   *          the search filter) must be provided.
293   */
294  @Override()
295  public int getMinTrailingArguments()
296  {
297    return 1;
298  }
299
300
301
302  /**
303   * Retrieves the maximum number of unnamed trailing arguments that are
304   * allowed.
305   *
306   * @return  A negative value to indicate that any number of trailing arguments
307   *          may be provided.
308   */
309  @Override()
310  public int getMaxTrailingArguments()
311  {
312    return -1;
313  }
314
315
316
317  /**
318   * Retrieves a placeholder string that may be used to indicate what kinds of
319   * trailing arguments are allowed.
320   *
321   * @return  A placeholder string that may be used to indicate what kinds of
322   *          trailing arguments are allowed.
323   */
324  @Override()
325  @NotNull()
326  public String getTrailingArgumentsPlaceholder()
327  {
328    return "{filter} [attr1 [attr2 [...]]]";
329  }
330
331
332
333  /**
334   * Indicates whether this tool should provide support for an interactive mode,
335   * in which the tool offers a mode in which the arguments can be provided in
336   * a text-driven menu rather than requiring them to be given on the command
337   * line.  If interactive mode is supported, it may be invoked using the
338   * "--interactive" argument.  Alternately, if interactive mode is supported
339   * and {@link #defaultsToInteractiveMode()} returns {@code true}, then
340   * interactive mode may be invoked by simply launching the tool without any
341   * arguments.
342   *
343   * @return  {@code true} if this tool supports interactive mode, or
344   *          {@code false} if not.
345   */
346  @Override()
347  public boolean supportsInteractiveMode()
348  {
349    return true;
350  }
351
352
353
354  /**
355   * Indicates whether this tool defaults to launching in interactive mode if
356   * the tool is invoked without any command-line arguments.  This will only be
357   * used if {@link #supportsInteractiveMode()} returns {@code true}.
358   *
359   * @return  {@code true} if this tool defaults to using interactive mode if
360   *          launched without any command-line arguments, or {@code false} if
361   *          not.
362   */
363  @Override()
364  public boolean defaultsToInteractiveMode()
365  {
366    return true;
367  }
368
369
370
371  /**
372   * Indicates whether this tool should provide arguments for redirecting output
373   * to a file.  If this method returns {@code true}, then the tool will offer
374   * an "--outputFile" argument that will specify the path to a file to which
375   * all standard output and standard error content will be written, and it will
376   * also offer a "--teeToStandardOut" argument that can only be used if the
377   * "--outputFile" argument is present and will cause all output to be written
378   * to both the specified output file and to standard output.
379   *
380   * @return  {@code true} if this tool should provide arguments for redirecting
381   *          output to a file, or {@code false} if not.
382   */
383  @Override()
384  protected boolean supportsOutputFile()
385  {
386    return true;
387  }
388
389
390
391  /**
392   * Indicates whether this tool supports the use of a properties file for
393   * specifying default values for arguments that aren't specified on the
394   * command line.
395   *
396   * @return  {@code true} if this tool supports the use of a properties file
397   *          for specifying default values for arguments that aren't specified
398   *          on the command line, or {@code false} if not.
399   */
400  @Override()
401  public boolean supportsPropertiesFile()
402  {
403    return true;
404  }
405
406
407
408  /**
409   * Indicates whether this tool should default to interactively prompting for
410   * the bind password if a password is required but no argument was provided
411   * to indicate how to get the password.
412   *
413   * @return  {@code true} if this tool should default to interactively
414   *          prompting for the bind password, or {@code false} if not.
415   */
416  @Override()
417  protected boolean defaultToPromptForBindPassword()
418  {
419    return true;
420  }
421
422
423
424  /**
425   * Indicates whether the LDAP-specific arguments should include alternate
426   * versions of all long identifiers that consist of multiple words so that
427   * they are available in both camelCase and dash-separated versions.
428   *
429   * @return  {@code true} if this tool should provide multiple versions of
430   *          long identifiers for LDAP-specific arguments, or {@code false} if
431   *          not.
432   */
433  @Override()
434  protected boolean includeAlternateLongIdentifiers()
435  {
436    return true;
437  }
438
439
440
441  /**
442   * Indicates whether this tool should provide a command-line argument that
443   * allows for low-level SSL debugging.  If this returns {@code true}, then an
444   * "--enableSSLDebugging}" argument will be added that sets the
445   * "javax.net.debug" system property to "all" before attempting any
446   * communication.
447   *
448   * @return  {@code true} if this tool should offer an "--enableSSLDebugging"
449   *          argument, or {@code false} if not.
450   */
451  @Override()
452  protected boolean supportsSSLDebugging()
453  {
454    return true;
455  }
456
457
458
459  /**
460   * Adds the arguments used by this program that aren't already provided by the
461   * generic {@code LDAPCommandLineTool} framework.
462   *
463   * @param  parser  The argument parser to which the arguments should be added.
464   *
465   * @throws  ArgumentException  If a problem occurs while adding the arguments.
466   */
467  @Override()
468  public void addNonLDAPArguments(@NotNull final ArgumentParser parser)
469         throws ArgumentException
470  {
471    this.parser = parser;
472
473    String description = "The base DN to use for the search.  This must be " +
474                         "provided.";
475    baseDN = new DNArgument('b', "baseDN", true, 1, "{dn}", description);
476    baseDN.addLongIdentifier("base-dn", true);
477    parser.addArgument(baseDN);
478
479
480    description = "The scope to use for the search.  It should be 'base', " +
481                  "'one', 'sub', or 'subord'.  If this is not provided, then " +
482                  "a default scope of 'sub' will be used.";
483    scopeArg = new ScopeArgument('s', "scope", false, "{scope}", description,
484                                 SearchScope.SUB);
485    parser.addArgument(scopeArg);
486
487
488    description = "Follow any referrals encountered during processing.";
489    followReferrals = new BooleanArgument('R', "followReferrals", description);
490    followReferrals.addLongIdentifier("follow-referrals", true);
491    parser.addArgument(followReferrals);
492
493
494    description = "Information about a control to include in the bind request.";
495    bindControls = new ControlArgument(null, "bindControl", false, 0, null,
496         description);
497    bindControls.addLongIdentifier("bind-control", true);
498    parser.addArgument(bindControls);
499
500
501    description = "Information about a control to include in search requests.";
502    searchControls = new ControlArgument('J', "control", false, 0, null,
503         description);
504    parser.addArgument(searchControls);
505
506
507    description = "Generate terse output with minimal additional information.";
508    terseMode = new BooleanArgument('t', "terse", description);
509    parser.addArgument(terseMode);
510
511
512    description = "Specifies the length of time in milliseconds to sleep " +
513                  "before repeating the same search.  If this is not " +
514                  "provided, then the search will only be performed once.";
515    repeatIntervalMillis = new IntegerArgument('i', "repeatIntervalMillis",
516                                               false, 1, "{millis}",
517                                               description, 0,
518                                               Integer.MAX_VALUE);
519    repeatIntervalMillis.addLongIdentifier("repeat-interval-millis", true);
520    parser.addArgument(repeatIntervalMillis);
521
522
523    description = "Specifies the number of times that the search should be " +
524                  "performed.  If this argument is present, then the " +
525                  "--repeatIntervalMillis argument must also be provided to " +
526                  "specify the length of time between searches.  If " +
527                  "--repeatIntervalMillis is used without --numSearches, " +
528                  "then the search will be repeated until the tool is " +
529                  "interrupted.";
530    numSearches = new IntegerArgument('n', "numSearches", false, 1, "{count}",
531                                      description, 1, Integer.MAX_VALUE);
532    numSearches.addLongIdentifier("num-searches", true);
533    parser.addArgument(numSearches);
534    parser.addDependentArgumentSet(numSearches, repeatIntervalMillis);
535  }
536
537
538
539  /**
540   * {@inheritDoc}
541   */
542  @Override()
543  public void doExtendedNonLDAPArgumentValidation()
544         throws ArgumentException
545  {
546    // There must have been at least one trailing argument provided, and it must
547    // be parsable as a valid search filter.
548    if (parser.getTrailingArguments().isEmpty())
549    {
550      throw new ArgumentException("At least one trailing argument must be " +
551           "provided to specify the search filter.  Additional trailing " +
552           "arguments are allowed to specify the attributes to return in " +
553           "search result entries.");
554    }
555
556    try
557    {
558      Filter.create(parser.getTrailingArguments().get(0));
559    }
560    catch (final Exception e)
561    {
562      Debug.debugException(e);
563      throw new ArgumentException(
564           "The first trailing argument value could not be parsed as a valid " +
565                "LDAP search filter.",
566           e);
567    }
568  }
569
570
571
572  /**
573   * {@inheritDoc}
574   */
575  @Override()
576  @NotNull()
577  protected List<Control> getBindControls()
578  {
579    return bindControls.getValues();
580  }
581
582
583
584  /**
585   * Performs the actual processing for this tool.  In this case, it gets a
586   * connection to the directory server and uses it to perform the requested
587   * search.
588   *
589   * @return  The result code for the processing that was performed.
590   */
591  @Override()
592  @NotNull()
593  public ResultCode doToolProcessing()
594  {
595    // Make sure that at least one trailing argument was provided, which will be
596    // the filter.  If there were any other arguments, then they will be the
597    // attributes to return.
598    final List<String> trailingArguments = parser.getTrailingArguments();
599    if (trailingArguments.isEmpty())
600    {
601      err("No search filter was provided.");
602      err();
603      err(parser.getUsageString(StaticUtils.TERMINAL_WIDTH_COLUMNS - 1));
604      return ResultCode.PARAM_ERROR;
605    }
606
607    final Filter filter;
608    try
609    {
610      filter = Filter.create(trailingArguments.get(0));
611    }
612    catch (final LDAPException le)
613    {
614      err("Invalid search filter:  ", le.getMessage());
615      return le.getResultCode();
616    }
617
618    final String[] attributesToReturn;
619    if (trailingArguments.size() > 1)
620    {
621      attributesToReturn = new String[trailingArguments.size() - 1];
622      for (int i=1; i < trailingArguments.size(); i++)
623      {
624        attributesToReturn[i-1] = trailingArguments.get(i);
625      }
626    }
627    else
628    {
629      attributesToReturn = StaticUtils.NO_STRINGS;
630    }
631
632
633    // Get the connection to the directory server.
634    final LDAPConnection connection;
635    try
636    {
637      connection = getConnection();
638      if (! terseMode.isPresent())
639      {
640        out("# Connected to ", connection.getConnectedAddress(), ':',
641             connection.getConnectedPort());
642      }
643    }
644    catch (final LDAPException le)
645    {
646      err("Error connecting to the directory server:  ", le.getMessage());
647      return le.getResultCode();
648    }
649
650
651    // Create a search request with the appropriate information and process it
652    // in the server.  Note that in this case, we're creating a search result
653    // listener to handle the results since there could potentially be a lot of
654    // them.
655    final SearchRequest searchRequest =
656         new SearchRequest(this, baseDN.getStringValue(), scopeArg.getValue(),
657                           DereferencePolicy.NEVER, 0, 0, false, filter,
658                           attributesToReturn);
659    searchRequest.setFollowReferrals(followReferrals.isPresent());
660
661    final List<Control> controlList = searchControls.getValues();
662    if (controlList != null)
663    {
664      searchRequest.setControls(controlList);
665    }
666
667
668    final boolean infinite;
669    final int numIterations;
670    if (repeatIntervalMillis.isPresent())
671    {
672      repeat = true;
673
674      if (numSearches.isPresent())
675      {
676        infinite      = false;
677        numIterations = numSearches.getValue();
678      }
679      else
680      {
681        infinite      = true;
682        numIterations = Integer.MAX_VALUE;
683      }
684    }
685    else
686    {
687      infinite      = false;
688      repeat        = false;
689      numIterations = 1;
690    }
691
692    ResultCode resultCode = ResultCode.SUCCESS;
693    long lastSearchTime = System.currentTimeMillis();
694    final WakeableSleeper sleeper = new WakeableSleeper();
695    for (int i=0; (infinite || (i < numIterations)); i++)
696    {
697      if (repeat && (i > 0))
698      {
699        final long sleepTime =
700             (lastSearchTime + repeatIntervalMillis.getValue()) -
701             System.currentTimeMillis();
702        if (sleepTime > 0)
703        {
704          sleeper.sleep(sleepTime);
705        }
706        lastSearchTime = System.currentTimeMillis();
707      }
708
709      try
710      {
711        final SearchResult searchResult = connection.search(searchRequest);
712        if ((! repeat) && (! terseMode.isPresent()))
713        {
714          out("# The search operation was processed successfully.");
715          out("# Entries returned:  ", searchResult.getEntryCount());
716          out("# References returned:  ", searchResult.getReferenceCount());
717        }
718      }
719      catch (final LDAPException le)
720      {
721        err("An error occurred while processing the search:  ",
722             le.getMessage());
723        err("Result Code:  ", le.getResultCode().intValue(), " (",
724             le.getResultCode().getName(), ')');
725        if (le.getMatchedDN() != null)
726        {
727          err("Matched DN:  ", le.getMatchedDN());
728        }
729
730        if (le.getReferralURLs() != null)
731        {
732          for (final String url : le.getReferralURLs())
733          {
734            err("Referral URL:  ", url);
735          }
736        }
737
738        if (resultCode == ResultCode.SUCCESS)
739        {
740          resultCode = le.getResultCode();
741        }
742
743        if (! le.getResultCode().isConnectionUsable())
744        {
745          break;
746        }
747      }
748    }
749
750
751    // Close the connection to the directory server and exit.
752    connection.close();
753    if (! terseMode.isPresent())
754    {
755      out();
756      out("# Disconnected from the server");
757    }
758    return resultCode;
759  }
760
761
762
763  /**
764   * Indicates that the provided search result entry was returned from the
765   * associated search operation.
766   *
767   * @param  entry  The entry that was returned from the search.
768   */
769  @Override()
770  public void searchEntryReturned(@NotNull final SearchResultEntry entry)
771  {
772    if (repeat)
773    {
774      out("# ", DATE_FORMAT.format(new Date()));
775    }
776
777    out(entry.toLDIFString());
778  }
779
780
781
782  /**
783   * Indicates that the provided search result reference was returned from the
784   * associated search operation.
785   *
786   * @param  reference  The reference that was returned from the search.
787   */
788  @Override()
789  public void searchReferenceReturned(
790                   @NotNull final SearchResultReference reference)
791  {
792    if (repeat)
793    {
794      out("# ", DATE_FORMAT.format(new Date()));
795    }
796
797    out(reference.toString());
798  }
799
800
801
802  /**
803   * {@inheritDoc}
804   */
805  @Override()
806  @NotNull()
807  public LinkedHashMap<String[],String> getExampleUsages()
808  {
809    final LinkedHashMap<String[],String> examples =
810         new LinkedHashMap<>(StaticUtils.computeMapCapacity(1));
811
812    final String[] args =
813    {
814      "--hostname", "server.example.com",
815      "--port", "389",
816      "--bindDN", "uid=admin,dc=example,dc=com",
817      "--bindPassword", "password",
818      "--baseDN", "dc=example,dc=com",
819      "--scope", "sub",
820      "(uid=jdoe)",
821      "givenName",
822       "sn",
823       "mail"
824    };
825    final String description =
826         "Perform a search in the directory server to find all entries " +
827         "matching the filter '(uid=jdoe)' anywhere below " +
828         "'dc=example,dc=com'.  Include only the givenName, sn, and mail " +
829         "attributes in the entries that are returned.";
830    examples.put(args, description);
831
832    return examples;
833  }
834}