從代碼嘗試重置 AD 用戶密碼并進一步使用相同的密碼從其他服務登錄。但 AD 并未對用戶進行身份驗證。在 AD 中,我們正在更新代碼中的userPassword,holcimIsRegistered和userAccountControl屬性以重置密碼。
當我們從 ADSI 手動重置 AD 用戶密碼時(右鍵單擊用戶 -> 去重置密碼 → 重置密碼)然后 AD 正在使用新密碼對用戶進行身份驗證。屬性都沒有userPassword更新。unicodePwd
我們也嘗試unicodePwd從 ADSI 和代碼更新屬性,但它不允許用戶從我們觀察到的代碼更新它的值
[LDAP: error code 53 - 0000001F: SvcErr: DSID-031A12D2, problem 5003 (WILL_NOT_PERFORM)]
我們比較了之前的用戶詳細資訊并從 ADSI 重置密碼,并觀察到很少有詳細資訊得到更新(BadLogonCount:0、badPasswordTime:0、badPwdCount:0、lastLogoff:0、lastLogon:0、logonCount:0、Modified、modifyTimeStamp、msDS-User-Account-Control-Computed、PasswordExpired:false、PasswordLastSet和)。uSNChangedwhenChanged
當我們嘗試修改usnChanged時,msDS-User-Account-Control-Computed從 ADSI 觀察到這兩個屬性無法從 ADSI 和它提供的代碼中編輯SchemaViolationException。對于passwordExpired和屬性,我們在從代碼和 ADSI 修改它時badLogonCount面臨這兩個屬性缺失。NoSuchAttributeException
我們還能怎么做呢?
uj5u.com熱心網友回復:
要重置密碼,請更新unicodePwd屬性。該檔案告訴您一些要求:
- 新密碼必須采用特定格式:用雙引號括起來,然后轉換為 UTF-16 編碼,以及
- 連接必須加密。
這個頁面有一個如何在 Java 中執行此操作的示例,我已將其粘貼在下面。它沒有談論加密,但您可以使用 LDAP over SSL (LDAPS),您可以使用LDAPS://而不是僅使用LDAP://. 這假設 AD 服務器已正確設定為 LDAPS,并且您沒有阻止 LDAPS 埠 (636) 的防火墻。
/**
* Update User Password in Microsoft Active Directory
* @param username
* @param password
*/
public void updateUserPassword(String username, String password)
{
try
{
System.out.println("updating password...\n");
String quotedPassword = "\"" password "\"";
char unicodePwd[] = quotedPassword.toCharArray();
byte pwdArray[] = new byte[unicodePwd.length * 2];
for (int i = 0; i < unicodePwd.length; i )
{
pwdArray[i * 2 1] = (byte) (unicodePwd[i] >>> 8);
pwdArray[i * 2 0] = (byte) (unicodePwd[i] & 0xff);
}
System.out.print("encoded password: ");
for (int i = 0; i < pwdArray.length; i )
{
System.out.print(pwdArray[i] " ");
}
System.out.println();
ModificationItem[] mods = new ModificationItem[1];
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("UnicodePwd", pwdArray));
ldapContext.modifyAttributes("cn=" username BASE_NAME, mods);
}
catch (Exception e)
{
System.out.println("update password error: " e);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/426012.html
上一篇:如何獲得快速訪問路徑
