WIP
parent
5a7540a2b5
commit
774af4552f
|
@ -26,6 +26,24 @@ namespace ln.identities
|
||||||
return assignedRoles[identity.UniqueID];
|
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()
|
public IEnumerator<AssignedRole> GetEnumerator()
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
namespace ln.identities
|
||||||
|
{
|
||||||
|
public class AuthenticationNeeded : Exception
|
||||||
|
{
|
||||||
|
public AuthenticationNeeded()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,8 @@ namespace ln.identities
|
||||||
{
|
{
|
||||||
public class Identity
|
public class Identity
|
||||||
{
|
{
|
||||||
|
public static Identity Anonymous(IIdentityProvider identityProvider) => new Identity(identityProvider, Guid.Empty, null);
|
||||||
|
|
||||||
private IIdentityProvider identityProvider;
|
private IIdentityProvider identityProvider;
|
||||||
public IIdentityProvider IdentityProvider => identityProvider;
|
public IIdentityProvider IdentityProvider => identityProvider;
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,6 +48,8 @@
|
||||||
<Compile Include="test\IdentityTests.cs" />
|
<Compile Include="test\IdentityTests.cs" />
|
||||||
<Compile Include="AssignedRole.cs" />
|
<Compile Include="AssignedRole.cs" />
|
||||||
<Compile Include="AssignedRoles.cs" />
|
<Compile Include="AssignedRoles.cs" />
|
||||||
|
<Compile Include="RequireAttribute.cs" />
|
||||||
|
<Compile Include="AuthenticationNeeded.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ln.types\ln.types.csproj">
|
<ProjectReference Include="..\ln.types\ln.types.csproj">
|
||||||
|
|
Loading…
Reference in New Issue