简体   繁体   English

如何在Tomcat Server.xml中配置自定义JNDIRealm(为LDAP添加了读取超时)

[英]How to configure Custom JNDIRealm (added read timeout for LDAP) in Tomcat Server.xml

We use JNDIRealm (Tomcat 6) for LDAP authentication. 我们使用JNDIRealm(Tomcat 6)进行LDAP身份验证。 May be due to LDAP flakiness, one thread gets lock on JNDIRealm.authenticate method and causing thread dump. 可能是由于LDAP脆弱,一个线程在JNDIRealm.authenticate方法上锁定并导致线程转储。 To solve this, added CustomJNDIRealm class that extends JNDIRealm as shown below 为了解决这个问题,添加了CustomJNDIRealm类,该类扩展了JNDIRealm,如下所示

 package com.gop.it.msoft;

 import org.apache.catalina.realm.JNDIRealm;

 public class CustomJNDIRealm extends JNDIRealm {
 protected String readTimeout;
    @Override
    protected Hashtable<String,String> getDirectoryContextEnvironment() {
      Hashtable<String,String> env = new Hashtable<String,String>();
        if(readTimeout != null) env.put("com.sun.jndi.ldap.read.timeout", readTimeout);
    return env;
    }
 }

Now, how do I configure in Server.xml ? 现在,如何在Server.xml中进行配置? By doing below, I get ClassNotFoundException. 通过执行以下操作,我得到ClassNotFoundException。 Please help. 请帮忙。

<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"/>

Thanks a bunch 谢谢一大堆

The Realm implementation has to be available before the webapp is loaded. 在加载Webapp之前,必须实现Realm实现。 So, it has to be in a JAR file in Tomcat's lib directory. 因此,它必须在Tomcat的lib目录中的JAR文件中。 Putting it into the webapp's own WEB-INF/lib can't work. 将其放入Webapp自己的WEB-INF / lib中无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM