簡體   English   中英

如何在AD中通過LDAP啟用用戶?

[英]How to enable user via LDAP in AD?

在我的程序(基於jldap)中,我嘗試通過將userAccountControl值設置為512來啟用AD中的用戶。使用以下屬性創建的用戶:

objectClass=user
cn=username
name=username
userAccountControl=512
userPassword={BASE64}<base64 encoded password>
sAMAccountName=username
distinguishedName=username,CN=Users,DC=company,DC=com

但我得到例外:

LDAPException: Unwilling To Perform (53) Unwilling To Perform
LDAPException: Server Message: 0000052D: SvcErr: DSID-031A0FC0, problem 5003 (WILL_NOT_PERFORM), data 0

可能有人能告訴我我在哪里犯了錯誤嗎? 也許我忘了一些必要的屬性?

編輯:

我的代碼(這是微不足道的,我認為它沒有錯誤):

LDAPConnection connection;
LDAPMessageQueue messageQueue;
...
LDAPAttributeSet attributes = new LDAPAttributeSet();
attributes.add(new LDAPAttribute("objectClass", "user"));
attributes.add(new LDAPAttribute("cn", "username"));
attributes.add(new LDAPAttribute("name", "username"));
attributes.add(new LDAPAttribute("userAccountControl", "512"));
attributes.add(new LDAPAttribute("userPassword", "{BASE64}<base64 encoded password>"));
attributes.add(new LDAPAttribute("sAMAccountName", "username"));
attributes.add(new LDAPAttribute("distinguishedName", "username,CN=Users,DC=company,DC=com"));

LDAPEntry entry = new LDAPEntry("CN=username,CN=Users,DC=company,DC=com", attributes);
connection.add(entry);

密碼未正確編碼時可能會出現此錯誤。 確保它是Base64編碼的UTF-16LE字符串。

示例(如果您使用的是Oracle JVM)

String pass = "password";
sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder();
String encoded = enc.encode(pass.getBytes("UTF-16LE"));

更新1:您是否嘗試在沒有userAccountControl屬性的情況下運行代碼(為了規則或者說它實際上是導致問題的屬性)?

我注意到你的專有名稱屬性看起來有點奇怪。 它應該看起來像CN=username,OU=Users,DC=company,DC=com

更新2:請參閱在Active Directory LDAP中添加具有密碼的用戶 如果您嘗試通過非SSL連接為條目設置密碼(因為您正在創建密碼),則可以返回WILL_NOT_PERFORM。 您需要確保通過SSL連接到AD服務器(並根據需要設置證書)。

暫無
暫無

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

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