Browse Source

Add LdapSettingProvider.

pull/4984/head
maliming 6 years ago
parent
commit
d24d4c8403
  1. 10
      framework/src/Volo.Abp.Ldap/Volo.Abp.Ldap.csproj
  2. 44
      framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpAbpLdapOptionsFactory.cs
  3. 31
      framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpLdapModule.cs
  4. 4
      framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapManager.cs
  5. 24
      framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapSettingNames.cs
  6. 67
      framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapSettingProvider.cs
  7. 10
      framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/LdapResource.cs
  8. 28
      framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/en.json
  9. 28
      framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/tr.json
  10. 28
      framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/zh-Hans.json
  11. 28
      framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/zh-Hant.json

10
framework/src/Volo.Abp.Ldap/Volo.Abp.Ldap.csproj

@ -17,9 +17,17 @@
<ItemGroup>
<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="2.3.8" />
</ItemGroup>
<ItemGroup>
<Content Remove="Volo\Abp\Ldap\Localization\*.json" />
<EmbeddedResource Include="Volo\Abp\Ldap\Localization\*.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
<ProjectReference Include="..\Volo.Abp.Localization\Volo.Abp.Localization.csproj" />
<ProjectReference Include="..\Volo.Abp.Settings\Volo.Abp.Settings.csproj" />
<ProjectReference Include="..\Volo.Abp.VirtualFileSystem\Volo.Abp.VirtualFileSystem.csproj" />
</ItemGroup>
</Project>

44
framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpAbpLdapOptionsFactory.cs

@ -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;
}
}
}

31
framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpLdapModule.cs

@ -1,14 +1,43 @@
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.Settings;
using Volo.Abp.VirtualFileSystem;
namespace Volo.Abp.Ldap
{
[DependsOn(
typeof(AbpSettingsModule),
typeof(AbpVirtualFileSystemModule),
typeof(AbpLocalizationModule))]
public class AbpLdapModule : AbpModule
{
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();
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");
});
}
}
}

4
framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapManager.cs

@ -251,8 +251,8 @@ namespace Volo.Abp.Ldap
protected virtual ILdapConnection GetConnection(string bindUserName = null, string bindUserPassword = null)
{
// bindUserName/bindUserPassword only be used when authenticate
bindUserName = bindUserName ?? LdapOptions.Credentials.DomainUserName;
bindUserPassword = bindUserPassword ?? LdapOptions.Credentials.Password;
bindUserName ??= LdapOptions.Credentials.DomainUserName;
bindUserPassword ??= LdapOptions.Credentials.Password;
var ldapConnection = new LdapConnection() { SecureSocketLayer = LdapOptions.UseSsl };
if (LdapOptions.UseSsl)

24
framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapSettingNames.cs

@ -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";
}
}
}

67
framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapSettingProvider.cs

@ -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);
}
}
}

10
framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/LdapResource.cs

@ -0,0 +1,10 @@
using Volo.Abp.Localization;
namespace Volo.Abp.Ldap.Localization
{
[LocalizationResourceName("AbpLdap")]
public class LdapResource
{
}
}

28
framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/en.json

@ -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",
}
}

28
framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/tr.json

@ -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",
}
}

28
framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/zh-Hans.json

@ -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",
}
}

28
framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/zh-Hant.json

@ -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…
Cancel
Save