D J
D J

Reputation: 7028

AuthorizationContext.Principal is changing from ClaimsPrincipal to GenericPrincipal automatically

I dont know how come the context principle is changing in AuthorisationManager. My code is like

  public class AuthorisationManager : ClaimsAuthorizationManager
{
    public override bool CheckAccess(AuthorizationContext context)
    {
        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);
    }
}

I have list of items in GUI. It works fine first time but when I select second item the context.Principle is chnaged to GenericPrinciple.

Any idea will be helpfull on this.

Upvotes: 0

Views: 1503

Answers (2)

leastprivilege
leastprivilege

Reputation: 18482

return context.Principal.HasClaim(resource, action);

Well - typically there is no 1:1 correlation of claims and authorization "decisions". Also in typical scenarios claims only hold identity data - something data can be used later to base authorization decisions on. The authorization manager then uses its own data management to make those decisions.

Now since this is a client application (I didn't know that it was WPF) you may do things a little differently. In server applications your approach would scale very well.

Upvotes: 1

leastprivilege
leastprivilege

Reputation: 18482

OK - WPF.

Yeah I vaguely remember that there is some "feature" in WPF around Thread.CurrentPrincipal.

try

Thread.CurrentPrincipal = principal

AppDomain.CurrentDomain.SetThreadPrincipal(principal);

IIRC you maybe have to do that in the App class (ctor?).

Upvotes: 1

Related Questions