Add ldapS option

This commit is contained in:
Marcio
2024-07-25 00:04:43 -03:00
parent c9657dd57d
commit 46b737434e
5 changed files with 53 additions and 4 deletions
@@ -9,7 +9,7 @@
<UserSecretsId>d52504e9-ea6e-4152-a52e-467ca002e47c</UserSecretsId> <UserSecretsId>d52504e9-ea6e-4152-a52e-467ca002e47c</UserSecretsId>
<AssemblyVersion>$(PackageVersion)</AssemblyVersion> <AssemblyVersion>$(PackageVersion)</AssemblyVersion>
<FileVersion>$(PackageVersion)</FileVersion> <FileVersion>$(PackageVersion)</FileVersion>
<Version>1.0.0.2</Version> <Version>1.0.0.3</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -3,6 +3,8 @@
public class LdapConfigs public class LdapConfigs
{ {
public string Server { get; set; } public string Server { get; set; }
public int Port { get; set; }
public bool UseSSL { get; set; }
public string DomainName { get; set; } public string DomainName { get; set; }
public string User { get; set; } public string User { get; set; }
public string Pass { get; set; } public string Pass { get; set; }
+6 -1
View File
@@ -30,12 +30,17 @@ builder.Services.AddSwaggerGen(s =>
builder.Services.AddSingleton(provider => builder.Services.AddSingleton(provider =>
{ {
var configs = builder.Configuration.GetSection(nameof(LdapConfigs)).Get<LdapConfigs>(); var configs = builder.Configuration.GetSection(nameof(LdapConfigs)).Get<LdapConfigs>();
var endpoint = new LdapDirectoryIdentifier(configs.Server, false, false); var endpoint = new LdapDirectoryIdentifier(configs.Server, configs.Port, configs.UseSSL ? true : false, false);
var ldapConnection = new LdapConnection(endpoint, var ldapConnection = new LdapConnection(endpoint,
new NetworkCredential($"{configs.User}@{configs.DomainName}", configs.Pass)) new NetworkCredential($"{configs.User}@{configs.DomainName}", configs.Pass))
{ {
AuthType = AuthType.Basic AuthType = AuthType.Basic
}; };
if (configs.UseSSL)
{
ldapConnection.SessionOptions.SecureSocketLayer = true;
ldapConnection.SessionOptions.VerifyServerCertificate = (con, cert) => true;
}
ldapConnection.SessionOptions.ReferralChasing = ReferralChasingOptions.None; ldapConnection.SessionOptions.ReferralChasing = ReferralChasingOptions.None;
ldapConnection.Bind(); ldapConnection.Bind();
return ldapConnection; return ldapConnection;
@@ -2,7 +2,27 @@
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
"Microsoft.AspNetCore": "Warning" "Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"System.Net.Http.HttpClient": "Warning"
},
"Console": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"System.Net.Http.HttpClient": "Warning"
},
"FormatterName": "json",
"FormatterOptions": {
"SingleLine": true,
"IncludeScopes": false,
"TimestampFormat": "dd/MM/yyyy HH:mm:ss",
"UseUtcTimestamp": false,
"JsonWriterOptions": {
"Indented": false
}
}
} }
} }
} }
+23 -1
View File
@@ -2,12 +2,34 @@
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
"Microsoft.AspNetCore": "Warning" "Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"System.Net.Http.HttpClient": "Warning"
},
"Console": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"System.Net.Http.HttpClient": "Warning"
},
"FormatterName": "json",
"FormatterOptions": {
"SingleLine": true,
"IncludeScopes": false,
"TimestampFormat": "dd/MM/yyyy HH:mm:ss",
"UseUtcTimestamp": false,
"JsonWriterOptions": {
"Indented": false
}
}
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"LdapConfigs": { "LdapConfigs": {
"Server": "192.168.100.25", "Server": "192.168.100.25",
"Port": 636,
"UseSSL": true,
"DomainName": "AD", // (pre-Windows 2000) "DomainName": "AD", // (pre-Windows 2000)
"User": "ldapAdmin", "User": "ldapAdmin",
"Pass": "Thi$1sMyPassw0rd", "Pass": "Thi$1sMyPassw0rd",