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

159 lines
5.6 KiB
C#
Raw Normal View History

2019-09-09 12:56:33 +00:00
2019-10-22 11:21:44 +00:00
using System;
2020-05-27 13:19:58 +00:00
using System.Text.Json.Serialization;
2019-12-20 11:17:01 +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;
2020-02-17 08:58:14 +00:00
using ASC.Common;
using ASC.Common.DependencyInjection;
2019-07-09 10:29:53 +00:00
using ASC.Common.Logging;
2019-10-22 11:21:44 +00:00
using ASC.Common.Threading.Progress;
using ASC.Common.Threading.Workers;
using ASC.Data.Reassigns;
2019-10-31 11:28:30 +00:00
using ASC.Employee.Core.Controllers;
2019-08-01 08:47:15 +00:00
using ASC.Web.Core.Users;
2019-08-02 14:40:33 +00:00
using Microsoft.AspNetCore.Authentication;
2019-11-13 15:11:30 +00:00
using Microsoft.AspNetCore.Authorization;
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;
2019-11-13 15:11:30 +00:00
using Microsoft.AspNetCore.Mvc.Authorization;
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;
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();
2020-02-20 14:57:48 +00:00
services.AddControllers()
.AddXmlSerializerFormatters()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.WriteIndented = false;
options.JsonSerializerOptions.IgnoreNullValues = true;
options.JsonSerializerOptions.Converters.Add(new ApiDateTimeConverter());
2020-05-27 13:19:58 +00:00
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});
2019-08-02 14:40:33 +00:00
2019-09-10 12:42:15 +00:00
services.AddAuthentication("cookie")
2020-02-20 14:57:48 +00:00
.AddScheme<AuthenticationSchemeOptions, CookieAuthHandler>("cookie", a => { })
.AddScheme<AuthenticationSchemeOptions, ConfirmAuthHandler>("confirm", a => { });
2020-02-20 14:57:48 +00:00
var builder = services.AddMvcCore(config =>
{
2019-11-13 15:11:30 +00:00
var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
config.Filters.Add(new AuthorizeFilter(policy));
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());
});
2020-02-17 08:58:14 +00:00
var diHelper = new DIHelper(services);
2020-02-20 14:57:48 +00:00
2020-02-17 08:58:14 +00:00
diHelper
2019-11-01 09:37:02 +00:00
.AddConfirmAuthHandler()
.AddCookieAuthHandler()
.AddCultureMiddleware()
.AddIpSecurityFilter()
.AddPaymentFilter()
.AddProductSecurityFilter()
.AddTenantStatusFilter();
2020-02-19 08:37:52 +00:00
diHelper.Configure<WorkerQueue<ResizeWorkerItem>>(r =>
2019-10-22 11:21:44 +00:00
{
r.workerCount = 2;
r.waitInterval = (int)TimeSpan.FromSeconds(30).TotalMilliseconds;
r.errorCount = 1;
r.stopAfterFinsih = true;
});
2020-02-19 08:37:52 +00:00
diHelper.Configure<ProgressQueue<ReassignProgressItem>>(r =>
2019-10-22 11:21:44 +00:00
{
r.workerCount = 1;
r.waitInterval = (int)TimeSpan.FromMinutes(5).TotalMilliseconds;
r.removeAfterCompleted = true;
r.stopAfterFinsih = false;
r.errorCount = 0;
});
2020-02-19 08:37:52 +00:00
diHelper.Configure<ProgressQueue<RemoveProgressItem>>(r =>
2019-10-22 11:21:44 +00:00
{
r.workerCount = 1;
r.waitInterval = (int)TimeSpan.FromMinutes(5).TotalMilliseconds;
r.removeAfterCompleted = true;
r.stopAfterFinsih = false;
r.errorCount = 0;
});
2020-02-17 08:58:14 +00:00
diHelper.AddNLogManager("ASC.Api", "ASC.Web");
2019-10-31 13:54:43 +00:00
2020-02-17 08:58:14 +00:00
diHelper
2019-10-31 11:28:30 +00:00
.AddPeopleController()
.AddGroupController();
2019-12-20 11:17:01 +00:00
services.AddAutofac(Configuration, HostEnvironment.ContentRootPath);
}
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.UseAuthentication();
2019-09-10 12:42:15 +00:00
app.UseAuthorization();
app.UseCultureMiddleware();
app.UseDisposeMiddleware();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapCustom();
});
2019-05-15 14:56:09 +00:00
}
}
}