为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 Spring Ldap 模板更新密码?

如何使用 Spring Ldap 模板更新密码?

三国纷争 2023-03-23 15:05:04
我在使用 Spring LDAP 模板更改密码时遇到问题。我不使用 Spring 安全性。我通过示例创建了应用程序,并尝试编写一个更改用户密码的新方法。我们吃:@Data@AllArgsConstructor@NoArgsConstructor@ToString(exclude = "uid")public class Person {    private String uid;    private String fullName;    private String lastName;    private String password;    public Person(String uid, String fullName, String lastName) {        super();        this.fullName = fullName;       this.lastName = lastName;    }}带有方法的存储库:@Servicepublic class PersonRepository implements BaseLdapNameAware {    @Autowired    private LdapTemplate ldapTemplate;    private LdapName baseLdapPath;    public void setBaseLdapPath(LdapName baseLdapPath) {        this.baseLdapPath = baseLdapPath;    }    public Person findOne(String uid) {        Name dn = LdapNameBuilder.newInstance(baseLdapPath).add("ou", "people").add("uid", uid).build();        return ldapTemplate.lookup(dn, new PersonContextMapper());    }    public List<Person> findByName(String name) {        LdapQuery q = query().where("objectclass").is("person").and("cn").whitespaceWildcardsLike(name);        return ldapTemplate.search(q, new PersonContextMapper());    }    public void update(Person p) {        ldapTemplate.rebind(buildDn(p), null, buildAttributes(p));    }    public void updateLastName(Person p) {        Attribute attr = new BasicAttribute("sn", p.getLastName());        ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr);        ldapTemplate.modifyAttributes(buildDn(p), new ModificationItem[] { item });    }    public void updatePassword(Person p) {        Attribute attr = new BasicAttribute("password", p.getPassword());        ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr);        ldapTemplate.modifyAttributes(buildDn(p), new ModificationItem[] { item });    }    private Name buildDn(Person p) {        return LdapNameBuilder.newInstance(baseLdapPath).add("ou", "people").add("uid", p.getUid()).build();    }请帮我用这个方法。如何更新该密码?
查看完整描述

1 回答

?
qq_遁去的一_1

TA贡献1725条经验 获得超7个赞

我认为这是 userPassword 属性



查看完整回答
反对 回复 2023-03-23
  • 1 回答
  • 0 关注
  • 153 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信