我有以下问题:
我的桌面计算机上运行着一个富客户端 (Java),它与服务器进行通信。当您启动富客户端时,它会提示您输入用户名和密码。富客户端会将其发送到服务器,服务器会说“是,允许访问”或“不允许访问”。
现在我们希望提供更多一点的用户体验:当用户登录 Windows 并启动富客户端时,富客户端应自动检查当前用户并询问 LDAP(Active Directory)是否允许该用户。
我对 LDAP 完全陌生,但到目前为止我已经了解了以下内容:
我可以通过以下方式获取当前用户:
userName = new com.sun.security.auth.module.NTSystem().getName();
我可以使用 Waffle 获取它的域名,如下所示:
WindowsAuthProviderImpl auth = new WindowsAuthProviderImpl();
for(IWindowsDomain domain : auth.getDomains())
userDomain = domain.getFqn();
现在我可以使用一些已知的 LDAP 帐户来查找该特定用户:
Hashtable<String, String> props = new Hashtable<String, String>();
props.put(Context.SECURITY_PRINCIPAL, "admin");
props.put(Context.SECURITY_CREDENTIALS, "123");
DirContext context = LdapCtxFactory.getLdapCtxInstance("ldap://host:12345/", props);
String filter = "(& (userPrincipalName=" + userName + "@" + userDomain + ")(objectClass=user))";
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
context.search(dc, filter, controls);
最后,我得到了我想要的用户信息。但是:
- 保存了吗?或者有人可以轻易伪造它的用户名和域名吗?
- 我想摆脱“admin”用户来连接到 LDAP 服务器。我想获取当前用户并尝试与其连接。但如何呢?要连接到 LDAP 服务器,我需要密码,而 Windows 当然不会给我密码。
那么,如何根据 LDAP 验证/检查 Windows 中当前登录的用户?
到目前为止我所做的事情看起来很复杂并且感觉不对。我想我没明白重点...
编辑:
我知道我还可以从 Waffle 获取当前用户的组,如下所示:
WindowsAuthProviderImpl auth = new WindowsAuthProviderImpl();
IWindowsIdentity identity = auth.logonUser(user, pwd);
for(IWindowsAccount group : identity.getGroups())
group.getFqn();
但是,尽管我已经登录 Windows,但我仍然需要密码...
最佳答案
AFIK,没有办法从 Microsoft Active Directory 获取密码。
您没有说明为什么需要用户的密码,但您也许可以使用 Kerberos 票证。
-吉姆
关于java - 根据 LDAP 验证 Windows 用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17614355/