0

Web アプリケーションにクレーム ベースのセキュリティを実装しようとしています。みたいなクラスがあります。

public class AuthorisationManager : ClaimsAuthorizationManager
{
    public override bool CheckAccess(AuthorizationContext context)
    {
        //if (context.Principal.Identity.IsAdmin())
        //    return true;
        var resource = context.Resource.First().Value;
        var action = context.Action.First().Value;
        return context.Principal.HasClaim(resource, action);
    }
    public override void LoadCustomConfiguration(System.Xml.XmlNodeList nodelist)
    {
        base.LoadCustomConfiguration(nodelist);
    }
}

そして私は次のようなCustomPrincipleを持っています

 public class CustomPrinciple  : ClaimsPrincipal
{
    public CustomPrinciple(IIdentity identity)
        : base(identity)
    {
    }
}

context.PrincipalWindowsPrinciple であるため、常に false を返します。Globas.asax.cs のように設定しようとしました

 protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
    {
        HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

        if (authCookie != null)
        {
            FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);

            PermissionManager mgr = new PermissionManager();
            mgr.CheckUserAccess("", "");
            mgr.LoadPermissionModel("XYZ");

            HttpContext.Current.User = mgr.LoadPermissionModel("ABC");
            Thread.CurrentPrincipal = HttpContext.Current.User;
            AppDomain.CurrentDomain.SetThreadPrincipal(Thread.CurrentPrincipal);
        }
    }

を取得できるように変更するにはどうすればよいですCustomPrincipleCheckAccess(AuthorizationContext context)

ありがとう

4

1 に答える 1

2

(受け入れられる提案された回答):

または<authorization mode="Windows">の代わりにweb.configにあると思います(どちらもクレームベースの認証で動作するはずです)。FormsNone

于 2013-02-26T08:06:22.160 に答える