根据LDAP验证Windows用户

时间:2013-07-12 11:53:33

标签: java ldap single-sign-on

我有以下问题:

我的桌面计算机上运行了一个富客户端(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. 我想摆脱“admin”用户连接到LDAP服务器。我想接受当前用户并尝试连接它。但是怎么样?要连接到LDAP服务器,我需要一个密码,Windows当然 - 不会给我。
  3. 那么,如何在Windows中针对LDAP验证/检查当前登录的用户?

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

    修改

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

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

    但是,我需要再次输入密码,虽然我已登录Windows ...

1 个答案:

答案 0 :(得分:1)

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

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

-Jim

相关问题