2

認証タスクを実行するために、リモートの顧客の 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で正常に動作することです。

4

1 に答える 1

3

実際には 4.5 が問題かもしれません。「安全な」UerPrincipal.FindByIdentity にいくつかの変更が加えられました。それらは、クロス ドメインおよびワークグループ => ドメイン シナリオでコードを壊す傾向があります。

少なくとも 2 つの可能性があります。

  • 4.0 に戻す
  • 代わりに DirectoryEntry を使用してください
于 2013-04-24T18:51:42.593 に答える