code: public SearchResult searchForSingleUsername(final DirContext ctx, final String username) throws NamingException {
          final List<SearchResult> results = searchForUsername(ctx, username);
          if (results == null || results.size() == 0) {
              LOGGER.debug("Search for (" + username + ") did not produce any results");
              return null;
          } else if (results.size() == 1) {
              LOGGER.debug("Search for (" + username + ") produced a result");
              return results.get(0);
          } else {
              throw new NamingException("Multiple entries in the directory contain the same username. This scenario is not supported");
          }
      }
docs: Performs a search for the specified username. Internally, this method queries on
  the attribute defined by {@link Config.AlpineKey#LDAP_ATTRIBUTE_NAME}.
  @param ctx the DirContext to use
  @param username the username to query on
  @return a list of SearchResult objects. If the username is found, the list should typically only contain one result.
  @throws NamingException if an exception is thrown
  @since 1.4.0