257 lines
11 KiB
C#
257 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.OpenApi.Models;
|
|
using Newtonsoft.Json.Converters;
|
|
using Serilog;
|
|
using CRIF.ACTion.Common.Parsers;
|
|
using CRIF.ACTion.Configuration;
|
|
using CRIF.ACTion.Decisioning;
|
|
using CRIF.ACTion.Loan;
|
|
using CRIF.ACTion.Loan.Individuals;
|
|
using CRIF.ACTion.Services.Crif;
|
|
using Landmark.OLA.Application.Common.Domain;
|
|
using Landmark.OLA.Application.Common.Security;
|
|
using Landmark.OLA.Application.Configuration;
|
|
using Landmark.OLA.Application.DataAccess;
|
|
using Landmark.OLA.Application.DataAccessLayer;
|
|
using Landmark.OLA.Application.Services;
|
|
using Landmark.OLA.Models;
|
|
using Landmark.OLA.Models.Addresses;
|
|
using Landmark.OLA.Models.Decisioning;
|
|
using Landmark.OLA.Models.Decisioning.Enums;
|
|
using Landmark.OLA.Models.Individuals;
|
|
using Landmark.OLA.Models.Loan;
|
|
using Landmark.OLA.Models.OnlineBanking;
|
|
using Landmark.OLA.Models.Vendor;
|
|
using OnlineBankingAuth.Communication;
|
|
using OnlineBankingAuth.Parsers;
|
|
using OnlineBankingAuth.Services;
|
|
using OnlineBankingAuth.Tokens;
|
|
using LCU.Library.Internal.Logging;
|
|
using LCU.Library.Internal.Logging.Middleware;
|
|
using LCU.Library.Internal.Logging.Models;
|
|
using LCU.Library.Internal.LcuHttpClient;
|
|
using Landmark.OLA.Application.Services.MicroApiServices;
|
|
using Landmark.OLA.Application.Services.Email;
|
|
|
|
namespace Landmark.OLA.Application
|
|
{
|
|
public class Startup(IConfiguration configuration)
|
|
{
|
|
public IConfiguration Configuration { get; } = configuration;
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
var appConfig = new ApplicationSettings();
|
|
Configuration.GetSection("Primary").Bind(appConfig);
|
|
|
|
services.AddSingleton(appConfig);
|
|
|
|
var loggerConfiguration = new LoggingConfiguration(appConfig.AppName,
|
|
appConfig.SeqKey,
|
|
appConfig.SeqUrl);
|
|
var lcuLogging = new LcuLogging(loggerConfiguration);
|
|
lcuLogging.UseLcuLogging();
|
|
|
|
Log.Information($"{appConfig.AppName} Starting Up");
|
|
|
|
services.AddLCUHttpServices();
|
|
|
|
services.AddCors(options =>
|
|
{
|
|
options.AddPolicy("DevCors", b => b
|
|
.SetIsOriginAllowed(_ => true)
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials());
|
|
|
|
options.AddPolicy("ProdCors", b => b
|
|
.WithOrigins(
|
|
"https://applydev.landmarkcu.com",
|
|
"https://applyqa.landmarkcu.com",
|
|
"https://apply.landmarkcu.com",
|
|
"https://qa-online-loan-app.apps.azure.lcu-internal.com",
|
|
"https://uat-online-loan-app.apps.azure.lcu-internal.com",
|
|
"https://prd-online-loan-app.apps.azure.lcu-internal.com",
|
|
"https://qa-apps.landmarkcu.com",
|
|
"https://uat-apps.landmarkcu.com",
|
|
"https://apps.landmarkcu.com")
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials());
|
|
});
|
|
|
|
services.AddControllers().AddNewtonsoftJson(o => o.SerializerSettings.Converters.Add(new StringEnumConverter()));
|
|
|
|
services.Configure<CookiePolicyOptions>(options =>
|
|
{
|
|
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
|
options.CheckConsentNeeded = context => false;
|
|
options.MinimumSameSitePolicy = SameSiteMode.None;
|
|
});
|
|
|
|
//TODO #245: Disable in production?
|
|
services.AddEndpointsApiExplorer();
|
|
services.AddSwaggerGen(c =>
|
|
{
|
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Landmark Loan API", Version = "v1" });
|
|
// For this to work, I also had to check the generate xml box in build options.
|
|
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
|
c.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
|
|
});
|
|
|
|
|
|
services.AddScoped<ICrifVendorClient, CrifVendorClient>();
|
|
services.AddScoped<IStatus, Status>();
|
|
|
|
services.Configure<DataAccessConnection>(options =>
|
|
Configuration.GetSection("ApplicationStorage").Bind(options));
|
|
services.AddSingleton<IDataClient, DataClient>();
|
|
services.AddScoped<ILoanApplicationDataAccess, LoanApplicationDataAccess>();
|
|
services.AddScoped<INotificationDao, NotificationDao>();
|
|
services.AddScoped<IBranchDataAccess, BranchDataAccess>();
|
|
services.AddScoped<IConfigurationAccess, ConfigurationAccess>();
|
|
|
|
services.AddScoped<ICrifService, CrifService>();
|
|
services.AddScoped<IWcfInspectorBehavior, WcfInspectorBehavior>();
|
|
|
|
services.AddScoped<IResponseParser<Individual>, AddIndividualResponseParser>();
|
|
services.AddScoped<IResponseParser<LoanApplication>, LoanApplicationResponseParser>();
|
|
services.AddScoped<IResponseParser<DecisioningState>, DecisioningStateResponseParser>();
|
|
services.AddScoped<IResponseParser<DecisioningDetails>, GetApplicationProductsResponseParser>();
|
|
services.AddScoped<IResponseParser<SortedList<int, string>>, ConfigurationRequestResponseParser>();
|
|
services.AddScoped<IResponseParser<Dictionary<string, string>>, ProductDetailsResponseParser>();
|
|
services.AddScoped<IResponseParser<CustomFieldConfigs>, CustomFieldRequestResponseParser>();
|
|
services.AddScoped<IResponseParser<DealershipAuthRequest>, DealershipResponseParser>();
|
|
|
|
services.AddSingleton<UiSettings>();
|
|
|
|
// Add USPS scopes
|
|
services.AddScoped<IUspsVendorClient, USPS.Communication.UspsVendorClient>();
|
|
services.AddScoped<USPS.Communication.IUspsService, USPS.Communication.UspsService>();
|
|
|
|
services.AddScoped<USPS.Parsers.IResponseParser<Address>, USPS.Parsers.AddressValidationResponseParser>();
|
|
services.Configure<ApplicationControlConfiguration>(options => Configuration.GetSection("ApplicationControl").Bind(options));
|
|
|
|
services.Configure<CrifSettings>(options =>
|
|
Configuration.GetSection("CrifSettings").Bind(options));
|
|
|
|
services.Configure<BlobStorageSettings>(options =>
|
|
Configuration.GetSection("BlobStorageSettings").Bind(options));
|
|
|
|
services.Configure<BlobStorageConnectionSettings>(options =>
|
|
Configuration.GetSection("BlobStorageConnectionSettings").Bind(options));
|
|
|
|
services.Configure<DealershipEmailSettings>(options =>
|
|
Configuration.GetSection("DealershipEmailSettings").Bind(options));
|
|
|
|
services.AddSingleton<IBlobStorageAccess, BlobStorageAccess>();
|
|
|
|
// Set up USPS
|
|
services.Configure<USPS.Configuration.UspsSettings>(options =>
|
|
Configuration.GetSection("UspsSettings").Bind(options));
|
|
|
|
// Setup up Email
|
|
services.Configure<NotificationsApiConfiguration>(options =>
|
|
Configuration.GetSection("NotificationsApiConfiguration").Bind(options));
|
|
services.AddScoped<INotificationsApiService, NotificationsApiService>();
|
|
services.AddSingleton<IEmailTemplateService, EmailTemplateService>();
|
|
|
|
// Setup up Core
|
|
var coreSettings = new CoreSettings();
|
|
Configuration.GetSection("CoreSettings").Bind(coreSettings);
|
|
services.AddSingleton(coreSettings);
|
|
services.AddScoped<ICoreService, CoreService>();
|
|
services.AddScoped<IPdfService, PdfService>();
|
|
|
|
// Set up SAML IdP scopes
|
|
services.AddScoped<ITokenService, TokenService>();
|
|
services.AddScoped<ISAMLParser<DISAMLAssertion>, SAMLParser>();
|
|
|
|
// Set up SAML IdP configuration
|
|
services.Configure<OnlineBankingAuth.Configuration.SecuritySettings>(options =>
|
|
{
|
|
Configuration.GetSection("SecuritySettings").Bind(options);
|
|
});
|
|
|
|
// Setup DI service
|
|
services.AddScoped<IDigitalInsightVendorClient, DigitalInsightVendorClient>();
|
|
services.AddScoped<IDigitalInsightService, DigitalInsightService>();
|
|
services.AddScoped<IAuthTokenParser, AuthTokenParser>();
|
|
|
|
//Set up Authentication
|
|
services
|
|
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
// AzureAD config
|
|
.AddAzureAdBearer(options => Configuration.Bind("AzureActiveDirectory", options));
|
|
|
|
services.AddAuthorization();
|
|
services.AddDistributedMemoryCache();
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationSettings appSettings)
|
|
{
|
|
Log.Information("Configuring...");
|
|
|
|
var policyCollection = new HeaderPolicyCollection()
|
|
.AddDefaultSecurityHeaders()
|
|
.AddCustomHeader("Cache-Control", "no-cache")
|
|
.AddCustomHeader("Arr-Disable-Session-Affinity", "true");
|
|
|
|
app.UseCookiePolicy(new CookiePolicyOptions
|
|
{
|
|
CheckConsentNeeded = context => false,
|
|
MinimumSameSitePolicy = SameSiteMode.None
|
|
});
|
|
|
|
|
|
app.UseSecurityHeaders(policyCollection);
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Landmark Loan API"));
|
|
|
|
app.UseMiddleware<RequestResponseLoggingMiddleware>();
|
|
app.UseSerilogRequestLogging(options =>
|
|
{
|
|
options.EnrichDiagnosticContext = RequestResponseLoggingMiddleware.RequestDataParser.EnrichFromRequest;
|
|
});
|
|
}
|
|
else
|
|
{
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")?.Equals("Development", StringComparison.OrdinalIgnoreCase) ?? false)
|
|
app.UseCors("DevCors");
|
|
else
|
|
app.UseCors("ProdCors");
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
|
}
|
|
}
|
|
}
|