JNDI-Beispiel für LDAP Status Code 2 (protocolError)
Durchführung einer Bind-Operation gegen OpenLDAP 2.4, geforderte Protokollversion ist das veraltete LDAP v2. OpenLDAP quittiert das mit einem Statuscode 2 (
protocolError), der von JNDI auf eine
javax.naming.CommunicationException gemappt wird.
- LDAP-Server: OpenLDAP 2.4, Host: magritte, Port:389
- Java-Version: Java 7, JUnit 4
Java-Quelltext
@Test(expected=CommunicationException.class)
public void protocolError() throws NamingException {
Hashtable<String, String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,
"ldap://magritte:389");
env.put("java.naming.ldap.version", "2");
InitialDirContext ctx = new InitialDirContext(env);
ctx.list("");
}
Klicken Sie auf "Exception", um den Stacktrace zu sehen:
Exception
javax.naming.CommunicationException: [LDAP: error code 2 - historical protocol version requested, use LDAPv3 instead]
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.connect(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.<init>(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(Unknown Source)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(Unknown Source)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at javax.naming.directory.InitialDirContext.<init>(Unknown Source)
...