LDAP:错误代码 65 - 对象 class 'inetOrgPerson' 需要属性 'sn'

LDAP: error code 65 - object class 'inetOrgPerson' requires attribute 'sn'

我在 Spring application.While 中使用 LdapTemplate 添加记录时出现错误 LDAP: error code 65 - object class 'inetOrgPerson' requires attribute 'sn'

我的存储库代码是

@Autowired
    private LdapTemplate ldapTemplate;

    @Autowired
    private PasswordEncoder passwordEncoder;

    public void setLdapTemplate(LdapTemplate ldapTemplate) {
        this.ldapTemplate = ldapTemplate;
    }

    public void create(User user) {
        Name dn = buildDn(user);
        DirContextAdapter context = new DirContextAdapter(dn);
        mapToContext(user, context);
        ldapTemplate.bind(dn, context, null);
    }

    private LdapName buildDn(User user) {
        return LdapNameBuilder
                .newInstance()
                .add("cn", user.getName())
                .add("sn", user.getLname())
                .add("uid", user.getUid())
                .add("userPassword", passwordEncoder.encode(user.getPassword()))
                .build();

    }

    private void mapToContext(User user, DirContextAdapter context) {
        context.setAttributeValues("objectclass", new String[] { "top", "inetOrgPerson" });
        context.setAttributeValue("uid", user.getName());
        context.setAttributeValue("userPassword",
                passwordEncoder.encode(user.getPassword()));

    }
}

我也将 inetOrgPerson 更改为 person,organizationalPerson 但它不起作用。

在哪里我可以从我的终端添加 ldif 文件

dn: ou=roles,dc=cofinding,dc=com
objectclass: top
objectclass: organizationalUnit
ou: roles

dn: ou=people,dc=cofinding,dc=com
objectclass: top
objectclass: organizationalUnit
ou: people


# Users

dn: uid=admin1,ou=people,dc=cofinding,dc=com
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Prashant
sn:Thorat
uid: admin1
userPassword: admin1Pass

dn: uid=admin2,ou=people,dc=cofinding,dc=com
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Aniket
sn:Patil
uid: admin2
userPassword: admin2Pass

dn: uid=user1,ou=people,dc=cofinding,dc=com
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Gautam
sn:Kanawade
uid: user1
userPassword: user1Pass


# Roles

dn: cn=USER,ou=roles,dc=cofinding,dc=com
objectclass: top
objectclass: groupOfNames
cn: USER
member: uid=admin1,ou=people,dc=cofinding,dc=com
member: uid=admin2,ou=people,dc=cofinding,dc=com
member: uid=user2,ou=people,dc=cofinding,dc=com

dn: cn=ADMIN,ou=roles,dc=cofinding,dc=com
objectclass: top
objectclass: groupOfNames
cn: ADMIN
member: uid=admin1,ou=people,dc=cofinding,dc=com
member: uid=admin2,ou=people,dc=cofinding,dc=com
private LdapName buildDn(User user) {
        return LdapNameBuilder
                .newInstance()
                .add("cn", user.getName())
                .add("sn", user.getLname())
                .add("uid", user.getUid())
                .add("userPassword", passwordEncoder.encode(user.getPassword()))
                .build();

    }

    private void mapToContext(User user, DirContextAdapter context) {
        context.setAttributeValues("objectclass", new String[] { "top", "inetOrgPerson" });
        context.setAttributeValue("uid", user.getName());
        context.setAttributeValue("userPassword",
                passwordEncoder.encode(user.getPassword()));

    }

尝试用下面的代码替换此代码

private LdapName buildDn(User user) {
            return LdapNameBuilder
                    .newInstance()
                    .add("ou", "people")
                    .add("uid", user.getUid())
                                  .build();
        }



   private void mapToContext(User user, DirContextAdapter context) {
                    context.setAttributeValues("objectclass", new String[] { "top", "inetOrgPerson" });
                    context.setAttributeValue("uid", user.getName());
        context.setAttributeValue("cn", user.getName());
        context.setAttributeValue("sn", user.getLname());
                    context.setAttributeValue("userPassword",
                            passwordEncoder.encode(user.getPassword()));

                }