42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
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<string> _roles = new HashSet<string>();
|
|
public IReadOnlySet<string> 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());
|
|
}
|
|
}
|
|
} |