DocSpace-client/products/ASC.People/Server/Startup.cs

243 lines
10 KiB
C#
Raw Normal View History

2019-09-09 12:56:33 +00:00
using System.Configuration;
2019-07-29 10:51:14 +00:00
using ASC.Api.Core;
2019-09-10 12:42:15 +00:00
using ASC.Api.Core.Auth;
2019-07-09 10:29:53 +00:00
using ASC.Api.Core.Core;
using ASC.Api.Core.Middleware;
2019-09-09 12:56:33 +00:00
using ASC.Common.Data;
using ASC.Common.DependencyInjection;
2019-07-09 10:29:53 +00:00
using ASC.Common.Logging;
2019-09-09 12:56:33 +00:00
using ASC.Common.Security;
using ASC.Common.Security.Authorizing;
2019-07-09 10:29:53 +00:00
using ASC.Common.Utils;
2019-09-09 12:56:33 +00:00
using ASC.Core;
using ASC.Core.Billing;
using ASC.Core.Caching;
using ASC.Core.Common.Settings;
2019-09-09 12:56:33 +00:00
using ASC.Core.Data;
using ASC.Core.Notify;
using ASC.Core.Security.Authorizing;
2019-09-12 07:57:59 +00:00
using ASC.Core.Tenants;
using ASC.Data.Reassigns;
2019-09-13 11:18:27 +00:00
using ASC.Data.Storage;
2019-07-09 10:29:53 +00:00
using ASC.Data.Storage.Configuration;
2019-09-13 11:18:27 +00:00
using ASC.IPSecurity;
using ASC.MessagingSystem;
2019-09-09 12:56:33 +00:00
using ASC.Notify.Recipients;
2019-09-17 12:42:32 +00:00
using ASC.Security.Cryptography;
2019-07-09 10:29:53 +00:00
using ASC.Web.Core;
2019-09-09 12:56:33 +00:00
using ASC.Web.Core.Notify;
2019-08-01 08:47:15 +00:00
using ASC.Web.Core.Users;
2019-09-13 11:18:27 +00:00
using ASC.Web.Core.Utility;
using ASC.Web.Core.Utility.Settings;
2019-09-12 07:57:59 +00:00
using ASC.Web.Core.Utility.Skins;
2019-09-13 11:18:27 +00:00
using ASC.Web.Core.WhiteLabel;
2019-08-01 08:47:15 +00:00
using ASC.Web.Studio.Core.Notify;
2019-09-09 12:56:33 +00:00
using ASC.Web.Studio.UserControls.Statistics;
using ASC.Web.Studio.Utility;
2019-08-02 14:40:33 +00:00
using Microsoft.AspNetCore.Authentication;
2019-05-15 14:56:09 +00:00
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
2019-07-12 14:28:14 +00:00
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Formatters;
2019-05-15 14:56:09 +00:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
2019-05-15 14:56:09 +00:00
namespace ASC.People
{
public class Startup
{
2019-05-15 14:56:09 +00:00
public IConfiguration Configuration { get; }
public IHostEnvironment HostEnvironment { get; }
2019-05-15 14:56:09 +00:00
public Startup(IConfiguration configuration, IHostEnvironment hostEnvironment)
2019-05-15 14:56:09 +00:00
{
Configuration = configuration;
HostEnvironment = hostEnvironment;
}
2019-05-15 14:56:09 +00:00
public void ConfigureServices(IServiceCollection services)
{
2019-08-02 14:40:33 +00:00
services.AddHttpContextAccessor();
2019-09-09 12:56:33 +00:00
services.AddControllers().AddControllersAsServices()
.AddNewtonsoftJson()
.AddXmlSerializerFormatters();
services.AddTransient<IConfigureOptions<MvcNewtonsoftJsonOptions>, CustomJsonOptionsWrapper>();
2019-08-02 14:40:33 +00:00
services.AddMemoryCache();
services.AddDistributedMemoryCache();
services.AddSession();
2019-09-10 12:42:15 +00:00
services.AddAuthentication("cookie")
.AddScheme<AuthenticationSchemeOptions, CookieAuthHandler>("cookie", a => { })
.AddScheme<AuthenticationSchemeOptions, ConfirmAuthHandler>("confirm", a => { });
var builder = services.AddMvc(config =>
{
config.Filters.Add(new TypeFilterAttribute(typeof(TenantStatusFilter)));
config.Filters.Add(new TypeFilterAttribute(typeof(PaymentFilter)));
config.Filters.Add(new TypeFilterAttribute(typeof(IpSecurityFilter)));
config.Filters.Add(new TypeFilterAttribute(typeof(ProductSecurityFilter)));
config.Filters.Add(new CustomResponseFilterAttribute());
config.Filters.Add(new CustomExceptionFilterAttribute());
config.Filters.Add(new TypeFilterAttribute(typeof(FormatFilter)));
2019-07-24 10:48:45 +00:00
config.OutputFormatters.RemoveType<XmlSerializerOutputFormatter>();
config.OutputFormatters.Add(new XmlOutputFormatter());
});
var container = services.AddAutofac(Configuration, HostEnvironment.ContentRootPath);
services.AddLogManager()
.AddStorage()
.AddWebItemManager()
2019-09-09 12:56:33 +00:00
.AddSingleton((r) =>
{
var cs = DbRegistry.GetConnectionString("core");
if (cs == null)
{
throw new ConfigurationErrorsException("Can not configure CoreContext: connection string with name core not found.");
}
return (IUserService)new CachedUserService(new DbUserService(cs));
})
.AddSingleton((r) =>
{
var cs = DbRegistry.GetConnectionString("core");
if (cs == null)
{
throw new ConfigurationErrorsException("Can not configure CoreContext: connection string with name core not found.");
}
return (ITenantService)new CachedTenantService(new DbTenantService(cs));
})
.AddSingleton((r) =>
{
var quotaCacheEnabled = false;
if (Common.Utils.ConfigurationManager.AppSettings["core:enable-quota-cache"] == null)
{
quotaCacheEnabled = true;
}
else
{
quotaCacheEnabled = !bool.TryParse(Common.Utils.ConfigurationManager.AppSettings["core:enable-quota-cache"], out var enabled) || enabled;
}
var cs = DbRegistry.GetConnectionString("core");
if (cs == null)
{
throw new ConfigurationErrorsException("Can not configure CoreContext: connection string with name core not found.");
}
return quotaCacheEnabled ? (IQuotaService)new CachedQuotaService(new DbQuotaService(cs)) : new DbQuotaService(cs); ;
})
.AddSingleton((r) =>
{
var cs = DbRegistry.GetConnectionString("core");
if (cs == null)
{
throw new ConfigurationErrorsException("Can not configure CoreContext: connection string with name core not found.");
}
return (ITariffService)new TariffService(cs, r.GetService<IQuotaService>(), r.GetService<ITenantService>());
})
.AddScoped<ApiContext>()
.AddScoped<StudioNotifyService>()
.AddScoped<UserManagerWrapper>()
.AddScoped<MessageService>()
.AddScoped<QueueWorkerReassign>()
2019-09-09 12:56:33 +00:00
.AddScoped<QueueWorkerRemove>()
.AddScoped<TenantManager>()
.AddScoped<UserManager>()
.AddScoped<StudioNotifyHelper>()
.AddScoped<StudioNotifySource>()
.AddScoped<StudioNotifyServiceHelper>()
.AddScoped<AuthManager>()
.AddScoped<TenantExtra>()
.AddScoped<TenantStatisticsProvider>()
.AddScoped<SecurityContext>()
.AddScoped<AzManager>()
.AddScoped<WebItemSecurity>()
.AddScoped<UserPhotoManager>()
.AddScoped<CookiesManager>()
.AddScoped<PermissionContext>()
.AddScoped<AuthContext>()
.AddScoped<MessageFactory>()
2019-09-12 07:57:59 +00:00
.AddScoped<WebImageSupplier>()
.AddScoped<UserPhotoThumbnailSettings>()
.AddScoped<TenantCookieSettings>()
.AddScoped<WebItemManagerSecurity>()
.AddScoped<DbSettingsManager>()
.AddScoped<SettingsManager>()
2019-09-13 11:18:27 +00:00
.AddScoped<WebPath>()
.AddScoped<AdditionalWhiteLabelSettings>()
.AddScoped<TenantAccessSettings>()
.AddScoped<MailWhiteLabelSettings>()
.AddScoped<PasswordSettings>()
.AddScoped<StaticUploader>()
.AddScoped<CdnStorageSettings>()
.AddScoped<StorageFactory>()
.AddSingleton<StorageFactoryListener>()
.AddSingleton<StorageFactoryConfig>()
.AddScoped<StorageSettings>()
.AddScoped<IPRestrictionsSettings>()
.AddScoped<CustomNamingPeople>()
.AddScoped<PeopleNamesSettings>()
2019-09-17 12:42:32 +00:00
.AddScoped<EmailValidationKeyProvider>()
.AddScoped<TenantUtil>()
2019-09-13 11:18:27 +00:00
.AddSingleton<WebPathSettings>()
.AddSingleton<BaseStorageSettingsListener>()
2019-09-09 12:56:33 +00:00
.AddScoped(typeof(IRecipientProvider), typeof(RecipientProviderImpl))
.AddSingleton(typeof(IRoleProvider), typeof(RoleProvider))
.AddScoped(typeof(IPermissionResolver), typeof(PermissionResolver))
.AddScoped(typeof(IPermissionProvider), typeof(PermissionProvider))
;
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
2019-07-12 14:28:14 +00:00
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseCors(builder =>
builder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
app.UseRouting();
app.UseSession();
app.UseAuthentication();
2019-09-10 12:42:15 +00:00
app.UseAuthorization();
app.UseCultureMiddleware();
app.UseDisposeMiddleware();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapCustom();
});
app.UseCSP();
app.UseCm();
2019-07-08 11:57:03 +00:00
app.UseStaticFiles();
2019-05-15 14:56:09 +00:00
}
}
}