java - 无法使用 JNDI 将信息存储为 LDAP 中的属性

标签 java ldap jndi apacheds

我正在尝试根据给定的教程 here 将 java 对象绑定(bind)为一组属性

//In the main() method of the program
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:10389/o=csRepository");
env.put(Context.OBJECT_FACTORIES, "sample.UserFactory");
 // Create the initial context
DirContext ctx = new InitialDirContext(env);

User usr = new User("Goro");
ctx.bind("cn=Kill Bill, ou=employees", null, usr.getAttributes(""));

我的 User 类如下,

public class User implements DirContext {
    String employer;
    Attributes myAttrs;

    public User(String employer){
          this.employer = employer;
          myAttrs = new BasicAttributes(true);
          Attribute oc = new BasicAttribute("objectclass");
          oc.add("extensibleObject");
          oc.add("top");

          myAttrs.put(oc);
          myAttrs.put("em", employer);
       }

    public Attributes getAttributes(String name) throws NamingException {
        if (!name.equals("")) {
            throw new NameNotFoundException();
        }
        return (Attributes) myAttrs.clone();
    }
    //other methods
}

当我尝试绑定(bind)时,

javax.naming.directory.NoSuchAttributeException: [LDAP: error code 16
- NO_SUCH_ATTRIBUTE: failed for MessageType : ADD_REQUEST Message ID : 2
    Add Request : Entry
    dn[n]: cn=Kill Bill, ou=employees,o=csRepository
    objectclass: extensibleObject
    objectclass: top
    cn: Kill Bill
    em: Goro
    ManageDsaITImpl Control
        Type OID    : '2.16.840.1.113730.3.4.2'
        Criticality : 'false' ' : ERR_04269 ATTRIBUTE_TYPE for OID em does not exist!]; remaining name 'cn=Kill Bill, ou=employees'

最佳答案

why does it complain that OID em does not exist.

因为事实并非如此。使用extensibleObject 使您能够向对象添加任何现有属性。它并不赋予您发明新属性的权利。

关于java - 无法使用 JNDI 将信息存储为 LDAP 中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22610071/

相关文章:

java - 使用Cloudera快速启动vm和pig shell的Apache Pig输入路径错误

java - Spring LDAP 无法从 AD LDS 读取

java - 在 AS7 中转换查找的 EJB View 时出现 ClassCastException

multithreading - JNDI 名称解析在 tomee 的新线程中失败

java.lang.IndexOutOfBoundsException - 使用 Protocol buffer 构建 Java 对象时

java - 为什么我会遇到异常(exception)?

javascript - 如何与公司 LDAP 服务器成功绑定(bind)

authentication - LSA 中 "Found no TGT' 的所有可能原因”

使用 JNDI 的 javax.naming.NoInitialContextException

java - 为什么本地simpleDateFormat会导致bug