使用Tomcat的外部LDAP JNDI连接

使用Tomcat的外部LDAP JNDI连接,tomcat,ldap,jndi,Tomcat,Ldap,Jndi,我想知道如何使用TOMCAT中的JNDI配置连接外部LDAP 我的代码类似于 try { InitialContext iniCtx = new InitialContext(); ctx = (LdapContext) iniCtx.lookup("external/ldap/worker"); //System.out.println("LDAP Context initialized::"+ctx); if(ctx!=null) { urlP

我想知道如何使用TOMCAT中的JNDI配置连接外部LDAP

我的代码类似于

try {
    InitialContext iniCtx = new InitialContext();
    ctx = (LdapContext) iniCtx.lookup("external/ldap/worker");
    //System.out.println("LDAP Context initialized::"+ctx);
    if(ctx!=null) {
        urlProvider=ctx.getEnvironment().get("java.naming.provider.url").toString();
    } 

} catch (NamingException ne) {                        
    throw new NamingException(ne.toString());
} 
Tomcat中的My Context.xml包含以下条目

<Resource 
  useDataSourceFactory="true"
  name="external/ldap/worker"
  auth="Container"
  type="com.sun.jndi.ldap.LdapCtxFactory"
  java.naming.factory.initial="com.sun.jndi.ldap.LdapCtxFactory"
  java.naming.provider.url="ldap://corpt605.corporate.***.***:13891"
  java.naming.security.authentication="simple"
  java.naming.security.principal="uid=cpasysuser,ou=******,o=***.com"
  java.naming.security.credentials="*********"
/>
<resource-ref>
    <description>E2k Ldap Datasource example</description>
    <res-ref-name>external/ldap/worker</res-ref-name>
    <res-type>com.sun.jndi.ldap.LdapCtxFactory</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
我的web.xml有以下条目

<Resource 
  useDataSourceFactory="true"
  name="external/ldap/worker"
  auth="Container"
  type="com.sun.jndi.ldap.LdapCtxFactory"
  java.naming.factory.initial="com.sun.jndi.ldap.LdapCtxFactory"
  java.naming.provider.url="ldap://corpt605.corporate.***.***:13891"
  java.naming.security.authentication="simple"
  java.naming.security.principal="uid=cpasysuser,ou=******,o=***.com"
  java.naming.security.credentials="*********"
/>
<resource-ref>
    <description>E2k Ldap Datasource example</description>
    <res-ref-name>external/ldap/worker</res-ref-name>
    <res-type>com.sun.jndi.ldap.LdapCtxFactory</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
当我使用这个JNDI数据源时,我得到以下错误:

2014年10月8日10:12:03394错误waveset.ge.commons.LdapJndiConnection_CDI:52-getLdapCntxt::Ldap上下文查找过程中出错javax.naming.NameNotFoundException:名称[external/Ldap/worker]未绑定在此上下文中。找不到[外部]


怎么了?

可能是Hi的重复,我以前读过该博客,但这是针对同一jvm中的和ldap的。我正在diff jvm上使用ldap。所以这对我来说可能没有帮助。tomcat不接受资源名称,因此没有给我ldap jndi的上下文。这不是博客,这是一个SO问题,也不是“同一JVM中的ldap”。没有这样的事。