title: How to configure Custom JNDIRealm (added read timeout for LDAP) in Tomcat Server.xml
body: <p>We use JNDIRealm (Tomcat 6) for LDAP authentication. May be due to LDAP flakiness, one thread gets lock on JNDIRealm.authenticate method and causing thread dump. To solve this, added CustomJNDIRealm class that extends JNDIRealm as shown below</p>
  
  <pre><code> package com.gop.it.msoft;
  
   import org.apache.catalina.realm.JNDIRealm;
  
   public class CustomJNDIRealm extends JNDIRealm {
   protected String readTimeout;
      @Override
      protected Hashtable&lt;String,String&gt; getDirectoryContextEnvironment() {
        Hashtable&lt;String,String&gt; env = new Hashtable&lt;String,String&gt;();
          if(readTimeout != null) env.put("com.sun.jndi.ldap.read.timeout", readTimeout);
      return env;
      }
   }
  </code></pre>
  
  <p>Now, how do I configure in Server.xml ? By doing below, I get ClassNotFoundException. Please help.</p>
  
  <pre><code>&lt;Realm allRolesMode="authOnly" className="com.gop.it.msoft.CustomJNDIRealm" connectionURL="ldaps://ldap.gop.com:636" referrals="follow" userPattern="uid={0},ou=People,o=gop.com" readTimeout="5000" userSubtree="false"/&gt;
  </code></pre>
  
  <p>Thanks a bunch</p>