简体   繁体   English

如何为ldap用户添加自定义属性?

[英]How to add an self defined attribute to ldap user?

I have created an attribute in LDAP using the following code. 我已使用以下代码在LDAP中创建了一个属性。

attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.1.9");
            attrs.put("NAME", "myattribute");
            attrs.put("DESC", "for JNDITutorial example only");
            attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.15");
            DirContext schema = context.getSchema("");
           DirContext newAttr = schema.createSubcontext  ("AttributeDefinition/myattribute1", attrs);   

The attribute is created successfully, Now I am trying to add this attribute to a user say "user1"(uid). 该属性已成功创建,现在我试图将此属性添加到用户说的“ user1”(uid)。

Attributes attributeslist = context.getAttributes(ld.getUserDN(username));
            attributeslist.put("myattribute1", "");
            context.modifyAttributes(ld.getUserDN("test5"), DirContext.REPLACE_ATTRIBUTE, attributeslist);

But it gives me object class violation error. 但这给了我对象类违反错误。

Can anyone help me to solve this? 谁能帮我解决这个问题? I need to add an user defined attribut to the user using java code. 我需要使用Java代码向用户添加用户定义的属性。

You create the attribute, then you choose a class to which it should belong, and update the class. 创建属性,然后选择它应属于的类,然后更新该类。

You could modify a base class (comes with the LDAP servers base schema), an effective class (a class of object that can exist on its own, like inetOrgPerson), or an auxiliary class (cannot make an object of this type by itself, but it extends another object class). 您可以修改基类(LDAP服务器基模式附带),有效类(可以自己存在的对象类,例如inetOrgPerson)或辅助类(不能单独创建这种类型的对象,但它扩展了另一个对象类)。

So define an aux class to 'hold' your new attribute, then add an entry to the Object Class of your target object, with the name of your class, and then you can add the attribute to the user. 因此,定义一个aux类以“保留”您的新属性,然后向您的目标对象的Object Class添加一个条目,并带有您的类的名称,然后您可以将该属性添加到用户。

We do this all the time. 我们一直在这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将自定义的 MouseMotionListener 添加到 JPanel? - How to add a self-defined MouseMotionListener to a JPanel? 如何将ActionListener添加到自定义对象 - How to add an ActionListener to a self defined object 如何在Ldap中将用户帐户控制属性固定为512 - How to fix the user account control attribute to 512 in Ldap 如何使用Apache LDAP API添加新的密码属性 - How to add new password Attribute with Apache LDAP API 如何以编程方式在原型(Google协议缓冲区)中添加用户定义的类型属性 - how to add user defined type attribute in proto(Google Protocol Buffer) programatically 如何添加到定义为属性的速度图? - How to add to a velocity map which is defined as an attribute? 具有自定义属性的Java LDAP用户创建 - Java LDAP user creation with custom attribute 如何将用户定义的对象添加到LinkedList? - How to add user defined objects to LinkedList? 如何在Eclipse默认中添加用户定义的功能? - how to add user defined function in eclipse default? LDAP searchFilter samAccountName来自用户输入定义的变量? Java JNDI。 有人知道怎么做吗? - LDAP searchFilter samAccountName from variable defined by user input ? java JNDI. DOes anybody know how to do it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM