Код: Выделить всё
public static DirContext initSimpleContext() {
ensureProperConfig();
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, Config.get(Config.LDAP_DOMAIN) + "/" + Config.get(Config.LDAP_BASEDN));
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, Config.get(Config.LDAP_USER));
env.put(Context.SECURITY_CREDENTIALS, PasswordObfuscation.retrieve(Config.get(Config.LDAP_PASSWORD)));
try {
DirContext context = new InitialDirContext(env);
return context;
} catch (NamingException e) {
e.printStackTrace();
System.err.println("#getSimpleContext() - Error when trying to create the context!");
}
return null;
}
private static void ensureProperConfig() throws MissingResourceException {
if (!Config.exist(Config.LDAP_DOMAIN)) {
log.info("Missing " + Config.LDAP_DOMAIN + " property");
throw new MissingResourceException("", "", "");
}
if (!Config.exist(Config.LDAP_BASEDN)) {
log.info("Missing " + Config.LDAP_BASEDN + " property");
throw new MissingResourceException("", "", "");
}
if (!Config.exist(Config.LDAP_USER)) {
log.info("Missing " + Config.LDAP_USER + " property");
throw new MissingResourceException("", "", "");
}
if (!Config.exist(Config.LDAP_PASSWORD)) {
log.info("Missing " + Config.LDAP_PASSWORD + " property");
throw new MissingResourceException("", "", "");
}
}
Код: Выделить всё
2024-05-18 10:16:51,549 ERROR [stderr] (default task-2) javax.naming.CommunicationException: Connection timed out (Read failed) [Root exception is java.net.SocketException: Connection timed out (Read failed)]; remaining name 'groupId=user,groupId=MyGroupId'
2024-05-18 10:16:51,549 ERROR [stderr] (default task-2) at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:2031)
2024-05-18 10:16:51,549 ERROR [stderr] (default task-2) at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1873)
2024-05-18 10:16:51,549 ERROR [stderr] (default task-2) at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1798)
2024-05-18 10:16:51,549 ERROR [stderr] (default task-2) at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:392)
2024-05-18 10:16:51,549 ERROR [stderr] (default task-2) at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:358)
2024-05-18 10:16:51,549 ERROR [stderr] (default task-2) at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:341)
2024-05-18 10:16:51,549 ERROR [stderr] (default task-2) at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:267)
... 1 more
Подробнее здесь: https://stackoverflow.com/questions/784 ... n-timeouts