diff --git a/common/ASC.Api.Core/Auth/ConfirmAuthHandler.cs b/common/ASC.Api.Core/Auth/ConfirmAuthHandler.cs index 717e186701..efcb88e617 100644 --- a/common/ASC.Api.Core/Auth/ConfirmAuthHandler.cs +++ b/common/ASC.Api.Core/Auth/ConfirmAuthHandler.cs @@ -10,6 +10,7 @@ using ASC.Core; using ASC.Security.Cryptography; using ASC.Web.Studio.Core; using Microsoft.AspNetCore.Authentication; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -105,4 +106,19 @@ namespace ASC.Api.Core.Auth return Task.FromResult(result); } } + + public static class ConfirmAuthHandlerExtension + { + public static IServiceCollection AddConfirmAuthHandler(this IServiceCollection services) + { + return services + .AddSecurityContextService() + .AddEmailValidationKeyProviderService() + .AddSetupInfo() + .AddTenantManagerService() + .AddUserManagerService() + .AddAuthManager() + .AddAuthContextService(); + } + } } diff --git a/common/ASC.Api.Core/Auth/CookieAuthHandler.cs b/common/ASC.Api.Core/Auth/CookieAuthHandler.cs index e85a22df26..5afe221d63 100644 --- a/common/ASC.Api.Core/Auth/CookieAuthHandler.cs +++ b/common/ASC.Api.Core/Auth/CookieAuthHandler.cs @@ -4,6 +4,7 @@ using System.Text.Encodings.Web; using System.Threading.Tasks; using ASC.Core; using Microsoft.AspNetCore.Authentication; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -35,4 +36,12 @@ namespace ASC.Api.Core.Auth ); } } + + public static class CookieAuthHandlerExtension + { + public static IServiceCollection AddCookieAuthHandler(this IServiceCollection services) + { + return services.AddSecurityContextService(); + } + } } diff --git a/common/ASC.Api.Core/Middleware/CultureMiddleware.cs b/common/ASC.Api.Core/Middleware/CultureMiddleware.cs index 0ecf69baca..9a5a7e9f5b 100644 --- a/common/ASC.Api.Core/Middleware/CultureMiddleware.cs +++ b/common/ASC.Api.Core/Middleware/CultureMiddleware.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using ASC.Core; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; namespace ASC.Api.Core.Middleware { @@ -48,5 +49,13 @@ namespace ASC.Api.Core.Middleware { return builder.UseMiddleware(); } + + public static IServiceCollection AddCultureMiddleware(this IServiceCollection services) + { + return services + .AddUserManagerService() + .AddTenantManagerService() + .AddAuthContextService(); + } } } diff --git a/common/ASC.Api.Core/Middleware/IpSecurityFilter.cs b/common/ASC.Api.Core/Middleware/IpSecurityFilter.cs index 07674271de..ea0bd6a238 100644 --- a/common/ASC.Api.Core/Middleware/IpSecurityFilter.cs +++ b/common/ASC.Api.Core/Middleware/IpSecurityFilter.cs @@ -4,6 +4,7 @@ using ASC.Core; using ASC.IPSecurity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace ASC.Api.Core.Middleware @@ -40,4 +41,15 @@ namespace ASC.Api.Core.Middleware } } } + + public static class IpSecurityFilterExtension + { + public static IServiceCollection AddIpSecurityFilter(this IServiceCollection services) + { + return services + .AddIPRestrictionsSettingsService() + .AddAuthContextService() + .AddIPSecurityService(); + } + } } diff --git a/common/ASC.Api.Core/Middleware/PaymentFilter.cs b/common/ASC.Api.Core/Middleware/PaymentFilter.cs index f00d74438c..5f3a8b6d57 100644 --- a/common/ASC.Api.Core/Middleware/PaymentFilter.cs +++ b/common/ASC.Api.Core/Middleware/PaymentFilter.cs @@ -7,6 +7,7 @@ using ASC.Web.Studio.Utility; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace ASC.Api.Core.Middleware @@ -46,4 +47,13 @@ namespace ASC.Api.Core.Middleware } } } + + public static class PaymentFilterExtension + { + public static IServiceCollection AddPaymentFilter(this IServiceCollection services) + { + return services + .AddTenantExtraService(); + } + } } diff --git a/common/ASC.Api.Core/Middleware/ProductSecurityFilter.cs b/common/ASC.Api.Core/Middleware/ProductSecurityFilter.cs index b9439b4a71..53335202ee 100644 --- a/common/ASC.Api.Core/Middleware/ProductSecurityFilter.cs +++ b/common/ASC.Api.Core/Middleware/ProductSecurityFilter.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Routing; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace ASC.Api.Core.Middleware @@ -119,4 +120,16 @@ namespace ASC.Api.Core.Middleware return default; } } + + public static class ProductSecurityFilterExtension + { + public static IServiceCollection AddProductSecurityFilter(this IServiceCollection services) + { + return services + .AddUserManagerService() + .AddTenantManagerService() + .AddWebItemSecurity() + .AddAuthContextService(); + } + } } diff --git a/common/ASC.Api.Core/Middleware/TenantStatusFilter.cs b/common/ASC.Api.Core/Middleware/TenantStatusFilter.cs index a84c5a9d19..8e0305c5e2 100644 --- a/common/ASC.Api.Core/Middleware/TenantStatusFilter.cs +++ b/common/ASC.Api.Core/Middleware/TenantStatusFilter.cs @@ -4,6 +4,7 @@ using ASC.Core; using ASC.Core.Tenants; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace ASC.Api.Core.Middleware @@ -42,4 +43,13 @@ namespace ASC.Api.Core.Middleware } } } + + public static class TenantStatusFilterExtension + { + public static IServiceCollection AddTenantStatusFilter(this IServiceCollection services) + { + return services + .AddTenantManagerService(); + } + } } diff --git a/common/ASC.Core.Common/Security/Authorizing/RoleProvider.cs b/common/ASC.Core.Common/Security/Authorizing/RoleProvider.cs index 45ab855a38..95eddda3a5 100644 --- a/common/ASC.Core.Common/Security/Authorizing/RoleProvider.cs +++ b/common/ASC.Core.Common/Security/Authorizing/RoleProvider.cs @@ -88,7 +88,7 @@ namespace ASC.Core.Security.Authorizing { public static IServiceCollection AddRoleProviderService(this IServiceCollection services) { - services.TryAddSingleton(typeof(IRoleProvider), typeof(RoleProvider)); + services.TryAddScoped(typeof(IRoleProvider), typeof(RoleProvider)); return services; } } diff --git a/products/ASC.People/Server/Startup.cs b/products/ASC.People/Server/Startup.cs index 42cd994644..84582c2036 100644 --- a/products/ASC.People/Server/Startup.cs +++ b/products/ASC.People/Server/Startup.cs @@ -72,6 +72,15 @@ namespace ASC.People var container = services.AddAutofac(Configuration, HostEnvironment.ContentRootPath); + services + .AddConfirmAuthHandler() + .AddCookieAuthHandler() + .AddCultureMiddleware() + .AddIpSecurityFilter() + .AddPaymentFilter() + .AddProductSecurityFilter() + .AddTenantStatusFilter(); + services.Configure(r => r.Name = "ASC"); services.Configure("ASC", r => r.Name = "ASC"); services.Configure("ASC.Api", r => r.Name = "ASC.Api"); diff --git a/web/ASC.Web.Api/Startup.cs b/web/ASC.Web.Api/Startup.cs index 244451a5fe..0eca8b4224 100644 --- a/web/ASC.Web.Api/Startup.cs +++ b/web/ASC.Web.Api/Startup.cs @@ -71,6 +71,15 @@ namespace ASC.Web.Api var container = services.AddAutofac(Configuration, HostEnvironment.ContentRootPath); + services + .AddConfirmAuthHandler() + .AddCookieAuthHandler() + .AddCultureMiddleware() + .AddIpSecurityFilter() + .AddPaymentFilter() + .AddProductSecurityFilter() + .AddTenantStatusFilter(); + services.Configure(r => r.Name = "ASC"); services.Configure("ASC", r => r.Name = "ASC"); services.Configure("ASC.Api", r => r.Name = "ASC.Api"); diff --git a/web/ASC.Web.Studio/Startup.cs b/web/ASC.Web.Studio/Startup.cs index 1a43e4fbdf..bcab969bb6 100644 --- a/web/ASC.Web.Studio/Startup.cs +++ b/web/ASC.Web.Studio/Startup.cs @@ -54,6 +54,7 @@ namespace ASC.Web.Studio services.Configure("default", r => { }); services + .AddCookieAuthHandler() .AddStorage() .AddPathUtilsService() .AddStorageHandlerService();