diff --git a/LdapLoginLib/Data/LdapConfig.cs b/LdapLoginLib/Data/LdapConfig.cs index 26f8942..a9c05e8 100644 --- a/LdapLoginLib/Data/LdapConfig.cs +++ b/LdapLoginLib/Data/LdapConfig.cs @@ -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}"); } diff --git a/LdapLoginLib/LDAP.cs b/LdapLoginLib/LDAP.cs index 85e63ac..4075501 100644 --- a/LdapLoginLib/LDAP.cs +++ b/LdapLoginLib/LDAP.cs @@ -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();