From 564d8ffcfdf3ac09e9ae41e0c1ea616f5c3d9b81 Mon Sep 17 00:00:00 2001
From: maliming <6908465+maliming@users.noreply.github.com>
Date: Tue, 11 Aug 2020 14:42:24 +0800
Subject: [PATCH] Add BaseDc to AbpLdapOptions.
---
.../Volo/Abp/Ldap/AbpAbpLdapOptionsFactory.cs | 1 +
.../Volo.Abp.Ldap/Volo/Abp/Ldap/AbpLdapOptions.cs | 8 ++++++++
.../Volo.Abp.Ldap/Volo/Abp/Ldap/ILdapManager.cs | 10 ----------
.../src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapManager.cs | 14 +++++---------
.../Volo/Abp/Ldap/LdapSettingNames.cs | 2 ++
.../Volo/Abp/Ldap/LdapSettingProvider.cs | 6 ++++++
.../Volo/Abp/Ldap/Localization/en.json | 3 +++
.../Volo/Abp/Ldap/Localization/tr.json | 6 ++++++
.../Volo/Abp/Ldap/Localization/zh-Hans.json | 6 ++++++
.../Volo/Abp/Ldap/Localization/zh-Hant.json | 6 ++++++
.../Volo/Abp/Ldap/AbpLdapTestModule.cs | 3 ++-
.../Volo/Abp/Ldap/LdapManager_Tests.cs | 5 +----
12 files changed, 46 insertions(+), 24 deletions(-)
diff --git a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpAbpLdapOptionsFactory.cs b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpAbpLdapOptionsFactory.cs
index 0f7117a42a..9579e169be 100644
--- a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpAbpLdapOptionsFactory.cs
+++ b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpAbpLdapOptionsFactory.cs
@@ -34,6 +34,7 @@ namespace Volo.Abp.Ldap
{
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);
}
diff --git a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpLdapOptions.cs b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpLdapOptions.cs
index 38768581f4..ab9c2d12f2 100644
--- a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpLdapOptions.cs
+++ b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpLdapOptions.cs
@@ -6,8 +6,16 @@
public int ServerPort { get; set; }
+ public string BaseDc { get; set; }
+
+ ///
+ /// BindDN
+ ///
public string UserName { get; set; }
+ ///
+ ///BindPassword
+ ///
public string Password { get; set; }
}
}
diff --git a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/ILdapManager.cs b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/ILdapManager.cs
index 1943157fa8..6ad66b0cb3 100644
--- a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/ILdapManager.cs
+++ b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/ILdapManager.cs
@@ -2,16 +2,6 @@
{
public interface ILdapManager
{
- ///
- /// Authenticate with default username/password
- ///
- ///
- bool Authenticate();
-
- ///
- /// Authenticate with specified username/password
- ///
- ///
bool Authenticate(string username, string password);
}
}
diff --git a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapManager.cs b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapManager.cs
index 61b8f608d1..2d890c10f7 100644
--- a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapManager.cs
+++ b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapManager.cs
@@ -19,18 +19,15 @@ namespace Volo.Abp.Ldap
Logger = NullLogger.Instance;
}
- public virtual bool Authenticate()
- {
- return Authenticate(LdapOptions.UserName, LdapOptions.Password);
- }
-
public bool Authenticate(string username, string password)
{
try
{
- var conn = CreateLdapConnection();
- AuthenticateLdapConnection(conn, username, password);
- return true;
+ using (var conn = CreateLdapConnection())
+ {
+ AuthenticateLdapConnection(conn, username, password);
+ return true;
+ }
}
catch (Exception ex)
{
@@ -47,7 +44,6 @@ namespace Volo.Abp.Ldap
return ldapConnection;
}
-
protected virtual void ConfigureLdapConnection(ILdapConnection connection)
{
diff --git a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapSettingNames.cs b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapSettingNames.cs
index 62fa58b49f..14b2546bbf 100644
--- a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapSettingNames.cs
+++ b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapSettingNames.cs
@@ -6,6 +6,8 @@
public const string ServerPort = "Abp.Ldap.ServerPort";
+ public const string BaseDc = "Abp.Ldap.BaseDc";
+
public const string UserName = "Abp.Ldap.UserName";
public const string Password = "Abp.Ldap.Password";
diff --git a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapSettingProvider.cs b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapSettingProvider.cs
index 4549e1d8a0..edcfc2e4ef 100644
--- a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapSettingProvider.cs
+++ b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapSettingProvider.cs
@@ -21,6 +21,12 @@ namespace Volo.Abp.Ldap
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,
"",
diff --git a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/en.json b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/en.json
index e1894aa9d0..1d720fc26f 100644
--- a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/en.json
+++ b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/en.json
@@ -7,6 +7,9 @@
"DisplayName:Abp.Ldap.ServerPort": "Server port",
"Description:Abp.Ldap.ServerPort": "Server port",
+ "DisplayName:Abp.Ldap.BaseDc": "Base domain component",
+ "Description:Abp.Ldap.BaseDc": "Base domain component",
+
"DisplayName:Abp.Ldap.UserName": "Username",
"Description:Abp.Ldap.UserName": "Username",
diff --git a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/tr.json b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/tr.json
index 078d403da8..7d04b9aa50 100644
--- a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/tr.json
+++ b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/tr.json
@@ -3,10 +3,16 @@
"texts": {
"DisplayName:Abp.Ldap.ServerHost": "Sunucu Ana Bilgisayarı",
"Description:Abp.Ldap.ServerHost": "Sunucu Ana Bilgisayarı",
+
"DisplayName:Abp.Ldap.ServerPort": "Sunucu portu",
"Description:Abp.Ldap.ServerPort": "Sunucu portu",
+
+ "DisplayName:Abp.Ldap.BaseDc": "Temel alan bileşeni",
+ "Description:Abp.Ldap.BaseDc": "Temel alan bileşeni",
+
"DisplayName:Abp.Ldap.UserName": "Kullanıcı adı",
"Description:Abp.Ldap.UserName": "Kullanıcı adı",
+
"DisplayName:Abp.Ldap.Password": "parola",
"Description:Abp.Ldap.Password": "parola"
}
diff --git a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/zh-Hans.json b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/zh-Hans.json
index 6cacad8746..7efddf2682 100644
--- a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/zh-Hans.json
+++ b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/zh-Hans.json
@@ -3,10 +3,16 @@
"texts": {
"DisplayName:Abp.Ldap.ServerHost": "服务器主机",
"Description:Abp.Ldap.ServerHost": "服务器主机",
+
"DisplayName:Abp.Ldap.ServerPort": "服务器端口",
"Description:Abp.Ldap.ServerPort": "服务器端口",
+
+ "DisplayName:Abp.Ldap.BaseDc": "基域组件",
+ "Description:Abp.Ldap.BaseDc": "基域组件",
+
"DisplayName:Abp.Ldap.UserName": "用户名",
"Description:Abp.Ldap.UserName": "用户名",
+
"DisplayName:Abp.Ldap.Password": "密码",
"Description:Abp.Ldap.Password": "密码"
}
diff --git a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/zh-Hant.json b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/zh-Hant.json
index 1fcf263ed1..d8e30ea362 100644
--- a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/zh-Hant.json
+++ b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/Localization/zh-Hant.json
@@ -3,10 +3,16 @@
"texts": {
"DisplayName:Abp.Ldap.ServerHost": "服務器主機",
"Description:Abp.Ldap.ServerHost": "服務器主機",
+
"DisplayName:Abp.Ldap.ServerPort": "服務器端口",
"Description:Abp.Ldap.ServerPort": "服務器端口",
+
+ "DisplayName:Abp.Ldap.BaseDc": "基域組件",
+ "Description:Abp.Ldap.BaseDc": "基域組件",
+
"DisplayName:Abp.Ldap.UserName": "用戶名",
"Description:Abp.Ldap.UserName": "用戶名",
+
"DisplayName:Abp.Ldap.Password": "密碼",
"Description:Abp.Ldap.Password": "密碼"
}
diff --git a/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/AbpLdapTestModule.cs b/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/AbpLdapTestModule.cs
index a9ab4a28ed..8297655891 100644
--- a/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/AbpLdapTestModule.cs
+++ b/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/AbpLdapTestModule.cs
@@ -16,7 +16,8 @@ namespace Volo.Abp.Ldap
{
options.ServerHost = "192.168.0.3";
options.ServerPort = 389;
- options.UserName = "cn=admin,dc=abp,dc=io";
+ options.BaseDc = "dc=abp,dc=io";
+ options.UserName = "admin";
options.Password = "123qwe";
});
}
diff --git a/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/LdapManager_Tests.cs b/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/LdapManager_Tests.cs
index 4cfc8718c8..8da9a9303d 100644
--- a/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/LdapManager_Tests.cs
+++ b/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/LdapManager_Tests.cs
@@ -1,5 +1,4 @@
-using System;
-using Shouldly;
+using Shouldly;
using Volo.Abp.Testing;
using Xunit;
@@ -22,10 +21,8 @@ namespace Volo.Abp.Ldap
[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);
}
-
}
}