首页 文章

应用程序用户对用户的LDAP身份验证

提问于
浏览
0

我是LDAP身份验证的新手 . 我想用LDAP凭据验证用户身份 . 为此,我从服务器获得了应用程序凭据,以便我可以对其他用户进行身份验证 .

我的凭证作为应用程序用户如下:

Test LDAP Server IP: xx.xx.xx.xx
Port: 389
Bind DN:uid=uidxx,ou=applications,dc=dcxx
password: passxx

为了验证这个用户,我编写了代码

public String ldap()
{
        String value=null;
        SearchControls constraints= new SearchControls();
        Hashtable<String, String> env= new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL,"ldap://xx.xx.xx.xx:389");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL,"uid=uidxx, ou=applications, dc=dcxx");
        env.put(Context.SECURITY_CREDENTIALS,"passxx");

        try {
            DirContext ctx = new InitialDirContext(env);
            value = "Done with it";

        } 
        catch(AuthenticationException e)
        {
            value = "Invalid User name or password";
        }
        catch (NamingException e) {
            e.printStackTrace();
            value = "Exception occurred";

        }

        return value;
    }

我的返回值为 "Done with it"

现在我想验证其他用户的邮件ID和密码是我所知道的 . 它就像我想要使用他们的mailid,密码验证其他用户,为此我得到了uidxx和passxx来验证它们 . 我该怎么做?

没有得到其他来源的帮助 .

谢谢

1 回答

  • 0

    对LDAP进行身份验证时常见的工作流程是

    • 使用您拥有的凭据绑定到LDAP . 此用户必须至少具有对用户的子树的只读访问权限 . 通常是ou = People,ou = Domain,dc = com或类似 .

    • 查询用户DN的LDAP服务器(这里是ANR可能有用的地方)

    • 尝试使用提供给应用程序的用户DN和密码绑定到LDAP

    这是有效的,因为在每个用户对数据库中的对象赋予RW权限是很常见的 . 如果您希望用户能够更改自己的密码,这非常有用 .

相关问题