diff --git a/common/ASC.ActiveDirectory/Base/LdapHelper.cs b/common/ASC.ActiveDirectory/Base/LdapHelper.cs index aad7cf9272..1a2d379cbd 100644 --- a/common/ASC.ActiveDirectory/Base/LdapHelper.cs +++ b/common/ASC.ActiveDirectory/Base/LdapHelper.cs @@ -23,15 +23,14 @@ public abstract class LdapHelper : IDisposable public abstract bool IsConnected { get; } protected readonly ILog Log; - - private readonly InstanceCrypto _instanceCrypto; + protected readonly InstanceCrypto InstanceCrypto; protected LdapHelper( IOptionsMonitor option, InstanceCrypto instanceCrypto) { Log = option.Get("ASC"); - _instanceCrypto = instanceCrypto; + InstanceCrypto = instanceCrypto; } public void Init(LdapSettings settings) @@ -108,7 +107,7 @@ public abstract class LdapHelper : IDisposable string password; try { - password = _instanceCrypto.Decrypt(passwordBytes); + password = InstanceCrypto.Decrypt(passwordBytes); } catch (Exception) { @@ -123,7 +122,7 @@ public abstract class LdapHelper : IDisposable try { - passwordBytes = _instanceCrypto.Encrypt(new UnicodeEncoding().GetBytes(password)); + passwordBytes = InstanceCrypto.Encrypt(new UnicodeEncoding().GetBytes(password)); } catch (Exception) { diff --git a/common/ASC.ActiveDirectory/Base/LdapNotifyHelper.cs b/common/ASC.ActiveDirectory/Base/LdapNotifyHelper.cs index 068de8622b..5ff274854d 100644 --- a/common/ASC.ActiveDirectory/Base/LdapNotifyHelper.cs +++ b/common/ASC.ActiveDirectory/Base/LdapNotifyHelper.cs @@ -23,7 +23,7 @@ public class LdapNotifyHelper private readonly DistributedTaskQueue _ldapTasks; private readonly IServiceProvider _serviceProvider; - LdapNotifyHelper( + public LdapNotifyHelper( IServiceProvider serviceProvider, DistributedTaskQueueOptionsManager distributedTaskQueueOptionsManager) { diff --git a/common/ASC.ActiveDirectory/ComplexOperations/LdapOperation.cs b/common/ASC.ActiveDirectory/ComplexOperations/LdapOperation.cs index a286598a93..93ea8b0f10 100644 --- a/common/ASC.ActiveDirectory/ComplexOperations/LdapOperation.cs +++ b/common/ASC.ActiveDirectory/ComplexOperations/LdapOperation.cs @@ -60,21 +60,16 @@ public abstract class LdapOperation public static LdapLocalization Resource { get; private set; } - protected IOptionsMonitor Options { get; private set; } - protected TenantManager TenantManager { get; private set; } - protected SecurityContext SecurityContext { get; private set; } - - protected NovellLdapHelper NovellLdapHelper { get; } - + private SecurityContext _securityContext; + private NovellLdapHelper _novellLdapHelper; private readonly IServiceProvider _serviceProvider; protected LdapOperation(IServiceProvider serviceProvider, IOptionsMonitor options) { _serviceProvider = serviceProvider; - Options = options; - Logger = Options.Get("ASC"); + Logger = options.Get("ASC"); } public void Init( @@ -107,9 +102,10 @@ public abstract class LdapOperation { using var scope = _serviceProvider.CreateScope(); TenantManager = scope.ServiceProvider.GetService(); - SecurityContext = scope.ServiceProvider.GetService(); + _securityContext = scope.ServiceProvider.GetService(); LDAPUserManager = scope.ServiceProvider.GetService(); LDAPUserManager.Init(Resource); + _novellLdapHelper = scope.ServiceProvider.GetService(); Importer = scope.ServiceProvider.GetService(); try @@ -118,7 +114,7 @@ public abstract class LdapOperation TenantManager.SetCurrentTenant(CurrentTenant); - SecurityContext.AuthenticateMe(Core.Configuration.Constants.CoreSystem); + _securityContext.AuthenticateMe(Core.Configuration.Constants.CoreSystem); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(_culture); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(_culture); @@ -221,7 +217,7 @@ public abstract class LdapOperation { TaskInfo.SetProperty(FINISHED, true); PublishTaskInfo(); - SecurityContext.Logout(); + _securityContext.Logout(); } catch (Exception ex) { @@ -397,7 +393,7 @@ public abstract class LdapOperation { if (!string.IsNullOrEmpty(settings.Password)) { - settings.PasswordBytes = NovellLdapHelper.GetPasswordBytes(settings.Password); + settings.PasswordBytes = _novellLdapHelper.GetPasswordBytes(settings.Password); if (settings.PasswordBytes == null) { diff --git a/common/ASC.ActiveDirectory/GlobalUsings.cs b/common/ASC.ActiveDirectory/GlobalUsings.cs index 6458621cf3..45679a1bb6 100644 --- a/common/ASC.ActiveDirectory/GlobalUsings.cs +++ b/common/ASC.ActiveDirectory/GlobalUsings.cs @@ -44,6 +44,7 @@ global using ASC.Web.Studio.Utility; global using Microsoft.Extensions.Configuration; global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Extensions.Hosting; global using Microsoft.Extensions.Options; global using Novell.Directory.Ldap; diff --git a/common/ASC.ActiveDirectory/Novell/NovellLdapHelper.cs b/common/ASC.ActiveDirectory/Novell/NovellLdapHelper.cs index 6583d74ca3..c1b99d1d00 100644 --- a/common/ASC.ActiveDirectory/Novell/NovellLdapHelper.cs +++ b/common/ASC.ActiveDirectory/Novell/NovellLdapHelper.cs @@ -19,15 +19,14 @@ namespace ASC.ActiveDirectory.Novell; [Scope] public class NovellLdapHelper : LdapHelper { - public NovellLdapSearcher LDAPSearcher { get; private set; } - + private readonly NovellLdapSearcher _lDAPSearcher; private readonly IConfiguration _configuration; private readonly IServiceProvider _serviceProvider; public NovellLdapHelper(IServiceProvider serviceProvider, IOptionsMonitor option, InstanceCrypto instanceCrypto, IConfiguration configuration, NovellLdapSearcher novellLdapSearcher) : base(option, instanceCrypto) { - LDAPSearcher = novellLdapSearcher; + _lDAPSearcher = novellLdapSearcher; _configuration = configuration; _serviceProvider = serviceProvider; @@ -39,7 +38,7 @@ public class NovellLdapHelper : LdapHelper ? GetPassword(settings.PasswordBytes) : settings.Password; - LDAPSearcher.Init(settings.Login, password, settings.Server, settings.PortNumber, + _lDAPSearcher.Init(settings.Login, password, settings.Server, settings.PortNumber, settings.StartTls, settings.Ssl, settings.AcceptCertificate, settings.AcceptCertificateHash); base.Init(settings); @@ -47,20 +46,20 @@ public class NovellLdapHelper : LdapHelper public override bool IsConnected { - get { return LDAPSearcher.IsConnected; } + get { return _lDAPSearcher.IsConnected; } } public override void Connect() { - LDAPSearcher.Connect(); + _lDAPSearcher.Connect(); - Settings.AcceptCertificate = LDAPSearcher.AcceptCertificate; - Settings.AcceptCertificateHash = LDAPSearcher.AcceptCertificateHash; + Settings.AcceptCertificate = _lDAPSearcher.AcceptCertificate; + Settings.AcceptCertificateHash = _lDAPSearcher.AcceptCertificateHash; } public override Dictionary GetCapabilities() { - return LDAPSearcher.GetCapabilities(); + return _lDAPSearcher.GetCapabilities(); } public override string SearchDomain() @@ -122,7 +121,7 @@ public class NovellLdapHelper : LdapHelper try { var searchResult = - LDAPSearcher.Search(Settings.UserDN, NovellLdapSearcher.LdapScope.Sub, Settings.UserFilter, limit: 1) + _lDAPSearcher.Search(Settings.UserDN, NovellLdapSearcher.LdapScope.Sub, Settings.UserFilter, limit: 1) .FirstOrDefault(); return searchResult != null ? LdapObjectExtension.GetDomainFromDn(searchResult) : null; @@ -147,7 +146,7 @@ public class NovellLdapHelper : LdapHelper { string[] attributes = { LdapConstants.ADSchemaAttributes.OBJECT_CLASS }; - var searchResult = LDAPSearcher.Search(userDn, NovellLdapSearcher.LdapScope.Base, + var searchResult = _lDAPSearcher.Search(userDn, NovellLdapSearcher.LdapScope.Base, LdapConstants.OBJECT_FILTER, attributes, 1); if (searchResult.Any()) @@ -161,7 +160,7 @@ public class NovellLdapHelper : LdapHelper { string[] attributes = { LdapConstants.ADSchemaAttributes.OBJECT_CLASS }; - var searchResult = LDAPSearcher.Search(groupDn, NovellLdapSearcher.LdapScope.Base, + var searchResult = _lDAPSearcher.Search(groupDn, NovellLdapSearcher.LdapScope.Base, LdapConstants.OBJECT_FILTER, attributes, 1); if (searchResult.Any()) @@ -193,7 +192,7 @@ public class NovellLdapHelper : LdapHelper ? Settings.UserFilter : string.Format("(&{0}{1})", Settings.UserFilter, filter); - list = LDAPSearcher.Search(Settings.UserDN, NovellLdapSearcher.LdapScope.Sub, searchfilter, limit: limit); + list = _lDAPSearcher.Search(Settings.UserDN, NovellLdapSearcher.LdapScope.Sub, searchfilter, limit: limit); return list; } @@ -230,7 +229,7 @@ public class NovellLdapHelper : LdapHelper var searchfilter = string.Format("(&{0}{1})", Settings.UserFilter, criteria); - var list = LDAPSearcher.Search(Settings.UserDN, NovellLdapSearcher.LdapScope.Sub, searchfilter, limit: 1); + var list = _lDAPSearcher.Search(Settings.UserDN, NovellLdapSearcher.LdapScope.Sub, searchfilter, limit: 1); return list.FirstOrDefault(); } @@ -259,7 +258,7 @@ public class NovellLdapHelper : LdapHelper : string.Format("(&{0}{1})", Settings.GroupFilter, criteria); - list = LDAPSearcher.Search(Settings.GroupDN, NovellLdapSearcher.LdapScope.Sub, searchfilter); + list = _lDAPSearcher.Search(Settings.GroupDN, NovellLdapSearcher.LdapScope.Sub, searchfilter); } catch (Exception e) { @@ -271,6 +270,6 @@ public class NovellLdapHelper : LdapHelper public override void Dispose() { - LDAPSearcher.Dispose(); + _lDAPSearcher.Dispose(); } }