gpt4 book ai didi

java.net.ConnectException : Connection refused: while connecting to Ldap

转载 作者:行者123 更新时间:2023-11-30 05:38:42 25 4
gpt4 key购买 nike

我尝试通过 java 代码连接 LDAP,但出现以下异常。有人能告诉我我错过了什么吗?这是我的代码-

 initialProperties = new Properties();
initialProperties.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
initialProperties.put(Context.PROVIDER_URL, providerURL);
initialProperties.put(Context.SECURITY_PRINCIPAL, securityPrincipal);
initialProperties.put(Context.SECURITY_CREDENTIALS, securityCredentials);
initialProperties.put(Context.SECURITY_AUTHENTICATION, authentication);
try {
context = new InitialDirContext(initialProperties);
}
catch(Exception e)
{e.printStackTrace();}

最佳答案

我稍微改变了你的代码,它在我的代码中有效。

public class LdapTest {

public static void main(String[] args) {

Properties initialProperties = new Properties();
initialProperties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
initialProperties.put(Context.PROVIDER_URL, "ldap://192.168.0.179:389");
initialProperties.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
initialProperties.put(Context.SECURITY_CREDENTIALS, "dirmanager");
initialProperties.put(Context.SECURITY_AUTHENTICATION, "simple");

try {
InitialDirContext context = new InitialDirContext(initialProperties);
System.out.println(context);
}
catch(Exception e)
{e.printStackTrace();}
}
}

不要忘记首先启动 LDAP 服务器。

关于java.net.ConnectException : Connection refused: while connecting to Ldap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56136148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com