我收到了以下错误
javax.naming.directory.InvalidAttributeIdentifierException:[LDAP:错误代码17 - 对象类:AttributeDescription包含不适当的字符];
这是我的班级:
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 :(得分:1)
在省略对象和类的空格后,您最好使用较新的错误提示更新您的问题吗?