ASP.NET Windows 認証とカスタム IPrincipal/IIdentity オブジェクトを組み合わせる良い方法はありますか? ユーザーの電子メール アドレスを保存する必要があり、AuthenticateRequest イベント中に Context.CurrentUser に追加したカスタム IIdentity/IPrincipal ペアを使用してフォーム認証を行いました。
WindowsAuthentication を使用してこれを達成するにはどうすればよいでしょうか?
ASP.NET Windows 認証とカスタム IPrincipal/IIdentity オブジェクトを組み合わせる良い方法はありますか? ユーザーの電子メール アドレスを保存する必要があり、AuthenticateRequest イベント中に Context.CurrentUser に追加したカスタム IIdentity/IPrincipal ペアを使用してフォーム認証を行いました。
WindowsAuthentication を使用してこれを達成するにはどうすればよいでしょうか?
「ExtendedWindowsPrincipal」を WindowsPrincipal に基づく派生クラスとして作成し、その派生クラスに余分なデータを追加するだけでよいでしょうか?
そうすれば、ExtendedWindowsPrincipal は、WindowsPricinpal が必要な場所ならどこでも認識されます。
または: Windows 認証の使用について話しているので、おそらく Windows ネットワークにいます。Active Directory またはユーザー データベースがどこかにありますか?プリンシパルに保存しますか?
マルク
当初考えていたように、アイデンティティの代わりにプリンシパルを置き換えるように最初のソリューションをリファクタリングすることになりました。新しい拡張 WindowsPrincipal のインスタンスを作成するときにセキュリティの問題が発生したため、ID の置き換えは面倒でした。
public class ExtendedWindowsPrincipal : WindowsPrincipal
{
private readonly string _email;
public ExtendedWindowsPrincipal(WindowsIdentity ntIdentity,
string email) : base(ntIdentity)
{
_email = email;
}
public string Email
{
get { return _email; }
}
}
私の Authentication モジュールでは、HttpContext のプリンシパルを次のように置き換えました。
var currentUser = (WindowsIdentity)HttpContext.Current.User.Identity;
HttpContext.Current.User =
new ExtendedWindowsPrincipal(currentUser, userEmail);