【问题标题】:Add new object class in LDAP schema using JNDI使用 JNDI 在 LDAP 模式中添加新对象类
【发布时间】:2011-03-25 10:40:52
【问题描述】:

我编写了在 LDAP 模式中添加对象类的代码。它适用于 SunOne 目录服务。但它在 OpenLdap 的情况下给出“InvalidAttributeValueException”,在 IBM TDS 的情况下给出“OperationNotSupportedException”。有谁知道这 3 个目录服务的通用代码。

我的代码:

包演示;

导入 javax.naming.; 导入 javax.naming.directory.; 导入 java.util.Hashtable;

公共类 AddObjectClass {

public static void main(String args[])
{
    Hashtable env = new Hashtable(); 
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL,"ldap://localhost:389");
    env.put(Context.SECURITY_AUTHENTICATION,"simple");
    env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
    env.put(Context.SECURITY_CREDENTIALS,"cantsay");

    Attributes attrs = new BasicAttributes(true); // ignore case
    attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.1.45");
    attrs.put("NAME", "myObjectClass");
    attrs.put("DESC", "for JNDI example only");
    attrs.put("SUP", "top");
    attrs.put("STRUCTURAL", "true");
    Attribute must = new BasicAttribute("MUST", "cn");
    must.add("objectclass");
    attrs.put(must);

    try
    {
    DirContext ctx = new InitialDirContext(env);
    DirContext schema = ctx.getSchema("");
    schema.createSubcontext("ClassDefinition/myObjectClass", attrs);
    System.out.println("added");
    ctx.close();
    }catch(Exception e){e.printStackTrace();}

}

}

【问题讨论】:

    标签: jakarta-ee ldap jndi


    【解决方案1】:

    这里是答案的开始。在 LDAP V3 RFC 中记录了模式是动态的。这是您在Sun one 中使用的。我在 Active-Directory 中使用 LDIF 文件做同样的事情。但是有一个技巧,您添加以加载新属性,并在加载类之前使用特殊属性“重新加载模式”。

    我只是想让您知道,动态功能并不总是出现在所有 LDAP V3 目录中。当它出现时,它就不是那么标准了。

    我无法谈论 IBM TDS。但我可以肯定的是,即使 OpenLDAP 能够支持动态模式,我使用的大多数发行版都是在 slapd 启动期间加载的文本模式编译的。这些文本文件位于 /etc/openldap/schema/ 中。而且您必须重新启动守护进程 slapd 才能使用新架构。

    对于 OpenLDAP 或许可以看看 here

    This article 谈论 IBM TDS 上的动态模式。

    希望对你有帮助。

    日本

    【讨论】:

      猜你喜欢
      • 2010-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多