我正在尝试从 MS AD 检索一些信息:特定分支的成员、部门名称、职位等。
我使用了很多示例,包括Apache Directory LDAP API和UnboundID,但我无法获得与 AD 的连接。
RDN:
C:\Users\Aleksey> whoami /fqdn
CN=my common name here,
OU=my organization unit here,
OU=organization unit 2 here,
OU=organization unit 1 here,
OU=main organization unit here,
DC=.my domain here,
DC=domain 2 here,
DC=main domain here
对于搜索,我使用以下过滤器:
public class LdapRetriever {
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://" +
"ip of domain controller here" + ":389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
// Also I try to use the following SECURITY_PRINCIPAL:
// my login only, my domain\ my login
env.put(Context.SECURITY_PRINCIPAL, "my login here" + "@" +
"my domain here.domain 2 here.main domain here");
env.put(Context.SECURITY_CREDENTIALS, "my password here");
try {
DirContext ctx = new InitialLdapContext(env,null);
String returnedAtts[]={"sn","title","department","givenName"};
SearchControls searchCtls = new SearchControls();
searchCtls.setReturningAttributes(returnedAtts);
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String searchFilter = "(&(objectClass=user)(cn=*))";
String searchBase =
"DC=my domain here,DC=domain 2 here,DC=main domain here";
NamingEnumeration answer = ctx.search(searchBase,
searchFilter, searchCtls);
...
当我使用来自的数据创建目录上下文时,env
出现异常:
Exception in thread "main" javax.naming.AuthenticationException:
[LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment:
AcceptSecurityContext error, data 531, vece
如果未指定密码,则会出现以下异常:
Problem searching directory:
javax.naming.NamingException:[LDAP:error code 1 - 00000000:
LdapErr: DSID-0C090627, comment:
In order to perform this operation a successful bind must be completed
on the connection., data 0, vece]; remaining name
'DC=my domain here,DC=domain 2 here,DC=main domain here'
我已经确认我的帐户没有被锁定。
525 user not found 52e invalid credentials 530 not permitted to logon at this time 531 not permitted to logon at this workstation 532 password expired 533 account disabled 701 account expired 773 user must reset password 775 user account locked
就我而言,这意味着:“不允许在此工作站登录”,但使用相同的凭据我可以登录到域。
可能是什么原因?