using System.Collections.Generic; namespace ln.http { public class HttpPrincipal { public string UniqueId { get; set; } public string Username { get; set; } /** * If this principal is a delegated one, authenticated by another principal */ public HttpPrincipal AuthenticatedPrincipal { get; } private HashSet _roles = new HashSet(); public IReadOnlySet Roles => _roles; public bool HasRole(string role) => _roles.Contains(role); public HttpPrincipal(string uniquedId, string username, string[] roles) { UniqueId = uniquedId; Username = username; foreach (var role in roles) _roles.Add(role); } public HttpPrincipal(string uniquedId, string username, string[] roles, HttpPrincipal authenticatedPrincipal) : this(uniquedId, username, roles) { AuthenticatedPrincipal = authenticatedPrincipal; } public override string ToString() { if (AuthenticatedPrincipal is null) return string.Format("{0}[{1}]", Username, UniqueId); else return string.Format("{2}=>{0}[{1}]", Username, UniqueId, AuthenticatedPrincipal.ToString()); } } }