認証タスクを実行するために、リモートの顧客の Active Directory に対してバインドする必要があるアプリケーションがあります。
using (var ctx = new PrincipalContext(ContextType.Domain, "customer.org", "ou=people,dc=customer,dc=org", ContextOptions.SecureSocketLayer | ContextOptions.SimpleBind, "bindaccount@customer.org", "password"))
{
var user = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, username); // after several seconds, throws PrincipalServerDownException
if (user == null) return null; // user doesn't exist
// check if the account is locked out, etc. (omitted)
// quickly validate credentials
if (!ctx.ValidateCredentials(username, password, ContextOptions.SecureSocketLayer | ContextOptions.SimpleBind)) return null; // bad credentials
return user;
}
例外は次のとおりです。
PrincipalServerDownException: サーバーは動作していません。
at System.DirectoryServices.AccountManagement.ADStoreCtx.GetAsPrincipal(Object storeObject, Object discriminant)
at System.DirectoryServices.AccountManagement.ADStoreCtx.FindPrincipalByIdentRefHelper(Type principalType, String urnScheme, String urnValue, DateTime referenceDate, Boolean useSidHistory)
at System.DirectoryServices.AccountManagement.ADStoreCtx.FindPrincipalByIdentRef(Type principalType, String urnScheme, String urnValue, DateTime referenceDate)
at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate)
at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue)
at System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue)
今日まで、物事はうまくいっていました。1 つの変更点は、このコードを実行するアプリケーションが 4 から 4.5 にアップグレードされたことです。問題がアップグレード直後に発生したのか、それとも単なる偶然なのか、はっきりとは言えません。
私は AdFind を使用して顧客の AD に対するバインドをテストしていましたが、問題なく動作しているようです。
もう 1 つの興味深い点は、 が正常にPrincipalContext
初期化され (したがって、リモート ストアとの接続が検証され)、呼び出しをコメント アウトすると、FindByIdentity
呼び出されるだけctx.ValidateCredentials
で正常に動作することです。