使用 java 在 openLDAP 上啟用/停用使用者的屬性

使用 java 在 openLDAP 上啟用/停用使用者的屬性

我的用戶是 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}!,您可以輕鬆指示使用者是否已鎖定。作為獎勵,您不需要任何額外的覆蓋層,而且它也會阻止用戶登入。

相關內容