public SenderPrincipal(IPrincipal principal) { if (principal == null) throw new ArgumentNullException("principal"); if (principal.Identity != null) { _identity = new SenderIdentity(principal.Identity); } var claimsPrincipal = principal as ClaimsPrincipal; if (claimsPrincipal != null) { var roleClaimType = ClaimTypes.Role; var claimsIdentity = claimsPrincipal.Identity as ClaimsIdentity; if (claimsIdentity != null) { roleClaimType = claimsIdentity.RoleClaimType; } _roles = claimsPrincipal.Claims .Where(claim => claim.Type == roleClaimType) .Select(claim => new SenderRole(claim)) .Distinct() .ToArray(); } else { _roles = new SenderRole[0]; } }
protected SenderPrincipal(SerializationInfo info, StreamingContext context) { _identity = (SenderIdentity) info.GetValue("identity", typeof (SenderIdentity)); _roles = (SenderRole[]) info.GetValue("roles", typeof (SenderRole[])); }