Beispiel #1
0
        private ActivityPrincipal Convert(IPrincipal principal)
        {
            if (principal == null)
            {
                return(new ActivityPrincipal());
            }

            var activityPrincipal = principal as ActivityPrincipal;

            if (activityPrincipal != null)
            {
                return(activityPrincipal);
            }
            var claimsPrincipal = principal as ClaimsPrincipal;

            if (claimsPrincipal != null)
            {
                //This is wrong but we are not using roles yet
                var roles = claimsPrincipal.Claims.Select(x => x.Value);
                var p     = new ActivityPrincipal(
                    new ActivityIdentity(claimsPrincipal.Identity.Name, claimsPrincipal.Identity.IsAuthenticated, claimsPrincipal.Identity.AuthenticationType)
                    , roles.ToArray()
                    );

                return(p);
            }

            throw new NotSupportedException($"Converting {principal.GetType()} not supported");
        }
Beispiel #2
0
 public ActivityContext(IPrincipal principal)
 {
     _activityPrincipal = Convert(principal);
 }