簡體   English   中英

從Java修改LDAP屬性失敗,但使用ldapmodify命令成功

[英]Modify LDAP attribute fails from Java, but succeeds with ldapmodify command

我設法執行屬性的STARTTLS ldapmodify(-ZZ),但是無法使用javax.naming.ldap編碼執行相同的修改

服務器是OpenLDAP。 它具有用於修改的SSigned SSL證書,並且允許不安全的讀取。 古典組合。

我從嘗試在其上執行Java代碼的同一台服務器上運行以下命令:

ldapmodify -H ldap://my.ldap.server:389 -D "myldapadmin" -W -ZZ
Enter LDAP Password:
dn: CN=John Westood,OU=L100,DC=l,DC=woods
changetype: modify
replace: uPwd
uPwd:: 234WF34TG2U
modifying entry "CN=John Westood,OU=L100,DC=l,DC=woods" 

...如您所見,它要求我輸入myldapadmin的密碼,然后輸入密碼,然后進行修改。

這是我在Java中所做的事情,我想做同樣的修改,我在同一台服務器上運行它。 我首先將SSigned LDAP SSL證書導入到Java中。

Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://my.ldap.server:389");

// Create initial context
LdapContext ctx = new InitialLdapContext(env, null);

ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, "myldapadmin");
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, "myadminpass");

// Start TLS (STARTTLS is also used by the console command ldapmodify)
StartTlsResponse tls = (StartTlsResponse) ctx.extendedOperation(new 
StartTlsRequest());
SSLSession sess = tls.negotiate();

//Modification of 'uPwd' attribute
ModificationItem[] mods = new ModificationItem[1];
Attribute mod0 = new BasicAttribute("uPwd", "4G45G435G436UJWG");
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0);
ctx.modifyAttributes("CN=John Westood,OU=L100,DC=l,DC=woods", mods);

// Stop TLS
tls.close();
// Context close
ctx.close();

我在方法ctx.modifyAttributes中遇到異常。 異常如下:

javax.naming.OperationNotSupportedException: [LDAP: error code 53 - 0000052D: SvcErr: DSID-031A12D2, problem 5003 (WILL_NOT_PERFORM), data 0

有人知道為什么修改uPwd可以從命令行使用STARTLS而不是從Java進行嗎?

似乎您正在嘗試更改針對Microsoft Active Directory的密碼(即使您顯示的是openLDAP)(我也不知道uPwd可能是什么。)

更改Microsoft Active Directory 密碼有幾個限制

一旦您確定可以與Microsoft Active Directory建立可接受的連接,就可以使用JNDI更改Microsoft Active Directory密碼示例

僅供參考:默認情況下,startTLS將使用389。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM