LdapRepository update spring-ldap

泄露秘密 提交于 2019-12-25 03:02:18

问题


Spring LdapRepository save() method throws exception when I'm trying to update an existing object in LDAP database.

org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException: ERR_250_ENTRY_ALREADY_EXISTS

What method should I use to update existing ldap objects?

Person class:

@Entry(objectClasses = { "inetOrgPerson", "organizationalPerson", "person", "top" })
public class Person implements Serializable {

public Person() {
}

@Id
private Name dn;

@Attribute(name = "cn")
@DnAttribute(value = "cn")
@JsonProperty("cn")
private String fullName;

@Attribute(name = "uid")
private String uid;

private String mail;

@Attribute(name = "sn")
private String surname;
//setters and getters
}

Person repo interface:

public interface PersonRepo extends LdapRepository<Person> {
}

That's how I'm updating person:

personRepo.save(person);

回答1:


Default implementation for Spring LDAP repositories is SimpleLdapRepository, that checks the property annotated with @Id to determine if the objects is new - and perform create, or old - and perform update.

I'm guessing that Person.dn is null when you're trying to perform update.

You also can take the control over this by implementing org.springframework.data.domain.Persistable and place your logic in the isNew() method.

See the implementation details.



来源:https://stackoverflow.com/questions/33288011/ldaprepository-update-spring-ldap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!