簡體   English   中英

如何在 Spring 中重置 LDAP 密碼(忘記密碼)

[英]How to reset an LDAP password in Spring (Forgotten password)

在 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 安全 ldap 4.2.3.RELEASE ,我沒有看到任何方法來重置我擁有username的用戶的密碼。

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

解決方案在這篇文章中: 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);

I prefered this method since the version I am using of spring security ldap is not using the password overlay to change the password, for more consistency with it, otherwise, if you are using a more recent version of spring security ldap, prefer the second way做它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM