mirror of https://github.com/abpframework/abp.git
35 changed files with 234 additions and 176 deletions
@ -1,33 +0,0 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.Options; |
|||
using Volo.Abp.Settings; |
|||
|
|||
namespace Volo.Abp.Ldap; |
|||
|
|||
public class AbpAbpLdapOptionsManager : AbpDynamicOptionsManager<AbpLdapOptions> |
|||
{ |
|||
protected ISettingProvider SettingProvider { get; } |
|||
|
|||
public AbpAbpLdapOptionsManager(IOptionsFactory<AbpLdapOptions> factory, ISettingProvider settingProvider) |
|||
: base(factory) |
|||
{ |
|||
SettingProvider = settingProvider; |
|||
} |
|||
|
|||
protected override async Task OverrideOptionsAsync(string name, AbpLdapOptions options) |
|||
{ |
|||
options.ServerHost = await GetSettingOrDefaultValue(LdapSettingNames.ServerHost, options.ServerHost); |
|||
options.ServerPort = await SettingProvider.GetAsync(LdapSettingNames.ServerPort, options.ServerPort); |
|||
options.BaseDc = await GetSettingOrDefaultValue(LdapSettingNames.BaseDc, options.BaseDc); |
|||
options.UserName = await GetSettingOrDefaultValue(LdapSettingNames.UserName, options.UserName); |
|||
options.Password = await GetSettingOrDefaultValue(LdapSettingNames.Password, options.Password); |
|||
} |
|||
|
|||
protected virtual async Task<string> GetSettingOrDefaultValue(string name, string defaultValue) |
|||
{ |
|||
var value = await SettingProvider.GetOrNullAsync(name); |
|||
return value.IsNullOrWhiteSpace() ? defaultValue : value; |
|||
} |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
namespace Volo.Abp.Ldap; |
|||
|
|||
public class AbpLdapOptions |
|||
{ |
|||
public string ServerHost { get; set; } |
|||
|
|||
public int ServerPort { get; set; } |
|||
|
|||
public string BaseDc { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// BindDN
|
|||
/// </summary>
|
|||
public string UserName { get; set; } |
|||
|
|||
/// <summary>
|
|||
///BindPassword
|
|||
/// </summary>
|
|||
public string Password { get; set; } |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.Ldap; |
|||
|
|||
public interface ILdapSettingProvider |
|||
{ |
|||
public Task<string> GetServerHostAsync(); |
|||
|
|||
public Task<int> GetServerPortAsync(); |
|||
|
|||
public Task<string> GetBaseDcAsync(); |
|||
|
|||
public Task<string> GetDomainDcAsync(); |
|||
|
|||
public Task<string> GetUserNameAsync(); |
|||
|
|||
public Task<string> GetPasswordAsync(); |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
using Volo.Abp.Ldap.Localization; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Settings; |
|||
|
|||
namespace Volo.Abp.Ldap; |
|||
|
|||
public class LdapSettingDefinitionProvider : SettingDefinitionProvider |
|||
{ |
|||
public override void Define(ISettingDefinitionContext context) |
|||
{ |
|||
context.Add( |
|||
new SettingDefinition( |
|||
LdapSettingNames.ServerHost, |
|||
"", |
|||
L("DisplayName:Abp.Ldap.ServerHost"), |
|||
L("Description:Abp.Ldap.ServerHost")), |
|||
|
|||
new SettingDefinition( |
|||
LdapSettingNames.ServerPort, |
|||
"389", |
|||
L("DisplayName:Abp.Ldap.ServerPort"), |
|||
L("Description:Abp.Ldap.ServerPort")), |
|||
|
|||
new SettingDefinition( |
|||
LdapSettingNames.BaseDc, |
|||
"", |
|||
L("DisplayName:Abp.Ldap.BaseDc"), |
|||
L("Description:Abp.Ldap.BaseDc")), |
|||
|
|||
new SettingDefinition( |
|||
LdapSettingNames.Domain, |
|||
"", |
|||
L("DisplayName:Abp.Ldap.Domain"), |
|||
L("Description:Abp.Ldap.Domain")), |
|||
|
|||
new SettingDefinition( |
|||
LdapSettingNames.UserName, |
|||
"", |
|||
L("DisplayName:Abp.Ldap.UserName"), |
|||
L("Description:Abp.Ldap.UserName")), |
|||
|
|||
new SettingDefinition( |
|||
LdapSettingNames.Password, |
|||
"", |
|||
L("DisplayName:Abp.Ldap.Password"), |
|||
L("Description:Abp.Ldap.Password"), |
|||
isEncrypted: true) |
|||
); |
|||
} |
|||
|
|||
private static LocalizableString L(string name) |
|||
{ |
|||
return LocalizableString.Create<LdapResource>(name); |
|||
} |
|||
} |
|||
@ -1,49 +1,46 @@ |
|||
using Volo.Abp.Ldap.Localization; |
|||
using Volo.Abp.Localization; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Settings; |
|||
|
|||
namespace Volo.Abp.Ldap; |
|||
|
|||
public class LdapSettingProvider : SettingDefinitionProvider |
|||
public class LdapSettingProvider : ILdapSettingProvider, ITransientDependency |
|||
{ |
|||
public override void Define(ISettingDefinitionContext context) |
|||
protected ISettingProvider SettingProvider { get; } |
|||
|
|||
public LdapSettingProvider(ISettingProvider settingProvider) |
|||
{ |
|||
SettingProvider = settingProvider; |
|||
} |
|||
|
|||
public async Task<string> GetServerHostAsync() |
|||
{ |
|||
return await SettingProvider.GetOrNullAsync(LdapSettingNames.ServerHost); |
|||
} |
|||
|
|||
public async Task<int> GetServerPortAsync() |
|||
{ |
|||
return (await SettingProvider.GetOrNullAsync(LdapSettingNames.ServerPort))?.To<int>() ?? default; |
|||
} |
|||
|
|||
public async Task<string> GetBaseDcAsync() |
|||
{ |
|||
return await SettingProvider.GetOrNullAsync(LdapSettingNames.BaseDc); |
|||
} |
|||
|
|||
public async Task<string> GetDomainDcAsync() |
|||
{ |
|||
return await SettingProvider.GetOrNullAsync(LdapSettingNames.Domain); |
|||
} |
|||
|
|||
public async Task<string> GetUserNameAsync() |
|||
{ |
|||
context.Add( |
|||
new SettingDefinition( |
|||
LdapSettingNames.ServerHost, |
|||
"", |
|||
L("DisplayName:Abp.Ldap.ServerHost"), |
|||
L("Description:Abp.Ldap.ServerHost")), |
|||
|
|||
new SettingDefinition( |
|||
LdapSettingNames.ServerPort, |
|||
"389", |
|||
L("DisplayName:Abp.Ldap.ServerPort"), |
|||
L("Description:Abp.Ldap.ServerPort")), |
|||
|
|||
new SettingDefinition( |
|||
LdapSettingNames.BaseDc, |
|||
"", |
|||
L("DisplayName:Abp.Ldap.BaseDc"), |
|||
L("Description:Abp.Ldap.BaseDc")), |
|||
|
|||
new SettingDefinition( |
|||
LdapSettingNames.UserName, |
|||
"", |
|||
L("DisplayName:Abp.Ldap.UserName"), |
|||
L("Description:Abp.Ldap.UserName")), |
|||
|
|||
new SettingDefinition( |
|||
LdapSettingNames.Password, |
|||
"", |
|||
L("DisplayName:Abp.Ldap.Password"), |
|||
L("Description:Abp.Ldap.Password"), |
|||
isEncrypted: true) |
|||
); |
|||
return await SettingProvider.GetOrNullAsync(LdapSettingNames.UserName); |
|||
} |
|||
|
|||
private static LocalizableString L(string name) |
|||
public async Task<string> GetPasswordAsync() |
|||
{ |
|||
return LocalizableString.Create<LdapResource>(name); |
|||
return await SettingProvider.GetOrNullAsync(LdapSettingNames.Password); |
|||
} |
|||
} |
|||
|
|||
@ -1,20 +0,0 @@ |
|||
using Microsoft.Extensions.Options; |
|||
using Shouldly; |
|||
using Volo.Abp.Testing; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Ldap; |
|||
|
|||
public class LdapOptions_Tests : AbpIntegratedTest<AbpLdapTestModule> |
|||
{ |
|||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
|||
{ |
|||
options.UseAutofac(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Resolve_AbpAbpLdapOptionsFactory() |
|||
{ |
|||
GetRequiredService<IOptions<AbpLdapOptions>>().ShouldBeOfType(typeof(AbpAbpLdapOptionsManager)); |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Settings; |
|||
|
|||
namespace Volo.Abp.Ldap; |
|||
|
|||
public class TestLdapSettingValueProvider : ISettingValueProvider, ITransientDependency |
|||
{ |
|||
public const string ProviderName = "Test"; |
|||
|
|||
public string Name => ProviderName; |
|||
|
|||
public Task<string> GetOrNullAsync(SettingDefinition setting) |
|||
{ |
|||
switch (setting.Name) |
|||
{ |
|||
case LdapSettingNames.ServerHost: |
|||
return Task.FromResult("localhost"); |
|||
|
|||
case LdapSettingNames.ServerPort: |
|||
return Task.FromResult("389"); |
|||
|
|||
case LdapSettingNames.BaseDc: |
|||
return Task.FromResult("dc=abp,dc=io"); |
|||
|
|||
case LdapSettingNames.Domain: |
|||
return Task.FromResult<string>(null); |
|||
|
|||
case LdapSettingNames.UserName: |
|||
return Task.FromResult("admin"); |
|||
|
|||
case LdapSettingNames.Password: |
|||
return Task.FromResult("123qwe"); |
|||
|
|||
default: |
|||
return Task.FromResult<string>(null); |
|||
} |
|||
} |
|||
|
|||
public Task<List<SettingValue>> GetAllAsync(SettingDefinition[] settings) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue