2016-05-11 5 views
0

Ich erhalte die follwing FehlerInvalidAttributeIdentifierException: [LDAP: Fehlercode 17 - Objektklasse: Attribute enthalten unangemessene Zeichen]

javax.naming.directory.InvalidAttributeIdentifierException: [LDAP: Fehlercode 17 - Objektklasse: AttributeDescription enthält unpassende Zeichen];

Das ist meine Klasse:

public class OpenLDAPTest { 

public static void main(String[] args) { 
    String url = "ldap://localhost:389"; 
    Hashtable env = new Hashtable(); 
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 
    env.put(Context.PROVIDER_URL, url); 
    env.put(Context.SECURITY_AUTHENTICATION, "simple"); 
    env.put(Context.SECURITY_PRINCIPAL, "cn=Manager,dc=maxcrc,dc=com"); 
    env.put(Context.SECURITY_CREDENTIALS, "secret"); 
    try { 
     DirContext ctx = new InitialDirContext(env); 
     System.out.println("connected"); 
     System.out.println(ctx.getEnvironment()); 
     System.out.println("Creating subContext"); 
     String name = "dc=mine, dc=com"; 
     Attributes atrs = new BasicAttributes(); 
     Attribute atr1 = new BasicAttribute("Object Class"); 
     atr1.add("OrgPerson"); 
     atrs.put(atr1); 
     Attribute atr2 = new BasicAttribute("cn"); 
     atr2.add("sathish"); 
     atrs.put(atr2); 
     atrs.put("Phone", "12345"); 
     Context c = ctx.createSubcontext(name, atrs); 
     System.out.println(c.getEnvironment()); 
     ctx.close(); 

    } catch (AuthenticationNotSupportedException ex) { 
     System.out.println("The authentication is not supported by the server"); 
    } catch (AuthenticationException ex) { 
     System.out.println("incorrect password or username"); 
    } catch (NamingException ex) { 
     //System.out.println("error when trying to create the context"); 
     ex.printStackTrace(); 
    } 
} 

} 
+0

Sind Sie sicher, dass Sie ein Attribut namens "Objektklasse" haben? (Der Platz ist wahrscheinlich das Problem). Laut https://www.google.com/support/enterprise/static/postini/docs/admin/en/dss_admin/prep_ldap.html sollte es wahrscheinlich "objectclass" sein. –

+0

Eigentlich bin ich nicht so gut in LDAP, ich sah Code im Netz, es arbeitete mit ApacheDirectoryStudio, dann versuchte ich für OpenLDAP, meine Absicht ist Code für den Zugang zu openLDAP mit Java schreiben – Sat

+0

Ich habe in "objectclass" geändert, aber immer noch den gleichen Fehler bekommen ... Weißt du, wie diese LDAP-Abfragen in Java zu verwenden? Wenn Sie wissen, bitte führen Sie mich .. Danke – Sat

Antwort

1

Sie besser würde Ihre Frage mit neueren Fehler prompt aktualisieren, nachdem der Raum mit dem Objekt und Klasse wegzulassen?