Spring LdapTemplate - 属性'gidNumber'不允许异常

时间:2012-12-13 08:21:59

标签: spring ldap jndi spring-ldap

我正在尝试使用Spring LDAPTemplate控制OpenLDAP。

在LDAP中,我有组和用户组织单位。我正在尝试使用组关联将新用户绑定到LDAP。 (通用用户帐户)因此,当我尝试绑定新用户时,我还将gidNumber attiribute放入属性对象中。但我收到这样的错误:

[LDAP: error code 65 - attribute 'gidNumber' not allowed]; nested exception is javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - attribute 'gidNumber' not allowed]; remaining name 'ou=staff'

这是我到目前为止所尝试的内容:

DistinguishedName dn = new DistinguishedName();
dn.add("ou", "staff");
Attributes attributes = new BasicAttributes();
attributes.put("objectClass", "inetOrgPerson");
attributes.put("uid", username);
attributes.put("givenName", name);
attributes.put("gidNumber", gidNumber.toString());
attributes.put("sn", surname);
attributes.put("cn", name + " " + surname);
attributes.put("userPassword", password);
ldapTemplate.bind(dn, null, attributes);

这是我的架构:

+--> dc=ibu,dc=edu,dc=tr (5)
  ---> cn=admin
  +--> ou=group (1)
    | ---> cn=Academic
  ---> ou=guest
  +--> ou=staff (2)
    | ---> cn=John Clark
  ---> ou=student

2 个答案:

答案 0 :(得分:0)

您必须添加另一个名为posixAccount的对象类。因为属性gidNumber属于此类。因此,请尝试添加一个对象类,如下所示:

attributes.put("objectClass", "posixAccount");

答案 1 :(得分:0)

LDAP条目必须只有一个且只有一个结构对象类。但是,一些损坏的服务器确实允许多个结构对象类。添加结构对象类(要添加的对象类取决于使用该条目的目的)。

相关问题