Fix OverrideOptionsAsync method logic error.

pull/4984/head
maliming 5 years ago
parent c49b62ae03
commit f6c80f765e

@ -32,15 +32,15 @@ namespace Volo.Abp.Ldap
protected virtual async Task OverrideOptionsAsync(AbpLdapOptions options)
{
options.ServerHost = await GetStringValueOrDefault(LdapSettingNames.ServerHost) ?? options.ServerHost;
options.ServerHost = await GetSettingOrDefaultValue(LdapSettingNames.ServerHost, options.ServerHost);
options.ServerPort = await SettingProvider.GetAsync(LdapSettingNames.ServerPort, options.ServerPort);
options.UserName = await GetStringValueOrDefault(LdapSettingNames.UserName) ?? options.UserName;
options.Password = await GetStringValueOrDefault(LdapSettingNames.Password) ?? options.Password;
options.UserName = await GetSettingOrDefaultValue(LdapSettingNames.UserName, options.UserName);
options.Password = await GetSettingOrDefaultValue(LdapSettingNames.Password, options.Password);
}
protected virtual async Task<string> GetStringValueOrDefault(string name, string defaultValue = default)
protected virtual async Task<string> GetSettingOrDefaultValue(string name, string defaultValue)
{
var value = await SettingProvider.GetOrNullAsync(LdapSettingNames.ServerHost);
var value = await SettingProvider.GetOrNullAsync(name);
return value.IsNullOrWhiteSpace() ? defaultValue : value;
}
}

@ -29,7 +29,7 @@ namespace Volo.Abp.Ldap
try
{
var conn = CreateLdapConnection();
AuthenticateLdapConnection(conn, username,password);
AuthenticateLdapConnection(conn, username, password);
return true;
}
catch (Exception ex)

@ -12,9 +12,12 @@ namespace Volo.Abp.Ldap
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpLdapOptions>(settings =>
Configure<AbpLdapOptions>(options =>
{
options.ServerHost = "192.168.0.3";
options.ServerPort = 389;
options.UserName = "cn=admin,dc=abp,dc=io";
options.Password = "123qwe";
});
}
}

@ -1,4 +1,7 @@
using Volo.Abp.Testing;
using System;
using Shouldly;
using Volo.Abp.Testing;
using Xunit;
namespace Volo.Abp.Ldap
{
@ -15,5 +18,14 @@ namespace Volo.Abp.Ldap
{
options.UseAutofac();
}
[Fact(Skip = "Required Ldap environment")]
public void Authenticate()
{
_ldapManager.Authenticate().ShouldBe(true);
_ldapManager.Authenticate("cn=abp,dc=abp,dc=io", "123qwe").ShouldBe(true);
_ldapManager.Authenticate("NoExists", "123qwe").ShouldBe(false);
}
}
}

Loading…
Cancel
Save