I am trying to implement claim based security in web application. I have a class like.
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);
}
}
and I have CustomPrinciple like
public class CustomPrinciple : ClaimsPrincipal
{
public CustomPrinciple(IIdentity identity)
: base(identity)
{
}
}
Its always returning false because context.Principal
is WindowsPrinciple. I tried to set it in Globas.asax.cs like
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);
}
}
How can I change it so that I can get the CustomPrinciple
in CheckAccess(AuthorizationContext context)
Thanks
GenericPrinciple
now in AuthorizationManager but still I need to getCustomPrinciple
in that.