patch ldap
This commit is contained in:
parent
3db3ebeec6
commit
b5c54b1d8d
@ -19,13 +19,13 @@ namespace LdapLoginLib.Data
|
||||
private static string? AdminPassword { get; set; } = null;
|
||||
|
||||
|
||||
static LdapConfig()
|
||||
internal LdapConfig()
|
||||
{
|
||||
//string? mode = Environment.GetEnvironmentVariable("Mode");
|
||||
ReadCredentials();
|
||||
}
|
||||
|
||||
private static void ReadCredentials()
|
||||
private void ReadCredentials()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -79,19 +79,18 @@ namespace LdapLoginLib.Data
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal static NetworkCredential AdminCredential()
|
||||
internal NetworkCredential AdminCredential()
|
||||
{
|
||||
return new NetworkCredential($"uid={AdminUser},{AdminDn}", AdminPassword);
|
||||
}
|
||||
|
||||
internal static NetworkCredential UserCredentials(string username, string password)
|
||||
internal NetworkCredential UserCredentials(string username, string password)
|
||||
{
|
||||
return new NetworkCredential($"uid={username},{UserDn}", password);
|
||||
}
|
||||
|
||||
|
||||
internal static LdapConnection Connection()
|
||||
internal LdapConnection Connection()
|
||||
{
|
||||
return new LdapConnection($"{ServerIP}:{ServerPort}");
|
||||
}
|
||||
|
@ -6,17 +6,17 @@ namespace LdapLoginLib
|
||||
{
|
||||
public class LDAP
|
||||
{
|
||||
private readonly LdapConfig _ldap;// = new();
|
||||
private static readonly LdapConfig _ldap = new();
|
||||
|
||||
public LDAP()
|
||||
{
|
||||
_ldap = new LdapConfig();
|
||||
}
|
||||
//public LDAP()
|
||||
//{
|
||||
// _ldap = new LdapConfig();
|
||||
//}
|
||||
|
||||
public bool Login(string password, string? document = null, string? username = null, string? email = null)
|
||||
{
|
||||
|
||||
using (LdapConnection ldapConnection = LdapConfig.Connection())
|
||||
using (LdapConnection ldapConnection = _ldap.Connection())
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -31,7 +31,7 @@ namespace LdapLoginLib
|
||||
// Set LDAP connection options
|
||||
ldapConnection.SessionOptions.SecureSocketLayer = false;
|
||||
ldapConnection.AuthType = AuthType.Basic;
|
||||
ldapConnection.Credential = LdapConfig.UserCredentials(userInfo.Usuario!, password);
|
||||
ldapConnection.Credential = _ldap.UserCredentials(userInfo.Usuario!, password);
|
||||
|
||||
// Attempt to bind (authenticate) the user
|
||||
ldapConnection.Bind();
|
||||
@ -88,14 +88,14 @@ namespace LdapLoginLib
|
||||
|
||||
#endregion
|
||||
|
||||
using (LdapConnection ldapConnection = LdapConfig.Connection())
|
||||
using (LdapConnection ldapConnection = _ldap.Connection())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Admin login
|
||||
ldapConnection.SessionOptions.SecureSocketLayer = false;
|
||||
ldapConnection.AuthType = AuthType.Basic;
|
||||
ldapConnection.Credential = LdapConfig.AdminCredential();
|
||||
ldapConnection.Credential = _ldap.AdminCredential();
|
||||
ldapConnection.Bind();
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user