java.naming.communication exception :( mydomain name):636(port)[根异常是java.net.connectException:连接时间到时:连接]

发布于 2025-02-05 17:22:37 字数 3109 浏览 3 评论 0原文

这是我以下的Java代码,我尝试通过在Active Directory和Java中设置SSL来验证管理员。

public class Unicode_passwordLdap{
    public static void main(String[] args){
        LdapContext ctx = null;
        
        try{
            Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
            System.setProperty("javax.net.ssl.trustStore", "C://Java//jre1.8.0_331//lib//security//cacerts");
            System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
            System.setProperty("javax.net.ssl.keyStore", "C://Java//jre1.8.0_331//lib//security//cacerts");
            System.setProperty("javax.net.ssl.keyStorePassword","changeit");
            System.setProperty("javax.net.debug", "all");
            String baseName = ",CN=Users,DC=trial,DC=com";
            Hashtable env = new Hashtable();  
            env.put(Context.INITIAL_CONTEXT_FACTORY,  "com.sun.jndi.ldap.LdapCtxFactory");  
            env.put(Context.SECURITY_AUTHENTICATION, "Simple");  
            env.put(Context.SECURITY_PRINCIPAL, "cn=administrator" + baseName);  //"[email protected]"
            env.put(Context.SECURITY_CREDENTIALS, "admin1*");  //"Panda123*"
            env.put(Context.PROVIDER_URL, "ldaps://WS2K19.trail.com:636"); //dc=trial,dc=com
            //ldaps://WS2K19.trail.com:636
            env.put(Context.SECURITY_PROTOCOL, "ssl");
            ctx = new InitialLdapContext(env,null); 
            System.out.println("Connection Successfull");
}catch(Exception e){
            //System.out.println("Password Cannot be Changed");
            e.printStackTrace();
        }
    }
}

这是我遇到的以下错误,当我运行此Java代码时:

javax.naming.CommunicationException: WS2K19.trail.com:636 [Root exception is java.net.ConnectException: Connection timed out: connect]
        at com.sun.jndi.ldap.Connection.<init>(Connection.java:235)
        at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:137)
        at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1615)
        at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2847)
        at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:348)
        at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxFromUrl(LdapCtxFactory.java:225)
        at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:189)
        at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:243)
        at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:154)
        at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:84)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:694)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
        at javax.naming.InitialContext.init(InitialContext.java:244)
        at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:154)
        at Unicode_passwordLdap.main(Unicode_passwordLdap.java:63)

有人可以帮助解决此错误!!!

This is my following java code, where I try to authenticate administrator by setting up ssl in active directory and java.

public class Unicode_passwordLdap{
    public static void main(String[] args){
        LdapContext ctx = null;
        
        try{
            Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
            System.setProperty("javax.net.ssl.trustStore", "C://Java//jre1.8.0_331//lib//security//cacerts");
            System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
            System.setProperty("javax.net.ssl.keyStore", "C://Java//jre1.8.0_331//lib//security//cacerts");
            System.setProperty("javax.net.ssl.keyStorePassword","changeit");
            System.setProperty("javax.net.debug", "all");
            String baseName = ",CN=Users,DC=trial,DC=com";
            Hashtable env = new Hashtable();  
            env.put(Context.INITIAL_CONTEXT_FACTORY,  "com.sun.jndi.ldap.LdapCtxFactory");  
            env.put(Context.SECURITY_AUTHENTICATION, "Simple");  
            env.put(Context.SECURITY_PRINCIPAL, "cn=administrator" + baseName);  //"[email protected]"
            env.put(Context.SECURITY_CREDENTIALS, "admin1*");  //"Panda123*"
            env.put(Context.PROVIDER_URL, "ldaps://WS2K19.trail.com:636"); //dc=trial,dc=com
            //ldaps://WS2K19.trail.com:636
            env.put(Context.SECURITY_PROTOCOL, "ssl");
            ctx = new InitialLdapContext(env,null); 
            System.out.println("Connection Successfull");
}catch(Exception e){
            //System.out.println("Password Cannot be Changed");
            e.printStackTrace();
        }
    }
}

This is the following error I get, when I run this java code:

javax.naming.CommunicationException: WS2K19.trail.com:636 [Root exception is java.net.ConnectException: Connection timed out: connect]
        at com.sun.jndi.ldap.Connection.<init>(Connection.java:235)
        at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:137)
        at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1615)
        at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2847)
        at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:348)
        at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxFromUrl(LdapCtxFactory.java:225)
        at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:189)
        at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:243)
        at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:154)
        at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:84)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:694)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
        at javax.naming.InitialContext.init(InitialContext.java:244)
        at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:154)
        at Unicode_passwordLdap.main(Unicode_passwordLdap.java:63)

Could someone help to solve this error!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文