添加用于ldap时出错[LDAP:错误代码17 - javaSerializedData:属性类型undefined]

时间:2012-08-15 06:14:43

标签: java ldap openldap ldapconnection

我使用此代码段将用户添加到ldap

**public DirContext getLDAPDirContext() throws NamingException {
    final Hashtable envValues = new Hashtable();
    // Assign the JNDI environment values in Map
    envValues.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    envValues.put(Context.PROVIDER_URL, url);
    envValues.put(Context.SECURITY_PRINCIPAL,dn); // specify the username
    envValues.put(Context.SECURITY_CREDENTIALS,password);           // specify the password
    return new InitialDirContext(envValues);
}
public static void main(String arg[]) throws NamingException {
    LdapNew ldapNew = new LdapNew();
    String groupDN ="ou=user,dc=ldap,dc=***,dc=***";
    BasicAttributes myAttrs = new BasicAttributes(true);  //Basic Attributes
    myAttrs.put("uid","chamils");
    myAttrs.put("objectClass","top");
    myAttrs.put("objectClass","dcObject");
    myAttrs.put("objectClass","organization");
    myAttrs.put("objectClass", "inetOrgPerson");
    myAttrs.put("cn","FNAME LNAME");
    myAttrs.put("displayname", "FNAME LNAMEE");
    myAttrs.put("givenname","Chamilseeee");
    myAttrs.put("sn","Thanthrimudaliged");
    myAttrs.put("mail","*******");
    DirContext ctx = ldapNew.getLDAPDirContext();
    ctx.bind("uid=chamils,ou=user,dc=ldap,dc=****,dc=***",myAttrs);
}**

但它给出了

  

线程“main”中的异常   javax.naming.directory.InvalidAttributeIdentifierException:[LDAP:   错误代码17 - javaSerializedData:属性类型undefined];   剩余名称'uid = chamils,ou = user,dc = ldap,dc = ,dc = 'at at   com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3110)at at   com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2987)at at   com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2794)at at   com.sun.jndi.ldap.LdapCtx.c_bind(LdapCtx.java:397)at at   com.sun.jndi.ldap.LdapCtx.c_bind(LdapCtx.java:354)at at   com.sun.jndi.toolkit.ctx.ComponentContext.p_bind(ComponentContext.java:596)     在   com.sun.jndi.toolkit.ctx.PartialCompositeContext.bind(PartialCompositeContext.java:183)     在   com.sun.jndi.toolkit.ctx.PartialCompositeContext.bind(PartialCompositeContext.java:173)     在javax.naming.InitialContext.bind(InitialContext.java:400)at   LdapNew.main(LdapNew.java:49)at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     在java.lang.reflect.Method.invoke(Method.java:597)at   com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

为什么会这样。

1 个答案:

答案 0 :(得分:1)

您需要将include schema/java.schema添加到OpenLDAP配置中。