3

データベースに格納されているカスタムメンバーシッププロバイダとユーザー/ロールを持つMVC3アプリケーションがあります。ユーザーは、必要に応じてアプリケーション内で手動で作成され、適切な役割が割り当てられます。MVC3カスタムメンバーシッププロバイダとActive Directory

アプリケーションを拡張してActive Directoryを使用するオプションを提供したいと考えていますが、アプリケーションにFKルックアップを含む複数のカスタムフィールド+テーブルがあるため、私はまだ既定のアクティブディレクトリメンバーシッププロバイダのカスタムバージョン。

SFの誰かが私と共有できる何か類似していますか? おかげ

+0

これをバンプすると、 – SimpleUser

+0

最後にこの解決策が見つかりましたか? –

答えて

0

私はこれが古い質問です知っているが...

私は私のADFSサーバーと直接認証を基づいて、連合の主張をセットアップし、私のWebアプリケーションでは

を開始する場所を見てみましょう。私はこれを行う方法についての良いチュートリアルを見つけることができませんでしたが、それは簡単ではありません。しかし、紺碧のACSを中間の人間として使用する方法については、多くの参考文献があります。この1つは、少なくともあなたが始めるだろう:

http://haishibai.blogspot.com/2011/05/tutorialaspnet-mvc-3-claim-based.html

あなたはこの作業をあなたが物事のカップルを必要とする得れば。

ADにリンクできるデータベースユーザーテーブルにいくつかのプロパティを追加します。私はAD GUIDを鉱山に保管していますが、私はセカンダリとして電子メールアドレスも使用しています。これにより私のアプリでユーザーを作成し、ADで認証させることができます。私はクレームとしてメールを返信し、自分のアプリでユーザーと一致させてから、ユーザーにAD GUIDを追加します。

私はまた、私の認証を行うために継承を利用しています。私のすべてのコントローラはBaseControllerを継承し、標準的な動作をします。

public class BaseController 
{ 
    protected override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext) 
    { 
     if (filterContext.HttpContext.User.Identity.IsAuthenticated) 
     { 
      //read in the claims that we got back from ADFS 
      IClaimsPrincipal icp = Thread.CurrentPrincipal as IClaimsPrincipal; 
      IClaimsIdentity ici = icp.Identity as IClaimsIdentity; 

      var claims = ici.Claims; 

      // This is a claim that I add manually to see if I've already synced 
      // ADFS user with DB user 
      var ppid = claims.FirstOrDefault(x => x.ClaimType == ClaimTypes.PPID); 
      if (ppid == null) 
      { 
       //query/sync user. 
       var guidString = claims.FirstOrDefault(x => x.ClaimType == ClaimTypes.Name).Value; 

       // get AD GUID 
       var userGuid = new Guid(System.Convert.FromBase64String(guidString)); 

       //look up user 
       var currentUser = UserRepository.FetchUserByGUID(userGuid); 

       //if user not found try fetch by email. 
       if (currentUser == null) 
       { 
        var email = claims.FirstOrDefault(x => x.ClaimType == ClaimTypes.Email).Value; 
        currentUser = UserRepository.FetchByEmail(email); 
       } 

       //If user is still not found create User 
       if (currentUser == null) 
       { 
        currentUser = new Models.User(); 
        BaseRepository.GetDataContext().Users.Add(currentUser); 
       } 

       //update users information using AD claim as master record 
       currentUser.ADID = userGuid; 
       currentUser.Name = claims.FirstOrDefault(x => x.ClaimType == ClaimTypes.GivenName).Value; 
       currentUser.EmailAddress = claims.FirstOrDefault(x => x.ClaimType == ClaimTypes.Email).Value; 
       currentUser.LastLoginDate = DateTime.UtcNow; 
       currentUser.LoginCount = currentUser.LoginCount + 1; 

       BaseRepository.GetDataContext().SaveChanges(); 

       // Now that you have your AD user linked to your user record 
       // in your database... 
       // Create new claims in your ADFS token that include all the roles that 
       // your user has. That way you can just piggyback on claims based 
       // authentication 
       foreach (var r in currentUser.Roles) 
       { 
        claims.Add(new Claim(ClaimTypes.Role, r.Name)); 
       } 

       // Add userid claim so that we know that this users claims have already 
       // been sync with my database 
       claims.Add(new Claim(ClaimTypes.PPID, currentUser.Id.ToString())); 
      } 
     } 

     base.OnAuthorization(filterContext); 
    } 

希望します。