JNDI-Beispiel für LDAP Status Code 65 (objectClassViolation)
Durchführung einer Add-Operation gegen OpenLDAP 2.4, dem Personeneintrag fehlt der von der Objektklasse
person geforderte Nachname (
sn). OpenLDAP quittiert das mit einem Statuscode 65 (
objectClassViolation), der von JNDI auf eine
javax.naming.directory.SchemaViolationException gemappt wird.
- LDAP-Server: OpenLDAP 2.4, Host: magritte, Port:389
- Java-Version: Java 7, JUnit 4
Java-Quelltext
@Test(expected=SchemaViolationException.class)
public void objectClassViolation() 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/dc=bundestag,dc=de");
env.put(Context.SECURITY_PRINCIPAL, "cn=Manager,dc=magritte");
env.put(Context.SECURITY_CREDENTIALS, "...");
InitialDirContext ctx = new InitialDirContext(env);
Attributes attrs = new BasicAttributes();
Attribute ocls = new BasicAttribute("objectClass");
ocls.add("top");
ocls.add("person");
attrs.put(ocls);
attrs.put("cn", "Paulchen Panther");
ctx.createSubcontext("cn=Paulchen Panther,ou=personen", attrs);
}
Klicken Sie auf "Exception", um den Stacktrace zu sehen:
Exception
javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - object class 'person' requires attribute 'sn']; remaining name 'cn=Paulchen Panther,ou=personen'
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.c_createSubcontext(Unknown Source)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_createSubcontext(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(Unknown Source)
at javax.naming.directory.InitialDirContext.createSubcontext(Unknown Source)
...