ユーザーと Active Directory グループのリストを指定すると、ユーザーが属するグループのサブセットを返す .NET 3.5 メソッドがあります。コードは数十回のインストールで機能しますが、特定の顧客サイトで失敗します。コードは次のようになります。
List<GroupAttrs> ret = new List<GroupAttrs>();
foreach (SymDomainInfo domain in domains)
{
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domain.Name, adUser, adPwd))
{
foreach (GroupAttrs aGroup in grpAttrs)
{
if (aGroup.Available)
continue;
GroupPrincipal pGroup;
try
{
pGroup = GroupPrincipal.FindByIdentity(ctx, IdentityType.Sid, aGroup.Authid);
}
catch (Exception e3)
{
Console.WriteLine("{3} finding group {0}/{4} in domain {1}: {2}", aGroup.Name, domain.Name, e3.Message, e3.GetType().Name, aGroup.Authid);
if (e3.InnerException != null)
Console.WriteLine("\tInner {0}: {1}", e3.InnerException.GetType().Name, e3.InnerException.Message);
continue;
}
if (pGroup != null)
{
Console.WriteLine("Found Group " + pGroup.DistinguishedName);
FindUserInGroup(grpMap, identity.User, ret, pGroup);
}
}
}
}
Aは、Active Directory グループGroupAttrs
の名前と SID (フィールド内) を含む独自のデータベース クラスです。AuthID
コレクションSymDomainInfos
には、AD 内のすべての信頼されたドメインの名前とパスが含まれています。およびはadUser
、adPassword
AD を検索する権限を持つドメイン ユーザーの資格情報です。
ループのすべての反復で同じエラーが発生します。
System.ArgumentException: 値が無効でした。パラメーター名: System.DirectoryServices.AccountManagement.ADStoreCtx.FindPrincipalByIdentRefHelper
の System.Security.Principal.SecurityIdentifier..ctor(String sddlForm)の sddlForm
(Type principalType、String urnScheme、String urnValue、DateTime referenceDate、Boolean useSidHistory)
at System.DirectoryServices。 System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper の AccountManagement.ADStoreCtx.FindPrincipalByIdentRef (型 principalType、文字列 urnScheme、文字列 urnValue、DateTime referenceDate)
(PrincipalContext コンテキスト、型 principalType、Nullable`1 identityType、文字列 identityValue、DateTime refDate)
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType (PrincipalContext コンテキスト、型 principalType、IdentityType identityType、文字列 identityValue)
で System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity (PrincipalContext コンテキスト、IdentityType identityType、文字列 identityValue)
で ADGroupsTest.Program.Main (文字列[]引数)
これがうまくいかなかった顧客がもう1人いました。エラーは別のもので、その顧客は Active Directory の既定のプロパティの一部を削除または無効にしていました。それらのプロパティを復元すると、コードが機能し始めました。したがって、この顧客はGroupPrincipal.FindByIdentity
、ドメイン コンテキストから呼び出されたときに機能しないような AD を何らかの方法で構成したと考えられます。
私の質問は次のとおりです。どのタイプの AD (ミス) 構成がこの特定のエラーにつながるか知っている人はいますか? この場合、機能するためにどの AD プロパティを実装する必要があるかを誰かに教えてもらえないFindByIdentity
でしょうか?