【问题标题】:How to reset an LDAP password in Spring (Forgotten password)如何在 Spring 中重置 LDAP 密码(忘记密码)
【发布时间】:2020-08-26 13:16:51
【问题描述】:

在 Spring Boot 1.5.9 应用程序中,我重置了我的密码。使用令牌,我能够识别正在重置密码的用户。

这是我更新已连接用户密码的方式:

public void updatePassword(User entity) {
  if (null != entity.getOldPassword() && null != entity.getPassword()) {
    userDetailsService.changePassword(entity.getOldPassword(), encrypt(entity.getPassword()));
  }
}

我使用 LdapUserDetailsManager userDetailsService,来自 spring security ldap 4.2.3.RELEASE,我没有看到任何方法可以重置我拥有 username 的用户的密码。

如何使用username(或ldap 中的uid)重置密码?

【问题讨论】:

  • 那是因为 LDAP 是获取凭据的主要方式,要更改它们,您通常需要使用特定于每个供应商的额外 API。例如:stackoverflow.com/questions/15335614/…
  • 我已经尝试过那个例子,但那不是针对 ldap,这是针对活动目录的。我还没有找到更新现有密码的解决方案,这个例子对我没有帮助。
  • LDAP 是规范,Microsoft Active Directory 是实现之一。您使用哪个 LDAP 服务器?
  • 打开 LDAP。我已阅读此内容:tech.wrighting.org/2013/06/06/…,我现在正在尝试。

标签: java spring ldap spring-ldap spring-security-ldap


【解决方案1】:

解决方案在这篇文章中:https://tech.wrighting.org/2013/06/06/using-the-ldap-password-modify-extended-operation-with-spring-ldap/

我就是这样做的:

    DistinguishedName dn = new DistinguishedName(dn_string);
    Attribute passwordAttribute = new BasicAttribute(passwordAttr,
            newPassword);
    ModificationItem[] modificationItems = new ModificationItem[1];
    modificationItems[0] = new ModificationItem(
            DirContext.REPLACE_ATTRIBUTE, passwordAttribute);
/*
    Attribute userPasswordChangedAttribute = new BasicAttribute(
            LDAP_PASSWORD_CHANGE_DATE, format.format(convertToUtc(null)
                    .getTime()) + "Z");
    ModificationItem newPasswordChanged = new ModificationItem(
            DirContext.REPLACE_ATTRIBUTE, userPasswordChangedAttribute);
    modificationItems[1] = newPasswordChanged;
    */
    getLdapTemplate().modifyAttributes(dn, modificationItems);

我更喜欢这种方法,因为我使用的 spring security ldap 版本没有使用密码覆盖来更改密码,为了与它更加一致,否则,如果您使用的是更新版本的 spring security ldap,更喜欢第二种方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-12
    • 2018-11-05
    • 1970-01-01
    • 2021-07-30
    • 2014-08-20
    • 2018-07-07
    相关资源
    最近更新 更多