gpt4 book ai didi

java - 如何使用非管理员用户登录apacheds

转载 作者:行者123 更新时间:2023-11-30 09:18:03 24 4
gpt4 key购买 nike

我正在尝试通过 Java 以用户身份登录到 ApacheDS。

这是我在 ldif 中导出的用户详细信息:

dn: uid=carlspring,ou=users,ou=system
objectClass: top
objectClass: inetOrgPerson
objectClass: person
objectClass: organizationalPerson
cn: Martin Todorov
sn: Todorov
uid: carlspring
userPassword:: e1NTSEF9bC9LRk45RllHdW5aVGdLcUtScmNTYk80RXRLMmJvbTEvM2NOYnc9PQ==

这是我的代码:

    // Set up environment for creating initial context
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:10389/ou=users,ou=system");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "uid=carlspring,ou=users,ou=system");
env.put(Context.SECURITY_CREDENTIALS, "password");

try
{
// Create initial context
DirContext ctx = new InitialDirContext(env);

System.out.println(ctx.lookup("ou=users"));
System.out.println("Logged in.");

// do something useful with ctx

// Close the context when we're done
ctx.close();
}
catch (NamingException e)
{
e.printStackTrace();
}

我收到以下异常:

javax.naming.NameNotFoundException: [LDAP: error code 32 - NO_SUCH_OBJECT: failed for MessageType : SEARCH_REQUEST
Message ID : 2
SearchRequest
baseDn : 'ou=users,ou=users,ou=system'
filter : '(objectClass=*)'
scope : base object
typesOnly : false
Size Limit : no limit
Time Limit : no limit
Deref Aliases : deref Always
attributes :
org.apache.directory.api.ldap.model.message.SearchRequestImpl@c7594470 ManageDsaITImpl Control
Type OID : '2.16.840.1.113730.3.4.2'
Criticality : 'false'
'
: ERR_648 Invalid search base ou=users,ou=users,ou=system]; remaining name 'ou=users'

据我了解,它似乎没有正确连接。我已经尝试通过 Apache Directory Studio(使用 uid=carlspring,ou=users,ou=system)登录并且工作正常。我也可以像这样使用管理员用户登录:

    env.put(Context.PROVIDER_URL, "ldap://localhost:10389/ou=system");
env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
env.put(Context.SECURITY_CREDENTIALS, "secret");

有人可以告诉我我做错了什么以及为什么它没有登录吗?我似乎无法弄清楚。非常感谢!

最佳答案

看起来您在 Provider_URL 中提供了一个基本 DN,它已经指定了目录树的“ou=users”分支。尝试将其更改为:

ldap://localhost:10389/ou=系统

关于java - 如何使用非管理员用户登录apacheds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18690205/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com