DI: filters and handlers

This commit is contained in:
pavelbannov 2019-11-01 12:37:02 +03:00
parent c54f575c26
commit 0be2995e83
11 changed files with 99 additions and 1 deletions

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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<CultureMiddleware>();
}
public static IServiceCollection AddCultureMiddleware(this IServiceCollection services)
{
return services
.AddUserManagerService()
.AddTenantManagerService()
.AddAuthContextService();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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;
}
}

View File

@ -72,6 +72,15 @@ namespace ASC.People
var container = services.AddAutofac(Configuration, HostEnvironment.ContentRootPath);
services
.AddConfirmAuthHandler()
.AddCookieAuthHandler()
.AddCultureMiddleware()
.AddIpSecurityFilter()
.AddPaymentFilter()
.AddProductSecurityFilter()
.AddTenantStatusFilter();
services.Configure<LogNLog>(r => r.Name = "ASC");
services.Configure<LogNLog>("ASC", r => r.Name = "ASC");
services.Configure<LogNLog>("ASC.Api", r => r.Name = "ASC.Api");

View File

@ -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<LogNLog>(r => r.Name = "ASC");
services.Configure<LogNLog>("ASC", r => r.Name = "ASC");
services.Configure<LogNLog>("ASC.Api", r => r.Name = "ASC.Api");

View File

@ -54,6 +54,7 @@ namespace ASC.Web.Studio
services.Configure<DbManager>("default", r => { });
services
.AddCookieAuthHandler()
.AddStorage()
.AddPathUtilsService()
.AddStorageHandlerService();