mirror of https://github.com/abpframework/abp.git
14 changed files with 9 additions and 292 deletions
@ -1,9 +0,0 @@ |
|||||
namespace Volo.Abp.Identity.Features |
|
||||
{ |
|
||||
public class IdentityFeature |
|
||||
{ |
|
||||
public const string GroupName = "Identity"; |
|
||||
|
|
||||
public const string TwoFactor = GroupName + ".TwoFactor"; |
|
||||
} |
|
||||
} |
|
||||
@ -1,51 +0,0 @@ |
|||||
using System; |
|
||||
using Volo.Abp.Features; |
|
||||
using Volo.Abp.Identity.Localization; |
|
||||
using Volo.Abp.Localization; |
|
||||
using Volo.Abp.Validation.StringValues; |
|
||||
|
|
||||
namespace Volo.Abp.Identity.Features |
|
||||
{ |
|
||||
public class IdentityFeatureDefinitionProvider : FeatureDefinitionProvider |
|
||||
{ |
|
||||
public override void Define(IFeatureDefinitionContext context) |
|
||||
{ |
|
||||
var group = context.AddGroup(IdentityFeature.GroupName, L("Feature:IdentityGroup")); |
|
||||
|
|
||||
group.AddFeature(IdentityFeature.TwoFactor, |
|
||||
IdentityTwoFactorBehaviour.Optional.ToString(), |
|
||||
L("Feature:TwoFactor"), |
|
||||
L("Feature:TwoFactorDescription"), |
|
||||
new SelectionStringValueType |
|
||||
{ |
|
||||
ItemSource = new StaticSelectionStringValueItemSource( |
|
||||
new LocalizableSelectionStringValueItem |
|
||||
{ |
|
||||
Value = IdentityTwoFactorBehaviour.Optional.ToString(), |
|
||||
DisplayText = GetTwoFactorBehaviourLocalizableStringInfo("Feature:TwoFactor.Optional") |
|
||||
}, |
|
||||
new LocalizableSelectionStringValueItem |
|
||||
{ |
|
||||
Value = IdentityTwoFactorBehaviour.Disabled.ToString(), |
|
||||
DisplayText = GetTwoFactorBehaviourLocalizableStringInfo("Feature:TwoFactor.Disabled") |
|
||||
}, |
|
||||
new LocalizableSelectionStringValueItem |
|
||||
{ |
|
||||
Value = IdentityTwoFactorBehaviour.Forced.ToString(), |
|
||||
DisplayText = GetTwoFactorBehaviourLocalizableStringInfo("Feature:TwoFactor.Forced") |
|
||||
} |
|
||||
) |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
private static LocalizableString L(string name) |
|
||||
{ |
|
||||
return LocalizableString.Create<IdentityResource>(name); |
|
||||
} |
|
||||
|
|
||||
private static LocalizableStringInfo GetTwoFactorBehaviourLocalizableStringInfo(string key) |
|
||||
{ |
|
||||
return new LocalizableStringInfo(LocalizationResourceNameAttribute.GetName(typeof(IdentityResource)), key); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,11 +0,0 @@ |
|||||
namespace Volo.Abp.Identity.Features |
|
||||
{ |
|
||||
public enum IdentityTwoFactorBehaviour |
|
||||
{ |
|
||||
Optional, |
|
||||
|
|
||||
Disabled, |
|
||||
|
|
||||
Forced |
|
||||
} |
|
||||
} |
|
||||
@ -1,23 +0,0 @@ |
|||||
using System; |
|
||||
using System.Threading.Tasks; |
|
||||
using JetBrains.Annotations; |
|
||||
using Volo.Abp.Features; |
|
||||
|
|
||||
namespace Volo.Abp.Identity.Features |
|
||||
{ |
|
||||
public static class IdentityTwoFactorBehaviourFeatureHelper |
|
||||
{ |
|
||||
public static async Task<IdentityTwoFactorBehaviour> Get([NotNull] IFeatureChecker featureChecker) |
|
||||
{ |
|
||||
Check.NotNull(featureChecker, nameof(featureChecker)); |
|
||||
|
|
||||
var value = await featureChecker.GetOrNullAsync(IdentityFeature.TwoFactor); |
|
||||
if (value.IsNullOrWhiteSpace() || !Enum.TryParse<IdentityTwoFactorBehaviour>(value, out var behaviour)) |
|
||||
{ |
|
||||
throw new AbpException($"{IdentityFeature.TwoFactor} feature value is invalid"); |
|
||||
} |
|
||||
|
|
||||
return behaviour; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,24 +0,0 @@ |
|||||
using System; |
|
||||
using System.Threading.Tasks; |
|
||||
using JetBrains.Annotations; |
|
||||
using Volo.Abp.Identity.Features; |
|
||||
using Volo.Abp.Settings; |
|
||||
|
|
||||
namespace Volo.Abp.Identity.Settings |
|
||||
{ |
|
||||
public static class IdentityTwoFactorBehaviourSettingHelper |
|
||||
{ |
|
||||
public static async Task<IdentityTwoFactorBehaviour> Get([NotNull] ISettingProvider settingProvider) |
|
||||
{ |
|
||||
Check.NotNull(settingProvider, nameof(settingProvider)); |
|
||||
|
|
||||
var value = await settingProvider.GetOrNullAsync(IdentitySettingNames.TwoFactor.Behaviour); |
|
||||
if (value.IsNullOrWhiteSpace() || !Enum.TryParse<IdentityTwoFactorBehaviour>(value, out var behaviour)) |
|
||||
{ |
|
||||
throw new AbpException($"{IdentitySettingNames.TwoFactor.Behaviour} setting value is invalid"); |
|
||||
} |
|
||||
|
|
||||
return behaviour; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,70 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Volo.Abp.Domain.Services; |
|
||||
using Volo.Abp.Features; |
|
||||
using Volo.Abp.Identity.Features; |
|
||||
using Volo.Abp.Identity.Settings; |
|
||||
using Volo.Abp.Settings; |
|
||||
|
|
||||
namespace Volo.Abp.Identity |
|
||||
{ |
|
||||
public class IdentityTwoFactorManager : IDomainService |
|
||||
{ |
|
||||
protected IFeatureChecker FeatureChecker { get; } |
|
||||
|
|
||||
protected ISettingProvider SettingProvider { get; } |
|
||||
|
|
||||
public IdentityTwoFactorManager(IFeatureChecker featureChecker, ISettingProvider settingProvider) |
|
||||
{ |
|
||||
FeatureChecker = featureChecker; |
|
||||
SettingProvider = settingProvider; |
|
||||
} |
|
||||
|
|
||||
public virtual async Task<bool> IsOptionalAsync() |
|
||||
{ |
|
||||
var feature = await IdentityTwoFactorBehaviourFeatureHelper.Get(FeatureChecker); |
|
||||
if (feature == IdentityTwoFactorBehaviour.Optional) |
|
||||
{ |
|
||||
var setting = await IdentityTwoFactorBehaviourSettingHelper.Get(SettingProvider); |
|
||||
if (setting == IdentityTwoFactorBehaviour.Optional) |
|
||||
{ |
|
||||
return true; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
public virtual async Task<bool> IsForcedEnableAsync() |
|
||||
{ |
|
||||
var feature = await IdentityTwoFactorBehaviourFeatureHelper.Get(FeatureChecker); |
|
||||
if (feature == IdentityTwoFactorBehaviour.Forced) |
|
||||
{ |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
var setting = await IdentityTwoFactorBehaviourSettingHelper.Get(SettingProvider); |
|
||||
if (setting == IdentityTwoFactorBehaviour.Forced) |
|
||||
{ |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
public virtual async Task<bool> IsForcedDisableAsync() |
|
||||
{ |
|
||||
var feature = await IdentityTwoFactorBehaviourFeatureHelper.Get(FeatureChecker); |
|
||||
if (feature == IdentityTwoFactorBehaviour.Disabled) |
|
||||
{ |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
var setting = await IdentityTwoFactorBehaviourSettingHelper.Get(SettingProvider); |
|
||||
if (setting == IdentityTwoFactorBehaviour.Disabled) |
|
||||
{ |
|
||||
return true; |
|
||||
} |
|
||||
return false; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue