我正在使用WCF服務向我們的幫助臺人員公開某些Active Directory管理功能,但未向他們提供直接操作AD所需的組成員資格。將用戶添加到和刪除組中的用戶正在像現有用戶一個冠軍,但每次我創建一個新用戶時,它拋出回到這個有趣的代碼:在創建用戶後向AD安全組添加用戶失敗
The server is unwilling to process the request. (Exception from HRESULT: 0x80072035)
我用它來將用戶添加到組的代碼是
public bool AddGroupToUser(string userDn, string groupDn)
{
try
{
DirectoryEntry groupEntry = LdapTools.GetDirectoryEntry(groupDn);
groupEntry.Properties["member"].Add(userDn);
groupEntry.CommitChanges();
groupEntry.Close();
return true;
}
catch (DirectoryServicesCOMException)
{
return false;
}
}
一切我關於這個問題的閱讀是相當模糊的,我似乎無法找出爲什麼異常被觸發。有任何想法嗎?
UPDATE
這是我使用在AD中創建用戶的代碼:
try
{
DirectoryEntry container = GetDirectoryEntry(storageOu);
DirectoryEntry newUser = container.Children.Add("CN=" + employee.FullName, "user");
newUser.Properties["sAMAccountName"].Value = employee.Username;
newUser.Properties["displayName"].Value = employee.FullName;
newUser.Properties["givenName"].Value = employee.FirstName;
newUser.Properties["sn"].Value = employee.LastName;
newUser.Properties["department"].Value = departmentName;
newUser.Properties["userPrincipalName"].Value = employee.Username + "@APEX.Local";
newUser.CommitChanges();
newUser.Invoke("SetPassword", new object[] { employee.Password });
newUser.CommitChanges();
AdsUserFlags userSettings = AdsUserFlags.NormalAccount;
newUser.Properties["userAccountControl"].Value = userSettings;
newUser.CommitChanges();
ldapPath = newUser.Path;
newUser.Close();
container.Close();
}
catch (DirectoryServicesCOMException e)
{
// Something went wrong... what???
}
catch (Exception e)
{
// Something else went wrong
}
新的用戶可以登錄,並且可以使用標準的MS工具來操縱。
我不認爲DirectoryEntry基元可以保證在內部使用相同的AD綁定,因此完全可以在不同於您添加用戶的域控制器(AD使用多主複製模型)的域控制器上操作該組。 完成複製所需的時間量取決於域控制器的數量,該設置決定了在通知對等方更改和AD事務量之前要等待多長時間。 在一個大的領域,我看到AD花費5分鐘以上來完全複製一個SPN,所以要小心8秒。 –
我已經編寫了一個DirectoryEntry封裝器,旨在解決不知道我連接到的域控制器的問題。我現在每次都連接到同一個DC,並且在8秒鐘的時間過去之前,它仍然無法識別後續呼叫中的DirectoryEntry。幸運的是,至少現在,我只需要擔心兩個區議會。如果我們開始爲每個位置添加一個DC,Heaven會幫助我。 你知道一種方法來找出SPN何時被完全複製嗎? – thaBadDawg