如何修复未在条目的对象类中声明的属性 sn

How to fix Attribute sn not declared in objectClasses of entry

我正在尝试使用 Spring-Data-LDAP 创建一个条目,当我尝试保存条目时,它会给我属性 sn not declared in objectClasses of entry ou=用户,dc=示例,dc=com 。我是 LDAP 新手。

我创建了一个包含基本属性的模型 class,并且我有自动连接的 LdapRepository。

问题是我能够从 Apache DS ldap 检索条目,但无法使用我的模型保存条目。

下面是模型class。


@Entry(
          base = "ou=users", 
          objectClasses = { "inetOrgPerson","organizationalPerson","person", "top" })
public class User {

    private static final String BASE_DN = "dc=example,dc=com";

    @JsonIgnore
    @Id
    private Name id;
    @JsonProperty("userName")

    private @Attribute(name="uid")  String uid;
    @JsonProperty("firstName")
    private @Attribute(name = "cn") String firstName;
    @JsonIgnore
    private @Attribute(name = "displayname") String displayName;
    @JsonProperty("lastName")

    private  @Attribute(name = "sn") String lastName;

    public User() {

    }

    public User(String uid, String firstName, String displayName, String lastName) {
        this.uid = uid;
        this.firstName = firstName;
        this.displayName = displayName;
        this.lastName = lastName;
    }
    public User(String userName, String firstName, String lastName) {       
         Name dn = LdapNameBuilder.newInstance()
                 .add("ou", "users")                 
                 .build();
        this.id = dn;       
        this.uid = userName;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    // Setter and Getter
}

下面是ldif文件,

dn: dc=example,dc=com
objectclass: top
objectclass: domain
dc: example

dn: ou=users,dc=example,dc=com
objectClass: organizationalUnit
objectClass: top
ou: users

错误日志如下

There was an unexpected error (type=Internal Server Error, status=500).
[LDAP: error code 65 - OBJECT_CLASS_VIOLATION: failed for MessageType : MODIFY_REQUEST Message ID : 2 Modify Request Object : 'ou=users,dc=example,dc=com' Modification[0] Operation : add Modification uid: abc Modification[1] Operation : add Modification cn: Abc Modification[2] Operation : add Modification sn: Xyzsorg.apache.directory.api.ldap.model.message.ModifyRequestImpl@1b7e931e ManageDsaITImpl Control Type OID : '2.16.840.1.113730.3.4.2' Criticality : 'false' ' : ERR_277 Attribute sn not declared in objectClasses of entry ou=users,dc=example,dc=com]

提前致谢

不确定代码,但您似乎正在为该行中的用户构建 DN:

Name dn = LdapNameBuilder.newInstance()
                 .add("ou", "users")                 
                 .build();

其中不包含用户的 uid。

A​​ddRequest 必须是:

AddRequest ::= [APPLICATION 8] SEQUENCE 
{
    entry           LDAPDN,
    attributes      AttributeList 
} 

其中 LDAPDN 是条目的完全可分辨名称。