2

我正在尝试使用受信任的 ID 和另一个域 (B.lmig.com) 在 Java 中的一个域 (A.domain.com) 中搜索 Active Directory 组的成员。我知道信任配置正确,因为我可以连接 id 并通过 ldp 和 ADUC 成功执行搜索。但是使用以下代码:

Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://A.domain.com:389/");
env.put(Context.SECURITY_AUTHENTICATION, "simple");

env.put(Context.SECURITY_PRINCIPAL, "id@B.domain.com");
env.put(Context.SECURITY_CREDENTIALS, "*******");

env.put(Context.REFERRAL, "follow");
InitialLdapContext ctx = new InitialLdapContext(env, null);

String base = "DC=A,DC=domain,DC=com";

String filter = "(memberof=CN=grouptest,OU=someplace,OU=somewhere,OU=thegroups,DC=A,DC=domain,DC=com)";

SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);

NamingEnumeration<SearchResult> answer = ctx.search(base, filter, controls);

导致以下异常,这似乎表明用户 id 不存在。

Exception in thread "main" javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 525, vece

我的问题是是否有某个设置或我缺少的东西会告诉 Java 该 ID 位于“B.domain.com”域中,并且应该通过该域进行身份验证,同时在“A. domain.com”域名?因为我可以通过 LDP 和 ADUC 进行搜索,所以我必须缺少配置或引用错误的域或其他东西。

4

1 回答 1

0

LDAP 错误代码 49 是无效凭据。数据525表示没有这样的用户。

根据我的经验,security_principal通常是专有名称 (DN),而不是电子邮件地址。

在我们的系统中,我们在 AD 中搜索电子邮件(sAMAccountName=id@b.domain.com)以获取DN. 然后DN用于security_principal

于 2012-08-02T18:26:31.827 回答