1

我有以下问题:

我的台式计算机上运行着一个富客户端 (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);

最后,我得到了我想要的用户的信息。但:

  1. 是保存吗?或者有人可以轻松伪造它的用户名和域名吗?
  2. 我想摆脱“管理员”用户来连接到 LDAP 服务器。我想获取当前用户并尝试与它建立联系。但是怎么做?要连接到 LDAP 服务器,我需要一个密码,而 Windows 将 - 当然 - 不会给我密码。

那么,如何根据 LDAP 验证/检查 Windows 中的当前登录用户?

到目前为止,我所做的似乎很复杂并且感觉不对。我想我没明白重点...

编辑:

我知道我也可以像这样从 Waffle 获取当前用户的组:

WindowsAuthProviderImpl auth = new WindowsAuthProviderImpl();
IWindowsIdentity identity = auth.logonUser(user, pwd);
for(IWindowsAccount group : identity.getGroups())
    group.getFqn();

但是,尽管我已经在 Windows 上登录,但我再次需要密码...

4

1 回答 1

1

AFIK,没有从 Microsoft Active Directory 获取密码的方法。

您没有说明为什么需要用户密码,但您也许可以使用 Kerberos Ticket。

-吉姆

于 2013-07-13T10:54:00.213 回答