【发布时间】: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