java - 我们可以使用 Java 在 openLDAP 中为域组件条目创建子上下文吗?

标签 java openldap

我正在尝试为域组件创建子上下文, 但它显示以下错误

javax.naming.OperationNotSupportedException:[LDAP:错误代码 53 - 没有全局高级知识];剩余名称 'uid=user3, dc=example'

这是我的代码

公共(public)类 OpenLDAPTest {

public static void main(String[] args) {
    String url = "ldap://localhost:389";
    // String url = "ldap://localhost:10389";
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "cn=Manager,dc=maxcrc,dc=com");
    // env.put(Context.SECURITY_PRINCIPAL, "uid=admin, ou=system");
    env.put(Context.SECURITY_CREDENTIALS, "secret");
    try {
        DirContext ctx = new InitialDirContext(env);
        System.out.println("connected");
        System.out.println(ctx.getEnvironment());
        System.out.println("Creating subContext");
        String name = "uid=user3, dc=example";
        Attributes atrs = new BasicAttributes();
        Attribute atr1 = new BasicAttribute("objectClass");
        atr1.add("inetOrgPerson");
        atrs.put(atr1);
        Attribute atr2 = new BasicAttribute("cn");
        atr2.add("sathish");
        atrs.put(atr2);
        Attribute atr3 = new BasicAttribute("o");
        atr3.add("Kumar");
        atrs.put(atr3);
        Attribute atr4 = new BasicAttribute("sn");
        atr4.add("example");
        atrs.put(atr4);
        Context c = ctx.createSubcontext(name, atrs);
        System.out.println(c.getEnvironment());
        ctx.close();

    } catch (AuthenticationNotSupportedException ex) {
        System.out
                .println("The authentication is not supported by the server");
    } catch (AuthenticationException ex) {
        System.out.println("incorrect password or username");
    } catch (NamingException ex) {
        // System.out.println("error when trying to create the context");
        ex.printStackTrace();
    }
}

}

如果我对 ApacheDS 使用相同的代码(通过更改凭据)它的工作。但它不适用于 openLDAP。

最佳答案

您可以尝试安装时将域名设置为“dc=example”

在LDAP后端设置步骤中,

ldap setting
(来源:userbooster.de)

否则您可以将“uid=user3, dc=example”更改为“uid=user3,dc=maxcrc,dc=com”来添加它。

当 Windows 服务器中已经存在根目录为“dc=maxrc,dc=com”的数据库时,不必费心添加根目录为“dc=example”的数据库。

更新:

虽然您将域名设置为“dc=maxcrc,dc=com”,但默认情况下不会添加相应的域名根条目。

在添加该子上下文之前,您需要添加“dc=maxcrc,dc=com”

    String name = "dc=maxcrc,dc=com";
    Attributes atrs = new BasicAttributes();
    Attribute atr1 = new BasicAttribute("objectClass");
    atr1.add("organization");
    atrs.put(atr1);
    Attribute atr2 = new BasicAttribute("objectClass");
    atr2.add("dcObject");
    atrs.put(atr2);
    Attribute atr3 = new BasicAttribute("dc");
    atr3.add("maxcrm");
    atrs.put(atr3);
    Attribute atr4 = new BasicAttribute("o");
    atr4.add("anyOrgYouLike");
    atrs.put(atr4);
    Context c = ctx.createSubcontext(name, atrs);

关于java - 我们可以使用 Java 在 openLDAP 中为域组件条目创建子上下文吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37160842/

相关文章:

LDAPSEARCH 转换成表格格式

ldap - 如何在 LDAP3 中创建一个新的对象类?

java - jetty LdapLoginModule : Login Failure: all modules ignored

java - gradle 进程命令 java 已完成,退出值非零 1

java - 线性布局环绕 TextView

java - 将 SSL 证书加载到容器的 JVM

linux - 连接 kerio 和 openldap

java - 两个矩阵相加的简单java程序中发生NoSuchElementException?

java - 如何使用 Java 流从一组对象中提取不同整数的排序列表?

active-directory - 从命令行使用 ldapsearch 查询 Windows Active Directory 服务器