gpt4 book ai didi

Java Netscape LDAP 删除一个属性

转载 作者:行者123 更新时间:2023-12-02 00:52:05 31 4
gpt4 key购买 nike

我有 LDAP 架构,用户在哪里。我需要删除一个名为“notify”的属性,其值是:电话号码或邮件,或者删除用户的属性。我找到了方法

LDAPConnection myCon = new LDAPConnection("localhost",389);
myCon.delete("uid=test1, ou=People, o=domain.com, o=isp");

但这会删除整个用户,我只需要删除该用户的一个属性“notifyTo”。我需要删除整个属性,而不仅仅是其值。

谢谢回复

最佳答案

您需要调用modify method on LDAPConnection class :-)

来自 javadoc:

public void modify(java.lang.String DN, LDAPModification mod) throws LDAPException Makes a single change to an existing entry in the directory (for example, changes the value of an attribute, adds a new attribute value, or removes an existing attribute value). Use the LDAPModification object to specify the change to make and the LDAPAttribute object to specify the attribute value to change. The LDAPModification object allows you add an attribute value, change an attibute value, or remove an attribute value.

For example, the following section of code changes Barbara Jensen's email address in the directory to babs@aceindustry.com.

来自 javadocs 的示例代码:

String myEntryDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US";
LDAPAttribute attrEmail = new LDAPAttribute( "mail", "babs@aceindustry.com" );
LDAPModification singleChange = new LDAPModification( LDAPModification.REPLACE, attrEmail );

myConn.modify( myEntryDN, singleChange );

此示例用于删除条目属性之一的一个值。您需要删除所有值:-)

关于Java Netscape LDAP 删除一个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2585639/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com