-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
17.0.16
-
x86_64
-
linux_redhat_6.0
A DESCRIPTION OF THE PROBLEM :
To connect with LDAP server, we use "javax.naming.directory.InitialDirContext" class. In the "Context.PROVIDER_URL", we have provided ldap url with protocal "ldap"(non TLS) having host as FQDN`. This FQDN resolved to 2 IP. One is IPv4 and another is IPv6. Somehow, IPv4 is not reachable and IPv6 is reachable. In that case, we could not establish connection with LDAP server. But the expectation was if the one IP is not reachable, another IP should be tried.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create java class with below code:
--------------------------------------------------------------------------------------------
package com.ldap;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
public class LdapTest {
public static void main(String[] args) {
String fqdn = args[0];
String dn= args[1];
String password = args[2];
System.out.println("FQDN : " + fqdn + ", PASSWORD: " + password);
Hashtable<String, String> env = createEnvironmentForContextCreation(fqdn, dn, password);
try {
InitialDirContext refInitialDirContext = new InitialDirContext(env);
System.out.println("Context created successfully");
} catch (NamingException e) {
System.out.println("Context creation failed");
e.printStackTrace();
}
}
private static Hashtable<String, String> createEnvironmentForContextCreation(String fqdn, String dn, String password) {
String providerURL = "ldap://" + fqdn + ":389/dc=netact,dc=net";
Hashtable<String, String> env = new Hashtable<String, String>();
env.put("com.sun.jndi.ldap.connect.pool.prefsize", "1");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, providerURL);
env.put("java.naming.ldap.version", "3");
env.put("com.sun.jndi.ldap.connect.pool", "true");
env.put("com.sun.jndi.ldap.connect.pool.maxsize", "500");
env.put("com.sun.jndi.ldap.connect.pool.timeout", "10000");
env.put("com.sun.jndi.ldap.connect.timeout", "2000");
env.put("com.sun.jndi.ldap.read.timeout", "300000");
env.put(Context.REFERRAL, "ignore");
env.put(Context.SECURITY_PRINCIPAL, dn);
env.put(Context.SECURITY_CREDENTIALS, password);
return env;
}
}
-------------------------------------------------------------------------------------------------------------------
2. Compile and create executable jar for the able class.
3. Arrange a VM or system have 2 IP(one IPv4 and another IPv6) and LDAP server is running on it. host must have OpenJDK 17 install over there.
4. copy the executable jar on the some system.
5. Make the LDAP SERVER IPv4 IP not reachable.
6. run executable jar with parameters 1. FQDN of LDAP server, 2. BIND DN, 3. Password
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Get the message:
Context created successfully
ACTUAL -
Getting below error:
[root@vm152 ~]# java -jar ldap_test.jar cb0353lb1.netact.nsn-rdnet.net Manager
FQDN : cb0353lb1.netact.nsn-rdnet.net, PASSWORD: Manager
Context creation failed
javax.naming.CommunicationException: cb0353lb1.netact.nsn-rdnet.net:389 [Root exception is java.net.NoRouteToHostException: No route to host]
at java.naming/com.sun.jndi.ldap.Connection.<init>(Connection.java:251)
at java.naming/com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:137)
at java.naming/com.sun.jndi.ldap.LdapClientFactory.createPooledConnection(LdapClientFactory.java:71)
at java.naming/com.sun.jndi.ldap.pool.Connections.createConnection(Connections.java:185)
at java.naming/com.sun.jndi.ldap.pool.Connections.getAvailableConnection(Connections.java:151)
at java.naming/com.sun.jndi.ldap.pool.Pool.getOrCreatePooledConnection(Pool.java:189)
at java.naming/com.sun.jndi.ldap.pool.Pool.getPooledConnection(Pool.java:148)
at java.naming/com.sun.jndi.ldap.LdapPoolManager.getLdapClient(LdapPoolManager.java:341)
at java.naming/com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1608)
at java.naming/com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2848)
at java.naming/com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:348)
at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxFromUrl(LdapCtxFactory.java:229)
at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:189)
at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:247)
at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:154)
at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:84)
at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:732)
at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
at java.naming/javax.naming.InitialContext.init(InitialContext.java:236)
at java.naming/javax.naming.InitialContext.<init>(InitialContext.java:208)
at java.naming/javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:130)
at com.ldap.LdapTest.main(LdapTest.java:19)
Caused by: java.net.NoRouteToHostException: No route to host
at java.base/sun.nio.ch.Net.pollConnect(Native Method)
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:554)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:602)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.net.Socket.connect(Socket.java:633)
at java.naming/com.sun.jndi.ldap.Connection.createConnectionSocket(Connection.java:340)
at java.naming/com.sun.jndi.ldap.Connection.createSocket(Connection.java:283)
at java.naming/com.sun.jndi.ldap.Connection.<init>(Connection.java:230)
... 21 more
---------- BEGIN SOURCE ----------
package com.ldap;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
public class LdapTest {
public static void main(String[] args) {
String fqdn = args[0];
String dn= args[1];
String password = args[2];
System.out.println("FQDN : " + fqdn + ", PASSWORD: " + password);
Hashtable<String, String> env = createEnvironmentForContextCreation(fqdn, dn, password);
try {
InitialDirContext refInitialDirContext = new InitialDirContext(env);
System.out.println("Context created successfully");
} catch (NamingException e) {
System.out.println("Context creation failed");
e.printStackTrace();
}
}
private static Hashtable<String, String> createEnvironmentForContextCreation(String fqdn, String dn, String password) {
String providerURL = "ldap://" + fqdn + ":389/dc=netact,dc=net";
Hashtable<String, String> env = new Hashtable<String, String>();
env.put("com.sun.jndi.ldap.connect.pool.prefsize", "1");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, providerURL);
env.put("java.naming.ldap.version", "3");
env.put("com.sun.jndi.ldap.connect.pool", "true");
env.put("com.sun.jndi.ldap.connect.pool.maxsize", "500");
env.put("com.sun.jndi.ldap.connect.pool.timeout", "10000");
env.put("com.sun.jndi.ldap.connect.timeout", "2000");
env.put("com.sun.jndi.ldap.read.timeout", "300000");
env.put(Context.REFERRAL, "ignore");
env.put(Context.SECURITY_PRINCIPAL, dn);
env.put(Context.SECURITY_CREDENTIALS, password);
return env;
}
}
---------- END SOURCE ----------
To connect with LDAP server, we use "javax.naming.directory.InitialDirContext" class. In the "Context.PROVIDER_URL", we have provided ldap url with protocal "ldap"(non TLS) having host as FQDN`. This FQDN resolved to 2 IP. One is IPv4 and another is IPv6. Somehow, IPv4 is not reachable and IPv6 is reachable. In that case, we could not establish connection with LDAP server. But the expectation was if the one IP is not reachable, another IP should be tried.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create java class with below code:
--------------------------------------------------------------------------------------------
package com.ldap;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
public class LdapTest {
public static void main(String[] args) {
String fqdn = args[0];
String dn= args[1];
String password = args[2];
System.out.println("FQDN : " + fqdn + ", PASSWORD: " + password);
Hashtable<String, String> env = createEnvironmentForContextCreation(fqdn, dn, password);
try {
InitialDirContext refInitialDirContext = new InitialDirContext(env);
System.out.println("Context created successfully");
} catch (NamingException e) {
System.out.println("Context creation failed");
e.printStackTrace();
}
}
private static Hashtable<String, String> createEnvironmentForContextCreation(String fqdn, String dn, String password) {
String providerURL = "ldap://" + fqdn + ":389/dc=netact,dc=net";
Hashtable<String, String> env = new Hashtable<String, String>();
env.put("com.sun.jndi.ldap.connect.pool.prefsize", "1");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, providerURL);
env.put("java.naming.ldap.version", "3");
env.put("com.sun.jndi.ldap.connect.pool", "true");
env.put("com.sun.jndi.ldap.connect.pool.maxsize", "500");
env.put("com.sun.jndi.ldap.connect.pool.timeout", "10000");
env.put("com.sun.jndi.ldap.connect.timeout", "2000");
env.put("com.sun.jndi.ldap.read.timeout", "300000");
env.put(Context.REFERRAL, "ignore");
env.put(Context.SECURITY_PRINCIPAL, dn);
env.put(Context.SECURITY_CREDENTIALS, password);
return env;
}
}
-------------------------------------------------------------------------------------------------------------------
2. Compile and create executable jar for the able class.
3. Arrange a VM or system have 2 IP(one IPv4 and another IPv6) and LDAP server is running on it. host must have OpenJDK 17 install over there.
4. copy the executable jar on the some system.
5. Make the LDAP SERVER IPv4 IP not reachable.
6. run executable jar with parameters 1. FQDN of LDAP server, 2. BIND DN, 3. Password
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Get the message:
Context created successfully
ACTUAL -
Getting below error:
[root@vm152 ~]# java -jar ldap_test.jar cb0353lb1.netact.nsn-rdnet.net Manager
FQDN : cb0353lb1.netact.nsn-rdnet.net, PASSWORD: Manager
Context creation failed
javax.naming.CommunicationException: cb0353lb1.netact.nsn-rdnet.net:389 [Root exception is java.net.NoRouteToHostException: No route to host]
at java.naming/com.sun.jndi.ldap.Connection.<init>(Connection.java:251)
at java.naming/com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:137)
at java.naming/com.sun.jndi.ldap.LdapClientFactory.createPooledConnection(LdapClientFactory.java:71)
at java.naming/com.sun.jndi.ldap.pool.Connections.createConnection(Connections.java:185)
at java.naming/com.sun.jndi.ldap.pool.Connections.getAvailableConnection(Connections.java:151)
at java.naming/com.sun.jndi.ldap.pool.Pool.getOrCreatePooledConnection(Pool.java:189)
at java.naming/com.sun.jndi.ldap.pool.Pool.getPooledConnection(Pool.java:148)
at java.naming/com.sun.jndi.ldap.LdapPoolManager.getLdapClient(LdapPoolManager.java:341)
at java.naming/com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1608)
at java.naming/com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2848)
at java.naming/com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:348)
at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxFromUrl(LdapCtxFactory.java:229)
at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:189)
at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:247)
at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:154)
at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:84)
at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:732)
at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
at java.naming/javax.naming.InitialContext.init(InitialContext.java:236)
at java.naming/javax.naming.InitialContext.<init>(InitialContext.java:208)
at java.naming/javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:130)
at com.ldap.LdapTest.main(LdapTest.java:19)
Caused by: java.net.NoRouteToHostException: No route to host
at java.base/sun.nio.ch.Net.pollConnect(Native Method)
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:554)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:602)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.net.Socket.connect(Socket.java:633)
at java.naming/com.sun.jndi.ldap.Connection.createConnectionSocket(Connection.java:340)
at java.naming/com.sun.jndi.ldap.Connection.createSocket(Connection.java:283)
at java.naming/com.sun.jndi.ldap.Connection.<init>(Connection.java:230)
... 21 more
---------- BEGIN SOURCE ----------
package com.ldap;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
public class LdapTest {
public static void main(String[] args) {
String fqdn = args[0];
String dn= args[1];
String password = args[2];
System.out.println("FQDN : " + fqdn + ", PASSWORD: " + password);
Hashtable<String, String> env = createEnvironmentForContextCreation(fqdn, dn, password);
try {
InitialDirContext refInitialDirContext = new InitialDirContext(env);
System.out.println("Context created successfully");
} catch (NamingException e) {
System.out.println("Context creation failed");
e.printStackTrace();
}
}
private static Hashtable<String, String> createEnvironmentForContextCreation(String fqdn, String dn, String password) {
String providerURL = "ldap://" + fqdn + ":389/dc=netact,dc=net";
Hashtable<String, String> env = new Hashtable<String, String>();
env.put("com.sun.jndi.ldap.connect.pool.prefsize", "1");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, providerURL);
env.put("java.naming.ldap.version", "3");
env.put("com.sun.jndi.ldap.connect.pool", "true");
env.put("com.sun.jndi.ldap.connect.pool.maxsize", "500");
env.put("com.sun.jndi.ldap.connect.pool.timeout", "10000");
env.put("com.sun.jndi.ldap.connect.timeout", "2000");
env.put("com.sun.jndi.ldap.read.timeout", "300000");
env.put(Context.REFERRAL, "ignore");
env.put(Context.SECURITY_PRINCIPAL, dn);
env.put(Context.SECURITY_CREDENTIALS, password);
return env;
}
}
---------- END SOURCE ----------