diff --git a/AssignedRoles.cs b/AssignedRoles.cs index e5e3d15..9476c86 100644 --- a/AssignedRoles.cs +++ b/AssignedRoles.cs @@ -26,6 +26,24 @@ namespace ln.identities return assignedRoles[identity.UniqueID]; } } + public AssignedRole this[Guid identityUniqueID] + { + get + { + if (!assignedRoles.ContainsKey(identityUniqueID)) + { + if (identityUniqueID.Equals(Guid.Empty)) + assignedRoles.Add(identityUniqueID, new AssignedRole(identityProvider, Identity.Anonymous(identityProvider))); + else + throw new KeyNotFoundException(); + } + return assignedRoles[identityUniqueID]; + } + } + + public bool HasRole(Role role) => HasRole(null, role); + public bool HasRole(Identity identity, Role role) => HasRole(identity?.UniqueID ?? Guid.Empty, role); + public bool HasRole(Guid identityUniqueID, Role role)=> (this[identityUniqueID].Role & role) == role; public IEnumerator GetEnumerator() { diff --git a/AuthenticationNeeded.cs b/AuthenticationNeeded.cs new file mode 100644 index 0000000..632b2aa --- /dev/null +++ b/AuthenticationNeeded.cs @@ -0,0 +1,10 @@ +using System; +namespace ln.identities +{ + public class AuthenticationNeeded : Exception + { + public AuthenticationNeeded() + { + } + } +} diff --git a/Identity.cs b/Identity.cs index b46b4ad..5587bb8 100644 --- a/Identity.cs +++ b/Identity.cs @@ -6,6 +6,8 @@ namespace ln.identities { public class Identity { + public static Identity Anonymous(IIdentityProvider identityProvider) => new Identity(identityProvider, Guid.Empty, null); + private IIdentityProvider identityProvider; public IIdentityProvider IdentityProvider => identityProvider; diff --git a/RequireAttribute.cs b/RequireAttribute.cs new file mode 100644 index 0000000..dd13a85 --- /dev/null +++ b/RequireAttribute.cs @@ -0,0 +1,30 @@ +using System; +namespace ln.identities +{ + public class RequireAttribute : Attribute + { + public String IdentityName { get; set; } = null; + public Guid IdentityUniqueID { get; set; } = Guid.Empty; + + public Role Role { get; set; } + + public RequireAttribute() + { + } + + public RequireAttribute(String IdentityName) + { + this.IdentityName = IdentityName; + } + public RequireAttribute(Role Role) + { + this.Role = Role; + } + public RequireAttribute(String IdentityName,Role Role) + { + this.IdentityName = IdentityName; + this.Role = Role; + } + + } +} diff --git a/ln.identities.csproj b/ln.identities.csproj index 6edeae5..ecfc8bc 100644 --- a/ln.identities.csproj +++ b/ln.identities.csproj @@ -48,6 +48,8 @@ + +