title: Set method timeout on Ldap search
body: <pre><code>private Authentication authenticateUserPassword(UsernamePasswordAuthenticationToken token) throws NamingException {
      Object login = login(token);
      LOGGER.debug("Starting authentication login='{}'", login);
      Object password = token.getCredentials();
  
      LdapContext ctx = createLdapCtx(login, password);
      SearchControls ctrls = createSearchControls();
      String filter = String.format(this.filter, login);
  
      NamingEnumeration&lt;SearchResult&gt; ne = ctx.search(dn, filter, ctrls);
      ....
  </code></pre>
  
  <p>I have the folowing method to login user. It depends on LDAP. Sometimes it hangs on last row. I don't know why. It reproduces sometimes on performance tests.</p>
  
  <p>Is there way to wait some time and if method didn't respond - return some predefined value ?</p>
  
  <p>P.S.</p>
  
  <pre><code>private LdapContext createLdapCtx(Object login, Object password) throws NamingException {
      Hashtable&lt;String, String&gt; props = new Hashtable&lt;String, String&gt;();
      props.put(Context.INITIAL_CONTEXT_FACTORY, factory);
      props.put(Context.PROVIDER_URL, url);
      props.put(Context.SECURITY_AUTHENTICATION, "simple");
      props.put(Context.SECURITY_PRINCIPAL, String.format(domain, login));
      props.put(Context.SECURITY_CREDENTIALS, password.toString());
  
      return new InitialLdapContext(props, null);
  }
  </code></pre>