我在使用 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(); }請幫我用這個方法。如何更新該密碼?
添加回答
舉報
0/150
提交
取消