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

我在使用 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;

    }


}

带有方法的存储库:


@Service

public 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();

    }

请帮我用这个方法。如何更新该密码?


三国纷争
浏览 180回答 1
1回答

qq_遁去的一_1

我认为这是 userPassword 属性
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java