java - 使用 Apache LDAP API 从 Activedirector 检索当前密码

标签 java active-directory

我有一个用例,我想重置用户的密码。在我重置密码之前,我希望他们在 Active Directory 中检查密码,并且只有当前密码正确时,他们才应该能够更改密码。

我需要知道如何使用 Apache LDAP Api 从 Active Directory 检索用户的当前密码。

 entryCursor = connection.search(searchRequest);
            if(null!=entryCursor){
                Entry user = entryCursor.getEntry();
                Iterator<Attribute> attr = user.getAttributes().iterator();
                while(attr.hasNext()){
// I assumed that unicodePwd would be part of attribute set, but looks like it is not.
                    Attribute currentAttribute = (Attribute) attr.next();
                    currentAttribute.getAttributeType();
                }
        }

最佳答案

你在这里问了错误的问题。您无法获取密码,因为它是经过哈希处理的,并且您不需要它。您只需要尝试使用该用户声称的当前密码进行绑定(bind)。如果成功,则说明是正确的,您可以继续更改它。如果失败了,那就不是了。

比较密码总是错误的。让系统来做工作。另一个例子,这次是 SQL:

select password from users where username = ?

后面是密码比较,应该是:

select count(*) as count from users where username = ? and password = ?

并检查count == 1

这样做的另一个优点是,如果失败,您甚至可以向自己隐瞒用户名或密码是否错误。这是一条重要的信息隐私原则:您不会告诉攻击者他已经找到了有效的用户名,现在只需猜测密码即可。

关于java - 使用 Apache LDAP API 从 Activedirector 检索当前密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25275794/

相关文章:

java - 密码重置使用 UnboundID 执行目录策略

java - RabbitMQ:快速生产者和慢消费者

java.util.MissingResourceException : Couldn't find 3-letter country code for CS

java - 试图在数据库中找到一个实体

c# - 如何通过 ASP.NET Web API 使用 Active Directory 身份验证?

PHP LDAPS 连接到 AD

java - 如何在 Guava Optional 中保存空值

java - 重复类 : MainActivity

asp.net - System.DirectoryServices - 服务器无法运行

asp.net - 面对双跃点,我们应该使用 Exchange 模拟还是 Kerberos 委派