mirror of https://github.com/abpframework/abp.git
11 changed files with 298 additions and 4 deletions
@ -0,0 +1,44 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using Volo.Abp.Options; |
||||
|
using Volo.Abp.Settings; |
||||
|
using Volo.Abp.Threading; |
||||
|
|
||||
|
namespace Volo.Abp.Ldap |
||||
|
{ |
||||
|
public class AbpAbpLdapOptionsFactory : AbpOptionsFactory<AbpLdapOptions> |
||||
|
{ |
||||
|
protected ISettingProvider SettingProvider { get; } |
||||
|
|
||||
|
public AbpAbpLdapOptionsFactory( |
||||
|
IEnumerable<IConfigureOptions<AbpLdapOptions>> setups, |
||||
|
IEnumerable<IPostConfigureOptions<AbpLdapOptions>> postConfigures, |
||||
|
ISettingProvider settingProvider) |
||||
|
: base(setups, postConfigures) |
||||
|
{ |
||||
|
SettingProvider = settingProvider; |
||||
|
} |
||||
|
|
||||
|
public override AbpLdapOptions Create(string name) |
||||
|
{ |
||||
|
var options = base.Create(name); |
||||
|
|
||||
|
AsyncHelper.RunSync(() => OverrideOptionsAsync(options)); |
||||
|
|
||||
|
return options; |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task OverrideOptionsAsync(AbpLdapOptions options) |
||||
|
{ |
||||
|
options.ServerHost = await SettingProvider.GetOrNullAsync(LdapSettingNames.ServerHost) ?? options.ServerHost; |
||||
|
options.ServerPort = await SettingProvider.GetAsync(LdapSettingNames.ServerPort, options.ServerPort); |
||||
|
options.UseSsl = await SettingProvider.GetAsync(LdapSettingNames.UseSsl, options.UseSsl); |
||||
|
options.SearchBase = await SettingProvider.GetOrNullAsync(LdapSettingNames.SearchBase) ?? options.SearchBase; |
||||
|
options.DomainName = await SettingProvider.GetOrNullAsync(LdapSettingNames.DomainName) ?? options.DomainName; |
||||
|
options.DomainDistinguishedName = await SettingProvider.GetOrNullAsync(LdapSettingNames.DomainDistinguishedName) ?? options.DomainDistinguishedName; |
||||
|
options.Credentials.DomainUserName = await SettingProvider.GetOrNullAsync(LdapSettingNames.Credentials.DomainUserName) ?? options.Credentials.DomainUserName; |
||||
|
options.Credentials.Password = await SettingProvider.GetOrNullAsync(LdapSettingNames.Credentials.Password) ?? options.Credentials.Password; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,14 +1,43 @@ |
|||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using Volo.Abp.Ldap.Localization; |
||||
|
using Volo.Abp.Localization; |
||||
using Volo.Abp.Modularity; |
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.Settings; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
|
||||
namespace Volo.Abp.Ldap |
namespace Volo.Abp.Ldap |
||||
{ |
{ |
||||
|
[DependsOn( |
||||
|
typeof(AbpSettingsModule), |
||||
|
typeof(AbpVirtualFileSystemModule), |
||||
|
typeof(AbpLocalizationModule))] |
||||
public class AbpLdapModule : AbpModule |
public class AbpLdapModule : AbpModule |
||||
{ |
{ |
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
{ |
{ |
||||
|
context.Services.Replace(ServiceDescriptor.Transient<IOptionsFactory<AbpLdapOptions>, AbpAbpLdapOptionsFactory>()); |
||||
|
context.Services.Replace(ServiceDescriptor.Scoped<IOptions<AbpLdapOptions>, OptionsManager<AbpLdapOptions>>()); |
||||
|
|
||||
var configuration = context.Services.GetConfiguration(); |
var configuration = context.Services.GetConfiguration(); |
||||
Configure<AbpLdapOptions>(configuration.GetSection("LDAP")); |
var ldapConfiguration = configuration["LDAP"]; |
||||
|
if (!ldapConfiguration.IsNullOrEmpty()) |
||||
|
{ |
||||
|
Configure<AbpLdapOptions>(configuration.GetSection("LDAP")); |
||||
|
} |
||||
|
|
||||
|
Configure<AbpVirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<AbpLdapModule>(); |
||||
|
}); |
||||
|
|
||||
|
Configure<AbpLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.Resources |
||||
|
.Add<LdapResource>("en") |
||||
|
.AddVirtualJson("/Volo/Abp/Ldap/Localization"); |
||||
|
}); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,24 @@ |
|||||
|
namespace Volo.Abp.Ldap |
||||
|
{ |
||||
|
public static class LdapSettingNames |
||||
|
{ |
||||
|
public const string ServerHost = "Abp.Ldap.ServerHost"; |
||||
|
|
||||
|
public const string ServerPort = "Abp.Ldap.ServerPort"; |
||||
|
|
||||
|
public const string UseSsl = "Abp.Ldap.UseSsl"; |
||||
|
|
||||
|
public const string SearchBase = "Abp.Ldap.SearchBase"; |
||||
|
|
||||
|
public const string DomainName = "Abp.Ldap.DomainName"; |
||||
|
|
||||
|
public const string DomainDistinguishedName = "Abp.Ldap.DomainDistinguishedName"; |
||||
|
|
||||
|
public static class Credentials |
||||
|
{ |
||||
|
public const string DomainUserName = "Abp.Ldap.Credentials.DomainUserName"; |
||||
|
|
||||
|
public const string Password = "Abp.Ldap.Credentials.Password"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,67 @@ |
|||||
|
using Volo.Abp.Ldap.Localization; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Volo.Abp.Settings; |
||||
|
|
||||
|
namespace Volo.Abp.Ldap |
||||
|
{ |
||||
|
public class LdapSettingProvider : 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, |
||||
|
"", |
||||
|
L("DisplayName:Abp.Ldap.ServerPort"), |
||||
|
L("Description:Abp.Ldap.ServerPort")), |
||||
|
|
||||
|
new SettingDefinition( |
||||
|
LdapSettingNames.UseSsl, |
||||
|
"", |
||||
|
L("DisplayName:Abp.Ldap.UseSsl"), |
||||
|
L("Description:Abp.Ldap.UseSsl")), |
||||
|
|
||||
|
new SettingDefinition( |
||||
|
LdapSettingNames.SearchBase, |
||||
|
"", |
||||
|
L("DisplayName:Abp.Ldap.SearchBase"), |
||||
|
L("Description:Abp.Ldap.SearchBase")), |
||||
|
|
||||
|
new SettingDefinition( |
||||
|
LdapSettingNames.DomainName, |
||||
|
"", |
||||
|
L("DisplayName:Abp.Ldap.DomainName"), |
||||
|
L("Description:Abp.Ldap.DomainName")), |
||||
|
|
||||
|
new SettingDefinition( |
||||
|
LdapSettingNames.DomainDistinguishedName, |
||||
|
"", |
||||
|
L("DisplayName:Abp.Ldap.DomainDistinguishedName"), |
||||
|
L("Description:Abp.Ldap.DomainDistinguishedName")), |
||||
|
|
||||
|
new SettingDefinition( |
||||
|
LdapSettingNames.Credentials.DomainUserName, |
||||
|
"", |
||||
|
L("DisplayName:Abp.Ldap.Credentials.DomainUserName"), |
||||
|
L("Description:Abp.Ldap.Credentials.DomainUserName")), |
||||
|
|
||||
|
new SettingDefinition( |
||||
|
LdapSettingNames.Credentials.Password, |
||||
|
"", |
||||
|
L("DisplayName:Abp.Ldap.Credentials.Password"), |
||||
|
L("Description:Abp.Ldap.Credentials.Password")) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
private static LocalizableString L(string name) |
||||
|
{ |
||||
|
return LocalizableString.Create<LdapResource>(name); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using Volo.Abp.Localization; |
||||
|
|
||||
|
namespace Volo.Abp.Ldap.Localization |
||||
|
{ |
||||
|
[LocalizationResourceName("AbpLdap")] |
||||
|
public class LdapResource |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
{ |
||||
|
"culture": "en", |
||||
|
"texts": { |
||||
|
"DisplayName:Abp.Ldap.ServerHost": "ServerHost", |
||||
|
"Description:Abp.Ldap.ServerHost": "ServerHost", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.ServerPort": "ServerPort", |
||||
|
"Description:Abp.Ldap.ServerPort": "ServerPort", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.UseSsl": "UseSsl", |
||||
|
"Description:Abp.Ldap.UseSsl": "UseSsl", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.SearchBase": "SearchBase", |
||||
|
"Description:Abp.Ldap.SearchBase": "SearchBase", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.DomainName": "DomainName", |
||||
|
"Description:Abp.Ldap.DomainName": "DomainName", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.DomainDistinguishedName": "DomainDistinguishedName", |
||||
|
"Description:Abp.Ldap.DomainDistinguishedName": "DomainDistinguishedName", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.Credentials.DomainUserName": "Credentials DomainUserName", |
||||
|
"Description:Abp.Ldap.Credentials.DomainUserName": "Credentials DomainUserName", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.Credentials.Password": "Credentials Password", |
||||
|
"Description:Abp.Ldap.Credentials.Password": "Credentials Password", |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
{ |
||||
|
"culture": "tr", |
||||
|
"texts": { |
||||
|
"DisplayName:Abp.Ldap.ServerHost": "ServerHost", |
||||
|
"Description:Abp.Ldap.ServerHost": "ServerHost", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.ServerPort": "ServerPort", |
||||
|
"Description:Abp.Ldap.ServerPort": "ServerPort", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.UseSsl": "UseSsl", |
||||
|
"Description:Abp.Ldap.UseSsl": "UseSsl", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.SearchBase": "SearchBase", |
||||
|
"Description:Abp.Ldap.SearchBase": "SearchBase", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.DomainName": "DomainName", |
||||
|
"Description:Abp.Ldap.DomainName": "DomainName", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.DomainDistinguishedName": "DomainDistinguishedName", |
||||
|
"Description:Abp.Ldap.DomainDistinguishedName": "DomainDistinguishedName", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.Credentials.DomainUserName": "Credentials DomainUserName", |
||||
|
"Description:Abp.Ldap.Credentials.DomainUserName": "Credentials DomainUserName", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.Credentials.Password": "Credentials Password", |
||||
|
"Description:Abp.Ldap.Credentials.Password": "Credentials Password", |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
{ |
||||
|
"culture": "zh-Hans", |
||||
|
"texts": { |
||||
|
"DisplayName:Abp.Ldap.ServerHost": "ServerHost", |
||||
|
"Description:Abp.Ldap.ServerHost": "ServerHost", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.ServerPort": "ServerPort", |
||||
|
"Description:Abp.Ldap.ServerPort": "ServerPort", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.UseSsl": "UseSsl", |
||||
|
"Description:Abp.Ldap.UseSsl": "UseSsl", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.SearchBase": "SearchBase", |
||||
|
"Description:Abp.Ldap.SearchBase": "SearchBase", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.DomainName": "DomainName", |
||||
|
"Description:Abp.Ldap.DomainName": "DomainName", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.DomainDistinguishedName": "DomainDistinguishedName", |
||||
|
"Description:Abp.Ldap.DomainDistinguishedName": "DomainDistinguishedName", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.Credentials.DomainUserName": "Credentials DomainUserName", |
||||
|
"Description:Abp.Ldap.Credentials.DomainUserName": "Credentials DomainUserName", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.Credentials.Password": "Credentials Password", |
||||
|
"Description:Abp.Ldap.Credentials.Password": "Credentials Password", |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
{ |
||||
|
"culture": "zh-Hant", |
||||
|
"texts": { |
||||
|
"DisplayName:Abp.Ldap.ServerHost": "ServerHost", |
||||
|
"Description:Abp.Ldap.ServerHost": "ServerHost", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.ServerPort": "ServerPort", |
||||
|
"Description:Abp.Ldap.ServerPort": "ServerPort", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.UseSsl": "UseSsl", |
||||
|
"Description:Abp.Ldap.UseSsl": "UseSsl", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.SearchBase": "SearchBase", |
||||
|
"Description:Abp.Ldap.SearchBase": "SearchBase", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.DomainName": "DomainName", |
||||
|
"Description:Abp.Ldap.DomainName": "DomainName", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.DomainDistinguishedName": "DomainDistinguishedName", |
||||
|
"Description:Abp.Ldap.DomainDistinguishedName": "DomainDistinguishedName", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.Credentials.DomainUserName": "Credentials DomainUserName", |
||||
|
"Description:Abp.Ldap.Credentials.DomainUserName": "Credentials DomainUserName", |
||||
|
|
||||
|
"DisplayName:Abp.Ldap.Credentials.Password": "Credentials Password", |
||||
|
"Description:Abp.Ldap.Credentials.Password": "Credentials Password", |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue