master
Harald Wolff 2019-11-24 15:06:17 +01:00
parent 5a7540a2b5
commit 774af4552f
5 changed files with 62 additions and 0 deletions

View File

@ -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<AssignedRole> GetEnumerator()
{

View File

@ -0,0 +1,10 @@
using System;
namespace ln.identities
{
public class AuthenticationNeeded : Exception
{
public AuthenticationNeeded()
{
}
}
}

View File

@ -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;

View File

@ -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;
}
}
}

View File

@ -48,6 +48,8 @@
<Compile Include="test\IdentityTests.cs" />
<Compile Include="AssignedRole.cs" />
<Compile Include="AssignedRoles.cs" />
<Compile Include="RequireAttribute.cs" />
<Compile Include="AuthenticationNeeded.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ln.types\ln.types.csproj">