|
|
|
|
using AuthServer.Host.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using StackExchange.Redis;
|
|
|
|
|
using Volo.Abp;
|
|
|
|
|
using Volo.Abp.Account.Web;
|
|
|
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
|
|
|
|
|
using Volo.Abp.Auditing;
|
|
|
|
|
using Volo.Abp.AuditLogging.EntityFrameworkCore;
|
|
|
|
|
using Volo.Abp.Authorization.Permissions;
|
|
|
|
|
using Volo.Abp.EventBus.RabbitMq;
|
|
|
|
|
using Volo.Abp.Autofac;
|
|
|
|
|
using Volo.Abp.EntityFrameworkCore;
|
|
|
|
|
using Volo.Abp.EntityFrameworkCore.SqlServer;
|
|
|
|
|
using Volo.Abp.Identity;
|
|
|
|
|
using Volo.Abp.Identity.EntityFrameworkCore;
|
|
|
|
|
using Volo.Abp.IdentityServer.EntityFrameworkCore;
|
|
|
|
|
using Volo.Abp.Localization;
|
|
|
|
|
using Volo.Abp.Modularity;
|
|
|
|
|
using Volo.Abp.PermissionManagement;
|
|
|
|
|
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
|
|
|
|
|
using Volo.Abp.SettingManagement.EntityFrameworkCore;
|
|
|
|
|
using Volo.Abp.Threading;
|
|
|
|
|
|
|
|
|
|
namespace AuthServer.Host
|
|
|
|
|
{
|
|
|
|
|
[DependsOn(
|
|
|
|
|
typeof(AbpAutofacModule),
|
|
|
|
|
typeof(AbpEventBusRabbitMqModule),
|
|
|
|
|
typeof(AbpPermissionManagementEntityFrameworkCoreModule),
|
|
|
|
|
typeof(AbpAuditLoggingEntityFrameworkCoreModule),
|
|
|
|
|
typeof(AbpSettingManagementEntityFrameworkCoreModule),
|
|
|
|
|
typeof(AbpIdentityEntityFrameworkCoreModule),
|
|
|
|
|
typeof(AbpIdentityApplicationContractsModule),
|
|
|
|
|
typeof(AbpIdentityServerEntityFrameworkCoreModule),
|
|
|
|
|
typeof(AbpEntityFrameworkCoreSqlServerModule),
|
|
|
|
|
typeof(AbpAccountWebIdentityServerModule),
|
|
|
|
|
typeof(AbpAspNetCoreMvcUiBasicThemeModule)
|
|
|
|
|
)]
|
|
|
|
|
public class AuthServerHostModule : AbpModule
|
|
|
|
|
{
|
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
|
|
|
{
|
|
|
|
|
var configuration = context.Services.GetConfiguration();
|
|
|
|
|
|
|
|
|
|
context.Services.AddAbpDbContext<AuthServerDbContext>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.AddDefaultRepositories();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Configure<AbpDbContextOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.UseSqlServer();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Configure<AbpLocalizationOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.Languages.Add(new LanguageInfo("en", "en", "English"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.Services.AddDistributedRedisCache(options =>
|
|
|
|
|
{
|
|
|
|
|
options.Configuration = configuration["Redis:Configuration"];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Configure<AbpAuditingOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.IsEnabledForGetRequests = true;
|
|
|
|
|
options.ApplicationName = "AuthServer";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
|
|
|
|
|
context.Services.AddDataProtection()
|
|
|
|
|
.PersistKeysToStackExchangeRedis(redis, "MsDemo-DataProtection-Keys");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
|
|
|
{
|
|
|
|
|
var app = context.GetApplicationBuilder();
|
|
|
|
|
|
|
|
|
|
app.UseCorrelationId();
|
|
|
|
|
app.UseVirtualFiles();
|
|
|
|
|
app.UseIdentityServer();
|
|
|
|
|
app.UseAbpRequestLocalization();
|
|
|
|
|
app.UseAuditing();
|
|
|
|
|
app.UseMvcWithDefaultRouteAndArea();
|
|
|
|
|
|
|
|
|
|
//TODO: Problem on a clustered environment
|
|
|
|
|
using (var scope = context.ServiceProvider.CreateScope())
|
|
|
|
|
{
|
|
|
|
|
AsyncHelper.RunSync(async () =>
|
|
|
|
|
{
|
|
|
|
|
await scope.ServiceProvider
|
|
|
|
|
.GetRequiredService<IIdentityDataSeeder>()
|
|
|
|
|
.SeedAsync(
|
|
|
|
|
adminUserPassword: "1q2w3E*"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await scope.ServiceProvider
|
|
|
|
|
.GetRequiredService<IPermissionDataSeeder>()
|
|
|
|
|
.SeedAsync(
|
|
|
|
|
RolePermissionValueProvider.ProviderName,
|
|
|
|
|
"admin",
|
|
|
|
|
IdentityPermissions.GetAll()
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|