我正在使用下面的server.xml文件将tomcat配置为使用JNDIRealm连接到ldap服务器。

但是我不断出错:


  引起原因:javax.naming.CommunicationException:本地主机:389 [根本异常是java.net.ConnectException:连接被拒绝:connect]


如果您看到我的连接URL使用了主机和636端口,则我在任何地方都无法使用localhost:389。那么,是什么原因导致连接到本地主机:389。

以下是server.xml:

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
          type="org.apache.catalina.UserDatabase"
          description="User database that can be updated and saved"
          factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
 SSLEnabled="true" maxThreads="150" scheme="https" secure="true"
 keystoreFile="keystore_key.jks" keystoreType="JKS"
 keystorePass="xxxxx" URIEncoding="UTF-8" clientAuth="false" sslProtocol="TLS" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.JNDIRealm"
            connectionURL="ldap://mycomapny.org:636"
            userSubtree="true"
            userBase="DC=test,DC=win,DC=user,DC=org"
            userSearch="(&amp;(sAMAccountName={0})(objectcategory=user))"
            userRoleName="memberOf"
            roleBase="DC=test,DC=win,DC=user,DC=org"
            roleName="cn"
            roleSearch="(member={0})"
            roleSubtree="true"
            roleNested="true"/>
<Host name="localhost" appBase="webapps">
            <Context docBase="spnego" path="">
                <Valve className="org.apache.catalina.authenticator.SpnegoAuthenticator"
                    storeDelegatedCredential="true" />
            </Context>
        </Host>
</Engine>
</Service>
</Server>

最佳答案

您是否尝试在connectionURL设置中指定ldap,即
connectionURL =“ ldaps://mycompany.org:636”

端口389用于非安全连接

09-26 11:59