从JAVA在OpenDJ(LDAP)中创建新的对象类

时间:2017-06-08 11:18:52

标签: java ldap

我必须从java JNDI在LDAP服务器中创建自定义对象类。对象类应该有3个带有值的字段:Name,OID,Description。至今 我设法只定义了环境。

Properties properties = new Properties();

    properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    properties.put(Context.PROVIDER_URL, ldapUrl);
    properties.put(Context.REFERRAL, "ignore");
    properties.put(Context.SECURITY_PRINCIPAL, dirManagerUser);
    properties.put(Context.SECURITY_CREDENTIALS, password);

    DirContext ctx = new InitialDirContext(properties);

    //NEW CUSTOM OBJECT CREATION SHOULD GO HERE

    ctx.close();

1 个答案:

答案 0 :(得分:1)

我找到了解决方案:

BasicAttribute attribute = new BasicAttribute("objectClasses");
        attribute.add(parameters);
        attributes.put(attribute);
        context.modifyAttributes("cn=schema",DirContext.ADD_ATTRIBUTE, attributes);
        context.close();