![使用 java 在 openLDAP 上啟用/停用使用者的屬性](https://rvso.com/image/760630/%E4%BD%BF%E7%94%A8%20java%20%E5%9C%A8%20openLDAP%20%E4%B8%8A%E5%95%9F%E7%94%A8%2F%E5%81%9C%E7%94%A8%E4%BD%BF%E7%94%A8%E8%80%85%E7%9A%84%E5%B1%AC%E6%80%A7.png)
我的用戶是 inetOrgPerson 。啟用/停用用戶的屬性是什麼?我正在使用 JNDI 庫,並且正在嘗試此用於 Active Directory 的程式碼,但我收到 LDAP: error code 17 - userAccountControl: attribute type undefined 。如果我嘗試放置 attribute.put("userAccountControl","0x0001");創建用戶時我遇到同樣的錯誤。
任何想法?
public void disableEnableUser(String user) throws Exception {
ModificationItem[] mods = new ModificationItem[1];
//To enable user
//int UF_ACCOUNT_ENABLE = 0x0001;
//mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("userAccountControl",Integer.toString(UF_ACCOUNT_ENABLE)));
// To disable user
int UF_ACCOUNT_DISABLE = 0x0002;
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("userAccountControl",Integer.toString(UF_ACCOUNT_DISABLE)));
connection.modifyAttributes("path to user", mods);
}
答案1
userAccountControl
是一個AD屬性,所以在openldap中,你不會找到它(inerOrgPerson 的定義沒有userAccountControl
)。如果你想鎖定你的用戶,你必須採取其他方式。
一種可能性是使用密碼原則 (ppolicy) 覆蓋。 ppolicy 定義一個pwdAccountLockedTime
屬性,如果設定為“00000101000000Z”,則表示管理鎖定。為此,您必須在 LDAP 樹中包含 ppolicy,這基本上意味著檔案ldapadd
中包含 ppolicy ppolicy.ldif
。
另一種可能性是將使用者的密碼變更為表示鎖定的密碼。例如,透過將{SSHA}
密碼前綴變更為{SSHA}!
,您可以輕鬆指示使用者是否已鎖定。作為獎勵,您不需要任何額外的覆蓋層,而且它也會阻止用戶登入。