35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace ln.identities
|
|
{
|
|
public abstract class BaseIdentityProvider : IIdentityProvider
|
|
{
|
|
public BaseIdentityProvider()
|
|
{
|
|
}
|
|
|
|
public virtual Identity Authenticate(AuthenticationProve authenticationProve)
|
|
{
|
|
Identity identity = GetIdentity(authenticationProve.IdentityName);
|
|
if (identity == null)
|
|
throw new KeyNotFoundException();
|
|
|
|
SecureAttribute secureAttribute = identity.GetSecureAttribute(authenticationProve.SecureAttributeUniqueID);
|
|
if (secureAttribute.Authenticate(authenticationProve.Challenge, authenticationProve.Prove))
|
|
{
|
|
return identity;
|
|
}
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
|
|
public abstract Identity CreateIdentity(string identityName);
|
|
public abstract IEnumerable<KeyValuePair<Guid, string>> GetIdentities();
|
|
public abstract Identity GetIdentity(Guid uniqueID);
|
|
public abstract bool Save(Identity identity);
|
|
|
|
public virtual Identity GetIdentity(string identityName) => GetIdentity(GetIdentities().FirstOrDefault((kvp) => identityName.Equals(kvp.Value)).Key);
|
|
}
|
|
}
|