无法从Java获得与AD的连接
我正在尝试从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
对于搜索,我使用以下filter:
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:
Exception in thread "main" javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 531, vece
如果未指定密码,则会出现以下exception:
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'
我已经确认我的帐户没有锁定。
根据常见的Active Directory LDAP绑定错误列表 :
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
在我的情况下,它意味着:“不允许在此工作站登录”,但使用相同的凭据我可以登录到域。
可能是什么原因?
我非常感谢这些信息。 谢谢大家。
错误代码531很可能与AD的配置有关。 在某些情况下,用户只能从一个工作站登录,例如您的工作电脑。
这是在用户的userWorkstations字段中配置的。
如果您无法使用RDP登录AD,则需要您的AD管理员检查您的帐户以查找此字段,并且AD服务器包含在您的userWorkstations中,否则该字段将被完全删除。
我的项目使用ldap auth。 我把你的来源与我的impl进行了比较。 除SECURITY_PRINCIPAL参数外,其他相同。
这个对我有用:
String login = "login"; String base = "ou=People,dc=example,dc=com"; String dn = "uid=" + login + "," + base; env.put( Context.SECURITY_PRINCIPAL, dn );
错误数据531,意味着您无法从该工作站登录。 错误数据525意味着该条目不存在。
您可以通过发出以下命令从DC确定用户的FDN:{dsquery user -samid jim
“CN = Jim Willeke,CN = Users,DC = mad,DC = willeke,DC = com”}
我们有一些与AD配合使用的JNDI示例 (假设您知道正确的参数)
您可能会发现使用LDAP浏览器并使用它进行身份validation更容易,然后您就知道哪些参数可以正常工作。 我们喜欢Apache Studio 。
- 如何使用Spring Security对Active Directory服务器进行身份validation?
- Java SimpleDateFormat总是返回1月份的月份
- 用户解锁后,Windows机器上的Kerberos缓存票证无法重新生成
- 每次从Ldap连接池返回新连接时
- 具有错误的Active Directory Ldap凭据的会话/ Redis序列化错误的Spring启动
- 我可以从LDAP更改自己的Active Directory密码(没有管理帐户)
- 密码的SPNEGO身份validation问题
- 在尝试使用unboundid LDAP SDK更改scala中的密码时,如何解决“WILL_NOT_PERFORM”MS AD回复?
- 检测使用Java登录计算机的用户