[英]Unable to store information as attributes in LDAP using JNDI
我正在嘗試根據此處給出的教程將Java對象綁定為一組屬性
//In the main() method of the program
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:10389/o=csRepository");
env.put(Context.OBJECT_FACTORIES, "sample.UserFactory");
// Create the initial context
DirContext ctx = new InitialDirContext(env);
User usr = new User("Goro");
ctx.bind("cn=Kill Bill, ou=employees", null, usr.getAttributes(""));
我有如下的User類,
public class User implements DirContext {
String employer;
Attributes myAttrs;
public User(String employer){
this.employer = employer;
myAttrs = new BasicAttributes(true);
Attribute oc = new BasicAttribute("objectclass");
oc.add("extensibleObject");
oc.add("top");
myAttrs.put(oc);
myAttrs.put("em", employer);
}
public Attributes getAttributes(String name) throws NamingException {
if (!name.equals("")) {
throw new NameNotFoundException();
}
return (Attributes) myAttrs.clone();
}
//other methods
}
當我嘗試綁定時,
javax.naming.directory.NoSuchAttributeException: [LDAP: error code 16
- NO_SUCH_ATTRIBUTE: failed for MessageType : ADD_REQUEST Message ID : 2
Add Request : Entry
dn[n]: cn=Kill Bill, ou=employees,o=csRepository
objectclass: extensibleObject
objectclass: top
cn: Kill Bill
em: Goro
ManageDsaITImpl Control
Type OID : '2.16.840.1.113730.3.4.2'
Criticality : 'false' ' : ERR_04269 ATTRIBUTE_TYPE for OID em does not exist!]; remaining name 'cn=Kill Bill, ou=employees'
為什么抱怨OID em不存在。
因為不是。 使用extensibleObject
有權將任何現有屬性添加到對象。 它沒有賦予您創造新屬性的權利。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.