committed by
GitHub
61 changed files with 3359 additions and 2820 deletions
@ -1,114 +0,0 @@ |
|||||
{ |
|
||||
"App": { |
|
||||
"TrackingEntitiesChanged": true, |
|
||||
"SelfUrl": "http://localhost:44385/", |
|
||||
"CorsOrigins": "http://localhost:4200,http://localhost:9528,http://127.0.0.1:63898" |
|
||||
}, |
|
||||
"AppSelfUrl": "http://localhost:44385/", |
|
||||
"ConnectionStrings": { |
|
||||
"Default": "Server=127.0.0.1;Database=IdentityServer;User Id=root;Password=123456", |
|
||||
"AbpIdentity": "Server=127.0.0.1;Database=IdentityServer;User Id=root;Password=123456", |
|
||||
"AbpIdentityServer": "Server=127.0.0.1;Database=IdentityServer;User Id=root;Password=123456", |
|
||||
"AbpTenantManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpSettingManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpPermissionManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpFeatureManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456" |
|
||||
}, |
|
||||
"CAP": { |
|
||||
"EventBus": { |
|
||||
"DefaultGroupName": "AuthServer", |
|
||||
"Version": "v1", |
|
||||
"FailedRetryInterval": 300, |
|
||||
"FailedRetryCount": 10 |
|
||||
}, |
|
||||
"RabbitMQ": { |
|
||||
"HostName": "127.0.0.1", |
|
||||
"Port": 5672, |
|
||||
"UserName": "admin", |
|
||||
"Password": "admin", |
|
||||
"ExchangeName": "LINGYUN.AbpApplication", |
|
||||
"VirtualHost": "multi.service.test" |
|
||||
} |
|
||||
}, |
|
||||
"Redis": { |
|
||||
"Configuration": "127.0.0.1", |
|
||||
"InstanceName": "LINGYUN.AbpApplication", |
|
||||
"DefaultDatabase": 10 |
|
||||
}, |
|
||||
"AuthServer": { |
|
||||
"Authority": "http://localhost:44385/", |
|
||||
"ApiName": "lingyun-abp-application" |
|
||||
}, |
|
||||
"IdentityServer": { |
|
||||
"Clients": { |
|
||||
"AuthManagement": { |
|
||||
"ClientId": "auth-management", |
|
||||
"RootUrl": "http://localhost:44313/" |
|
||||
}, |
|
||||
"AuthVueAdmin": { |
|
||||
"ClientId": "vue-admin-element" |
|
||||
}, |
|
||||
"AuthApiGateway": { |
|
||||
"ClientId": "ApigatewayHostClient" |
|
||||
} |
|
||||
} |
|
||||
}, |
|
||||
"Serilog": { |
|
||||
"MinimumLevel": { |
|
||||
"Default": "Information", |
|
||||
"Override": { |
|
||||
"System": "Warning", |
|
||||
"Microsoft": "Warning", |
|
||||
"DotNetCore": "Information" |
|
||||
} |
|
||||
}, |
|
||||
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId" ], |
|
||||
"WriteTo": [ |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Debug-.log", |
|
||||
"restrictedToMinimumLevel": "Debug", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Info-.log", |
|
||||
"restrictedToMinimumLevel": "Information", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Warn-.log", |
|
||||
"restrictedToMinimumLevel": "Warning", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Error-.log", |
|
||||
"restrictedToMinimumLevel": "Error", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Fatal-.log", |
|
||||
"restrictedToMinimumLevel": "Fatal", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
} |
|
||||
] |
|
||||
} |
|
||||
} |
|
||||
@ -1,143 +0,0 @@ |
|||||
{ |
|
||||
"App": { |
|
||||
"TrackingEntitiesChanged": true, |
|
||||
"SelfUrl": "http://localhost:44385/" |
|
||||
}, |
|
||||
"ConnectionStrings": { |
|
||||
"Default": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpIdentity": "Server=127.0.0.1;Database=IdentityServer;User Id=root;Password=123456", |
|
||||
"AbpIdentityServer": "Server=127.0.0.1;Database=IdentityServer;User Id=root;Password=123456", |
|
||||
"AbpTenantManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpSettingManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpPermissionManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpLocalizationManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456" |
|
||||
}, |
|
||||
"Logging": { |
|
||||
"Serilog": { |
|
||||
"Elasticsearch": { |
|
||||
"IndexFormat": "linyun.abp.logging-{0:yyyy.MM.dd}" |
|
||||
} |
|
||||
} |
|
||||
}, |
|
||||
"AuditLogging": { |
|
||||
"Elasticsearch": { |
|
||||
"IndexPrefix": "lingyun.abp.auditing" |
|
||||
} |
|
||||
}, |
|
||||
"Elasticsearch": { |
|
||||
"NodeUris": "http://localhost:9200" |
|
||||
}, |
|
||||
"Location": { |
|
||||
"Baidu": { |
|
||||
"AccessKey": "你自己的百度地图WebAPI Key", |
|
||||
"ExtensionsRoad": true, |
|
||||
"ExtensionsTown": true, |
|
||||
"ExtensionsPoi": "1", |
|
||||
"VisableErrorToClient": true |
|
||||
}, |
|
||||
"Tencent": { |
|
||||
"AccessKey": "你自己的腾讯地图WebAPI Key", |
|
||||
"SecretKey": "你自己的腾讯地图WebAPI SecretKey Key, 不填的话不计算签名", |
|
||||
"VisableErrorToClient": true |
|
||||
} |
|
||||
}, |
|
||||
"CAP": { |
|
||||
"EventBus": { |
|
||||
"DefaultGroupName": "BackendAdmin", |
|
||||
"Version": "v1", |
|
||||
"FailedRetryInterval": 300, |
|
||||
"FailedRetryCount": 10 |
|
||||
}, |
|
||||
"RabbitMQ": { |
|
||||
"HostName": "Your RabbitMQ server connection address", |
|
||||
"Port": 5672, |
|
||||
"UserName": "Your RabbitMQ server connection user", |
|
||||
"Password": "Your RabbitMQ server connection user password", |
|
||||
"ExchangeName": "The name of your RabbitMQ server switch", |
|
||||
"VirtualHost": "Name of your RabbitMQ server VirtualHost" |
|
||||
} |
|
||||
}, |
|
||||
"Redis": { |
|
||||
"Configuration": "127.0.0.1", |
|
||||
"InstanceName": "LINGYUN.AbpApplication", |
|
||||
"DefaultDatabase": 10 |
|
||||
}, |
|
||||
"AuthServer": { |
|
||||
"Authority": "http://localhost:44385/", |
|
||||
"ApiName": "lingyun-abp-application" |
|
||||
}, |
|
||||
"Serilog": { |
|
||||
"MinimumLevel": { |
|
||||
"Default": "Debug", |
|
||||
"Override": { |
|
||||
"Microsoft.EntityFrameworkCore": "Debug", |
|
||||
"System": "Warning", |
|
||||
"Microsoft": "Warning" |
|
||||
} |
|
||||
}, |
|
||||
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId" ], |
|
||||
"WriteTo": [ |
|
||||
{ |
|
||||
"Name": "Console", |
|
||||
"Args": { |
|
||||
"restrictedToMinimumLevel": "Debug", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "Elasticsearch", |
|
||||
"Args": { |
|
||||
"nodeUris": "http://localhost:9200", |
|
||||
"indexFormat": "linyun.abp.logging-{0:yyyy.MM.dd}", |
|
||||
"autoRegisterTemplate": true, |
|
||||
"autoRegisterTemplateVersion": "ESv7" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Debug-.log", |
|
||||
"restrictedToMinimumLevel": "Debug", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Info-.log", |
|
||||
"restrictedToMinimumLevel": "Information", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Warn-.log", |
|
||||
"restrictedToMinimumLevel": "Warning", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Error-.log", |
|
||||
"restrictedToMinimumLevel": "Error", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Fatal-.log", |
|
||||
"restrictedToMinimumLevel": "Fatal", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
} |
|
||||
] |
|
||||
} |
|
||||
} |
|
||||
@ -1,107 +0,0 @@ |
|||||
{ |
|
||||
"App": { |
|
||||
"CorsOrigins": "http://localhost:9527,http://127.0.0.1:30000" |
|
||||
}, |
|
||||
"ConnectionStrings": { |
|
||||
"Default": "Server=127.0.0.1;Database=Messages;User Id=root;Password=123456", |
|
||||
"MessageService": "Server=127.0.0.1;Database=Messages;User Id=root;Password=123456", |
|
||||
"AbpTenantManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpSettingManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpPermissionManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456" |
|
||||
}, |
|
||||
"Redis": { |
|
||||
"Configuration": "127.0.0.1,defaultDatabase=10", |
|
||||
"InstanceName": "LINGYUN.AbpApplication" |
|
||||
}, |
|
||||
"AuthServer": { |
|
||||
"Authority": "http://localhost:44385/", |
|
||||
"ApiName": "lingyun-abp-application" |
|
||||
}, |
|
||||
"Hangfire": { |
|
||||
"MySql": { |
|
||||
"Connection": "Server=127.0.0.1;Database=Messages;User Id=root;Password=123456;Allow User Variables=true", |
|
||||
"TablePrefix": "AppHangfire" |
|
||||
} |
|
||||
}, |
|
||||
"Notifications": { |
|
||||
"WeChat": { |
|
||||
"WeApp": { |
|
||||
"DefaultWeAppState": "formal" |
|
||||
} |
|
||||
} |
|
||||
}, |
|
||||
"CAP": { |
|
||||
"EventBus": { |
|
||||
"DefaultGroupName": "MessageService", |
|
||||
"Version": "v1", |
|
||||
"FailedRetryInterval": 300, |
|
||||
"FailedRetryCount": 10 |
|
||||
}, |
|
||||
"RabbitMQ": { |
|
||||
"HostName": "127.0.0.1", |
|
||||
"Port": 5672, |
|
||||
"UserName": "admin", |
|
||||
"Password": "admin", |
|
||||
"ExchangeName": "LINGYUN.AbpApplication", |
|
||||
"VirtualHost": "multi.service.test" |
|
||||
} |
|
||||
}, |
|
||||
"Serilog": { |
|
||||
"MinimumLevel": { |
|
||||
"Default": "Debug", |
|
||||
"Override": { |
|
||||
"Microsoft.EntityFrameworkCore": "Debug", |
|
||||
"System": "Warning", |
|
||||
"Microsoft": "Warning" |
|
||||
} |
|
||||
}, |
|
||||
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId" ], |
|
||||
"WriteTo": [ |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Debug-.log", |
|
||||
"restrictedToMinimumLevel": "Debug", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Info-.log", |
|
||||
"restrictedToMinimumLevel": "Information", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Warn-.log", |
|
||||
"restrictedToMinimumLevel": "Warning", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Error-.log", |
|
||||
"restrictedToMinimumLevel": "Error", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Fatal-.log", |
|
||||
"restrictedToMinimumLevel": "Fatal", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
} |
|
||||
] |
|
||||
} |
|
||||
} |
|
||||
@ -1,119 +0,0 @@ |
|||||
{ |
|
||||
"App": { |
|
||||
"CorsOrigins": "http://localhost:9527,http://127.0.0.1:30000" |
|
||||
}, |
|
||||
"ConnectionStrings": { |
|
||||
"Default": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AppPlatform": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpTenantManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpSettingManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpPermissionManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
|
||||
"AbpLocalizationManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456" |
|
||||
}, |
|
||||
"Features": { |
|
||||
"Validation": { |
|
||||
"Redis": { |
|
||||
"Configuration": "127.0.0.1,defaultDatabase=11", |
|
||||
"InstanceName": "LINGYUN.Abp.Application" |
|
||||
} |
|
||||
} |
|
||||
}, |
|
||||
"CAP": { |
|
||||
"EventBus": { |
|
||||
"DefaultGroupName": "Platform", |
|
||||
"Version": "v1", |
|
||||
"FailedRetryInterval": 300, |
|
||||
"FailedRetryCount": 10 |
|
||||
}, |
|
||||
"RabbitMQ": { |
|
||||
"HostName": "Your RabbitMQ server connection address", |
|
||||
"Port": 5672, |
|
||||
"UserName": "Your RabbitMQ server connection user", |
|
||||
"Password": "Your RabbitMQ server connection user password", |
|
||||
"ExchangeName": "The name of your RabbitMQ server switch", |
|
||||
"VirtualHost": "Name of your RabbitMQ server VirtualHost" |
|
||||
} |
|
||||
}, |
|
||||
"RemoteServices": { |
|
||||
"AbpIdentity": { |
|
||||
"BaseUrl": "http://localhost:30015/", |
|
||||
"IdentityClient": "internal-service-client" |
|
||||
} |
|
||||
}, |
|
||||
"IdentityClients": { |
|
||||
"internal-service-client": { |
|
||||
"Authority": "http://localhost:44385", |
|
||||
"RequireHttps": false, |
|
||||
"GrantType": "client_credentials", |
|
||||
"Scope": "lingyun-abp-application", |
|
||||
"ClientId": "internal-service-client", |
|
||||
"ClientSecret": "1q2w3e*" |
|
||||
} |
|
||||
}, |
|
||||
"Redis": { |
|
||||
"Configuration": "127.0.0.1,defaultDatabase=10", |
|
||||
"InstanceName": "LINGYUN.AbpApplication" |
|
||||
}, |
|
||||
"AuthServer": { |
|
||||
"Authority": "http://localhost:44385/", |
|
||||
"ApiName": "lingyun-abp-application" |
|
||||
}, |
|
||||
"Serilog": { |
|
||||
"MinimumLevel": { |
|
||||
"Default": "Debug", |
|
||||
"Override": { |
|
||||
"Microsoft.EntityFrameworkCore": "Debug", |
|
||||
"System": "Warning", |
|
||||
"Microsoft": "Warning" |
|
||||
} |
|
||||
}, |
|
||||
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId" ], |
|
||||
"WriteTo": [ |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Debug-.log", |
|
||||
"restrictedToMinimumLevel": "Debug", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Info-.log", |
|
||||
"restrictedToMinimumLevel": "Information", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Warn-.log", |
|
||||
"restrictedToMinimumLevel": "Warning", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Error-.log", |
|
||||
"restrictedToMinimumLevel": "Error", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Fatal-.log", |
|
||||
"restrictedToMinimumLevel": "Fatal", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
} |
|
||||
] |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,32 @@ |
|||||
|
# LINGYUN.Abp.AuditLogging.EntityFrameworkCore |
||||
|
|
||||
|
审计模块 EntityFrameworkCore 实现, 此模块仅作为桥梁, 具体实现交给abp官方模块 |
||||
|
|
||||
|
AuditLogManager 实现了 IAuditLogManager, 审计日志由Volo.Abp.AuditLogging模块管理 |
||||
|
SecurityLogManager 实现了 ISecurityLogManager, 安全日志由Volo.Abp.Identity模块管理 |
||||
|
|
||||
|
## 模块引用 |
||||
|
|
||||
|
```csharp |
||||
|
[DependsOn(typeof(AbpAuditLoggingEntityFrameworkCoreModule))] |
||||
|
public class YouProjectModule : AbpModule |
||||
|
{ |
||||
|
// other |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
## 配置项 |
||||
|
|
||||
|
请遵循 Volo.Abp.AuditLogging、Volo.Abp.Identity模块中的配置 |
||||
|
|
||||
|
## appsettings.json |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
"ConnectionStrings": { |
||||
|
"AbpIdentity": "Server=127.0.0.1;Database=Identity;User Id=root;Password=*", |
||||
|
"AbpAuditLogging": "Server=127.0.0.1;Database=AuditLogging;User Id=root;Password=*", |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
``` |
||||
@ -0,0 +1,32 @@ |
|||||
|
# LINGYUN.Abp.Logging.Serilog.Elasticsearch |
||||
|
|
||||
|
ILoggingManager 接口的ES实现, 从ES中检索日志信息 |
||||
|
|
||||
|
## 模块引用 |
||||
|
|
||||
|
```csharp |
||||
|
[DependsOn(typeof(AbpLoggingSerilogElasticsearchModule))] |
||||
|
public class YouProjectModule : AbpModule |
||||
|
{ |
||||
|
// other |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
## 配置项 |
||||
|
|
||||
|
* AbpLoggingSerilogElasticsearchOptions.IndexFormat 必须和Serilog配置项中的IndexFormat相同,否则无法定位到正确的索引 |
||||
|
|
||||
|
## appsettings.json |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
"Logging": { |
||||
|
"Serilog": { |
||||
|
"Elasticsearch": { |
||||
|
"IndexFormat": "logstash-{0:yyyy.MM.dd}" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
``` |
||||
@ -0,0 +1,8 @@ |
|||||
|
namespace LINGYUN.Abp.Logging |
||||
|
{ |
||||
|
public class AbpLoggingEnricherPropertyNames |
||||
|
{ |
||||
|
public const string MachineName = "MachineName"; |
||||
|
public const string EnvironmentName = "EnvironmentName"; |
||||
|
} |
||||
|
} |
||||
@ -1,9 +1,15 @@ |
|||||
using System; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Volo.Abp.Modularity; |
using Volo.Abp.Modularity; |
||||
|
|
||||
namespace LINGYUN.Abp.Logging |
namespace LINGYUN.Abp.Logging |
||||
{ |
{ |
||||
public class AbpLoggingModule : AbpModule |
public class AbpLoggingModule : AbpModule |
||||
{ |
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
var configuration = context.Services.GetConfiguration(); |
||||
|
|
||||
|
Configure<AbpLoggingEnricherPropertyNames>(configuration.GetSection("Logging")); |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,31 @@ |
|||||
|
# LINGYUN.Abp.Logging |
||||
|
|
||||
|
日志基础模块 |
||||
|
|
||||
|
定义 ILoggingManager 接口, 实现日志信息查询 |
||||
|
|
||||
|
## 模块引用 |
||||
|
|
||||
|
```csharp |
||||
|
[DependsOn(typeof(AbpLoggingModule))] |
||||
|
public class YouProjectModule : AbpModule |
||||
|
{ |
||||
|
// other |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
## 配置项 |
||||
|
|
||||
|
* AbpLoggingOptions.ApplicationPropertyName 用于自定义ApplicationName字段的名称 |
||||
|
* AbpLoggingOptions.ApplicationName 在日志中标识当前应用的名称 |
||||
|
|
||||
|
## appsettings.json |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
"Logging": { |
||||
|
"ApplicationName": "app" |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
``` |
||||
@ -0,0 +1,169 @@ |
|||||
|
using Microsoft.AspNetCore.Cors; |
||||
|
using Microsoft.AspNetCore.DataProtection; |
||||
|
using Microsoft.AspNetCore.Identity; |
||||
|
using Microsoft.Extensions.Caching.StackExchangeRedis; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using StackExchange.Redis; |
||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Text.Encodings.Web; |
||||
|
using System.Text.Unicode; |
||||
|
using Volo.Abp.Account.Localization; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Abp.Json.SystemTextJson; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.UI.Navigation.Urls; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
|
||||
|
namespace AuthServer.Host |
||||
|
{ |
||||
|
public partial class AuthIdentityServerModule |
||||
|
{ |
||||
|
private void ConfigureDbContext() |
||||
|
{ |
||||
|
Configure<AbpDbContextOptions>(options => |
||||
|
{ |
||||
|
options.UseMySQL(); |
||||
|
}); |
||||
|
} |
||||
|
private void ConfigureJsonSerializer() |
||||
|
{ |
||||
|
// 中文序列化的编码问题
|
||||
|
Configure<AbpSystemTextJsonSerializerOptions>(options => |
||||
|
{ |
||||
|
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); |
||||
|
}); |
||||
|
} |
||||
|
private void ConfigureCaching(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpDistributedCacheOptions>(options => |
||||
|
{ |
||||
|
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
|
||||
|
options.KeyPrefix = "LINGYUN.Abp.Application"; |
||||
|
// 滑动过期30天
|
||||
|
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); |
||||
|
// 绝对过期60天
|
||||
|
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); |
||||
|
}); |
||||
|
|
||||
|
Configure<RedisCacheOptions>(options => |
||||
|
{ |
||||
|
var redisConfig = ConfigurationOptions.Parse(options.Configuration); |
||||
|
options.ConfigurationOptions = redisConfig; |
||||
|
options.InstanceName = configuration["Redis:InstanceName"]; |
||||
|
}); |
||||
|
} |
||||
|
private void ConfigureIdentity(IConfiguration configuration) |
||||
|
{ |
||||
|
// 增加配置文件定义,在新建租户时需要
|
||||
|
Configure<IdentityOptions>(options => |
||||
|
{ |
||||
|
var identityConfiguration = configuration.GetSection("Identity"); |
||||
|
if (identityConfiguration.Exists()) |
||||
|
{ |
||||
|
identityConfiguration.Bind(options); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
private void ConfigureVirtualFileSystem() |
||||
|
{ |
||||
|
Configure<AbpVirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<AuthIdentityServerModule>("AuthServer"); |
||||
|
}); |
||||
|
} |
||||
|
private void ConfigureLocalization() |
||||
|
{ |
||||
|
Configure<AbpLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
||||
|
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
||||
|
|
||||
|
options.Resources |
||||
|
.Get<AccountResource>() |
||||
|
.AddVirtualJson("/Localization/Resources"); |
||||
|
}); |
||||
|
} |
||||
|
private void ConfigureAuditing() |
||||
|
{ |
||||
|
Configure<AbpAuditingOptions>(options => |
||||
|
{ |
||||
|
// options.IsEnabledForGetRequests = true;
|
||||
|
options.ApplicationName = "Identity-Server-STS"; |
||||
|
}); |
||||
|
} |
||||
|
private void ConfigureUrls(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AppUrlOptions>(options => |
||||
|
{ |
||||
|
options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; |
||||
|
// 邮件登录地址
|
||||
|
options.Applications["MVC"].Urls["EmailVerifyLogin"] = "Account/VerifyCode"; |
||||
|
}); |
||||
|
} |
||||
|
private void ConfigureSecurity(IServiceCollection services, IConfiguration configuration, bool isDevelopment = false) |
||||
|
{ |
||||
|
services.AddAuthentication() |
||||
|
.AddJwtBearer(options => |
||||
|
{ |
||||
|
options.Authority = configuration["AuthServer:Authority"]; |
||||
|
options.RequireHttpsMetadata = false; |
||||
|
options.Audience = configuration["AuthServer:ApiName"]; |
||||
|
}); |
||||
|
|
||||
|
if (!isDevelopment) |
||||
|
{ |
||||
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
||||
|
services |
||||
|
.AddDataProtection() |
||||
|
.PersistKeysToStackExchangeRedis(redis, "AuthServer-Protection-Keys"); |
||||
|
} |
||||
|
} |
||||
|
private void ConfigureMultiTenancy(IConfiguration configuration) |
||||
|
{ |
||||
|
// 多租户
|
||||
|
Configure<AbpMultiTenancyOptions>(options => |
||||
|
{ |
||||
|
options.IsEnabled = true; |
||||
|
}); |
||||
|
|
||||
|
var tenantResolveCfg = configuration.GetSection("App:Domains"); |
||||
|
if (tenantResolveCfg.Exists()) |
||||
|
{ |
||||
|
Configure<AbpTenantResolveOptions>(options => |
||||
|
{ |
||||
|
var domains = tenantResolveCfg.Get<string[]>(); |
||||
|
foreach (var domain in domains) |
||||
|
{ |
||||
|
options.AddDomainTenantResolver(domain); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
private void ConfigureCors(IServiceCollection services, IConfiguration configuration) |
||||
|
{ |
||||
|
services.AddCors(options => |
||||
|
{ |
||||
|
options.AddPolicy(DefaultCorsPolicyName, builder => |
||||
|
{ |
||||
|
builder |
||||
|
.WithOrigins( |
||||
|
configuration["App:CorsOrigins"] |
||||
|
.Split(",", StringSplitOptions.RemoveEmptyEntries) |
||||
|
.Select(o => o.RemovePostFix("/")) |
||||
|
.ToArray() |
||||
|
) |
||||
|
.WithAbpExposedHeaders() |
||||
|
.SetIsOriginAllowedToAllowWildcardSubdomains() |
||||
|
.AllowAnyHeader() |
||||
|
.AllowAnyMethod() |
||||
|
.AllowCredentials(); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.Threading; |
||||
|
|
||||
|
namespace AuthServer.Host |
||||
|
{ |
||||
|
public partial class AuthIdentityServerModule |
||||
|
{ |
||||
|
private void SeedData(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
if (context.GetEnvironment().IsDevelopment()) |
||||
|
{ |
||||
|
AsyncHelper.RunSync(async () => |
||||
|
{ |
||||
|
using var scope = context.ServiceProvider.CreateScope(); |
||||
|
await scope.ServiceProvider.GetRequiredService<IDataSeeder>().SeedAsync(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,328 +1,168 @@ |
|||||
using DotNetCore.CAP; |
using DotNetCore.CAP; |
||||
using LINGYUN.Abp.AspNetCore.HttpOverrides; |
using LINGYUN.Abp.AspNetCore.HttpOverrides; |
||||
using LINGYUN.Abp.EventBus.CAP; |
using LINGYUN.Abp.AuditLogging.Elasticsearch; |
||||
using LINGYUN.Abp.Identity.EntityFrameworkCore; |
using LINGYUN.Abp.EventBus.CAP; |
||||
using LINGYUN.Abp.IdentityServer; |
using LINGYUN.Abp.Identity.EntityFrameworkCore; |
||||
using LINGYUN.Abp.IdentityServer.EntityFrameworkCore; |
using LINGYUN.Abp.IdentityServer; |
||||
using LINGYUN.Abp.IdentityServer.WeChat; |
using LINGYUN.Abp.IdentityServer.EntityFrameworkCore; |
||||
using LINGYUN.Abp.MultiTenancy.DbFinder; |
using LINGYUN.Abp.IdentityServer.WeChat; |
||||
using LINGYUN.Abp.PermissionManagement.Identity; |
using LINGYUN.Abp.MultiTenancy.DbFinder; |
||||
using LINGYUN.Abp.Sms.Aliyun; |
using LINGYUN.Abp.PermissionManagement.Identity; |
||||
using Microsoft.AspNetCore.Builder; |
using LINGYUN.Abp.Sms.Aliyun; |
||||
using Microsoft.AspNetCore.Cors; |
using Microsoft.AspNetCore.Builder; |
||||
using Microsoft.AspNetCore.DataProtection; |
using Microsoft.AspNetCore.Hosting; |
||||
using Microsoft.AspNetCore.Hosting; |
using Microsoft.Extensions.Configuration; |
||||
using Microsoft.AspNetCore.Identity; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Microsoft.Extensions.Caching.StackExchangeRedis; |
using Microsoft.Extensions.Hosting; |
||||
using Microsoft.Extensions.Configuration; |
using System.IO; |
||||
using Microsoft.Extensions.DependencyInjection; |
using System.Security.Cryptography.X509Certificates; |
||||
using Microsoft.Extensions.Hosting; |
using Volo.Abp; |
||||
using StackExchange.Redis; |
using Volo.Abp.Account; |
||||
using System; |
using Volo.Abp.Account.Web; |
||||
using System.IO; |
using Volo.Abp.AspNetCore.Authentication.JwtBearer; |
||||
using System.Linq; |
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; |
||||
using System.Security.Cryptography.X509Certificates; |
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; |
||||
using System.Text; |
using Volo.Abp.AspNetCore.Serilog; |
||||
using System.Text.Encodings.Web; |
using Volo.Abp.Autofac; |
||||
using System.Text.Unicode; |
using Volo.Abp.Caching.StackExchangeRedis; |
||||
using Volo.Abp; |
using Volo.Abp.EntityFrameworkCore.MySQL; |
||||
using Volo.Abp.Account; |
using Volo.Abp.FeatureManagement.EntityFrameworkCore; |
||||
using Volo.Abp.Account.Localization; |
using Volo.Abp.Identity; |
||||
using Volo.Abp.Account.Web; |
using Volo.Abp.IdentityServer; |
||||
using Volo.Abp.AspNetCore.Authentication.JwtBearer; |
using Volo.Abp.IdentityServer.Jwt; |
||||
using Volo.Abp.AspNetCore.Mvc; |
using Volo.Abp.Modularity; |
||||
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; |
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
||||
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; |
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
||||
using Volo.Abp.Auditing; |
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
||||
using Volo.Abp.Autofac; |
|
||||
using Volo.Abp.Caching; |
namespace AuthServer.Host |
||||
using Volo.Abp.Caching.StackExchangeRedis; |
{ |
||||
using Volo.Abp.Data; |
[DependsOn( |
||||
using Volo.Abp.EntityFrameworkCore; |
typeof(AbpAspNetCoreSerilogModule), |
||||
using Volo.Abp.EntityFrameworkCore.MySQL; |
typeof(AbpAuditLoggingElasticsearchModule), |
||||
using Volo.Abp.FeatureManagement.EntityFrameworkCore; |
typeof(AbpAccountWebIdentityServerModule), |
||||
using Volo.Abp.Identity; |
typeof(AbpAccountApplicationModule), |
||||
using Volo.Abp.IdentityServer; |
typeof(AbpAspNetCoreMvcUiBasicThemeModule), |
||||
using Volo.Abp.IdentityServer.Jwt; |
typeof(AbpAutofacModule), |
||||
using Volo.Abp.Json; |
typeof(AbpCachingStackExchangeRedisModule), |
||||
using Volo.Abp.Json.SystemTextJson; |
typeof(AbpEntityFrameworkCoreMySQLModule), |
||||
using Volo.Abp.Localization; |
typeof(AbpIdentityEntityFrameworkCoreModule), |
||||
using Volo.Abp.Modularity; |
typeof(AbpIdentityApplicationModule), |
||||
using Volo.Abp.MultiTenancy; |
typeof(AbpIdentityHttpApiModule), |
||||
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
typeof(AbpIdentityServerEntityFrameworkCoreModule), |
||||
using Volo.Abp.Security.Encryption; |
typeof(AbpIdentityServerSmsValidatorModule), |
||||
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
typeof(AbpIdentityServerWeChatModule), |
||||
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
typeof(AbpPermissionManagementDomainIdentityModule), |
||||
using Volo.Abp.Threading; |
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.UI.Navigation.Urls; |
typeof(AbpSettingManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.VirtualFileSystem; |
typeof(AbpFeatureManagementEntityFrameworkCoreModule), |
||||
|
typeof(AbpTenantManagementEntityFrameworkCoreModule), |
||||
namespace AuthServer.Host |
typeof(AbpAspNetCoreAuthenticationJwtBearerModule), |
||||
{ |
typeof(AbpAspNetCoreHttpOverridesModule), |
||||
[DependsOn( |
typeof(AbpDbFinderMultiTenancyModule), |
||||
typeof(AbpAccountWebIdentityServerModule), |
typeof(AbpCAPEventBusModule), |
||||
typeof(AbpAccountApplicationModule), |
typeof(AbpAliyunSmsModule) |
||||
typeof(AbpAspNetCoreMvcUiBasicThemeModule), |
)] |
||||
typeof(AbpAutofacModule), |
public partial class AuthIdentityServerModule : AbpModule |
||||
typeof(AbpCachingStackExchangeRedisModule), |
{ |
||||
typeof(AbpEntityFrameworkCoreMySQLModule), |
private const string DefaultCorsPolicyName = "Default"; |
||||
typeof(AbpIdentityEntityFrameworkCoreModule), |
|
||||
typeof(AbpIdentityApplicationModule), |
public override void PreConfigureServices(ServiceConfigurationContext context) |
||||
typeof(AbpIdentityHttpApiModule), |
{ |
||||
typeof(AbpIdentityServerEntityFrameworkCoreModule), |
var configuration = context.Services.GetConfiguration(); |
||||
typeof(AbpIdentityServerSmsValidatorModule), |
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
||||
typeof(AbpIdentityServerWeChatModule), |
|
||||
typeof(AbpPermissionManagementDomainIdentityModule), |
PreConfigure<CapOptions>(options => |
||||
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
{ |
||||
typeof(AbpSettingManagementEntityFrameworkCoreModule), |
options |
||||
typeof(AbpFeatureManagementEntityFrameworkCoreModule), |
.UseMySql(configuration.GetConnectionString("Default")) |
||||
typeof(AbpTenantManagementEntityFrameworkCoreModule), |
.UseRabbitMQ(rabbitMQOptions => |
||||
typeof(AbpAspNetCoreAuthenticationJwtBearerModule), |
{ |
||||
typeof(AbpAspNetCoreHttpOverridesModule), |
configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); |
||||
typeof(AbpDbFinderMultiTenancyModule), |
}) |
||||
typeof(AbpCAPEventBusModule), |
.UseDashboard(); |
||||
typeof(AbpAliyunSmsModule) |
}); |
||||
)] |
|
||||
public class AuthIdentityServerModule : AbpModule |
var cerConfig = configuration.GetSection("Certificates"); |
||||
{ |
if (hostingEnvironment.IsProduction() && |
||||
private const string DefaultCorsPolicyName = "Default"; |
cerConfig.Exists()) |
||||
|
{ |
||||
public override void PreConfigureServices(ServiceConfigurationContext context) |
// 开发环境下存在证书配置
|
||||
{ |
// 且证书文件存在则使用自定义的证书文件来启动Ids服务器
|
||||
var configuration = context.Services.GetConfiguration(); |
var cerPath = Path.Combine(hostingEnvironment.ContentRootPath, cerConfig["CerPath"]); |
||||
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
if (File.Exists(cerPath)) |
||||
|
{ |
||||
PreConfigure<CapOptions>(options => |
PreConfigure<AbpIdentityServerBuilderOptions>(options => |
||||
{ |
{ |
||||
options |
options.AddDeveloperSigningCredential = false; |
||||
.UseMySql(configuration.GetConnectionString("Default")) |
}); |
||||
.UseRabbitMQ(rabbitMQOptions => |
|
||||
{ |
var cer = new X509Certificate2(cerPath, cerConfig["Password"]); |
||||
configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); |
|
||||
}) |
PreConfigure<IIdentityServerBuilder>(builder => |
||||
.UseDashboard(); |
{ |
||||
}); |
builder.AddSigningCredential(cer); |
||||
|
}); |
||||
var cerConfig = configuration.GetSection("Certificates"); |
} |
||||
if (hostingEnvironment.IsProduction() && |
} |
||||
cerConfig.Exists()) |
} |
||||
{ |
|
||||
// 开发环境下存在证书配置
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
// 且证书文件存在则使用自定义的证书文件来启动Ids服务器
|
{ |
||||
var cerPath = Path.Combine(hostingEnvironment.ContentRootPath, cerConfig["CerPath"]); |
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
||||
if (File.Exists(cerPath)) |
var configuration = hostingEnvironment.BuildConfiguration(); |
||||
{ |
|
||||
PreConfigure<AbpIdentityServerBuilderOptions>(options => |
ConfigureDbContext(); |
||||
{ |
ConfigureJsonSerializer(); |
||||
options.AddDeveloperSigningCredential = false; |
ConfigureCaching(configuration); |
||||
}); |
ConfigureIdentity(configuration); |
||||
|
ConfigureVirtualFileSystem(); |
||||
var cer = new X509Certificate2(cerPath, cerConfig["Password"]); |
ConfigureLocalization(); |
||||
|
ConfigureAuditing(); |
||||
PreConfigure<IIdentityServerBuilder>(builder => |
ConfigureUrls(configuration); |
||||
{ |
ConfigureMultiTenancy(configuration); |
||||
builder.AddSigningCredential(cer); |
ConfigureCors(context.Services, configuration); |
||||
}); |
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); |
||||
} |
|
||||
} |
context.Services.ConfigureNonBreakingSameSiteCookies(); |
||||
} |
|
||||
|
|
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
} |
||||
{ |
|
||||
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
||||
var configuration = context.Services.GetConfiguration(); |
{ |
||||
|
var app = context.GetApplicationBuilder(); |
||||
Configure<AbpDbContextOptions>(options => |
var env = context.GetEnvironment(); |
||||
{ |
|
||||
options.UseMySQL(); |
if (env.IsDevelopment()) |
||||
}); |
{ |
||||
|
app.UseDeveloperExceptionPage(); |
||||
// 中文序列化的编码问题
|
} |
||||
Configure<AbpSystemTextJsonSerializerOptions>(options => |
else |
||||
{ |
{ |
||||
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); |
// 需要实现一个错误页面
|
||||
}); |
app.UseErrorPage(); |
||||
|
app.UseHsts(); |
||||
// 加解密
|
} |
||||
Configure<AbpStringEncryptionOptions>(options => |
|
||||
{ |
// app.UseHttpsRedirection();
|
||||
var encryptionConfiguration = configuration.GetSection("Encryption"); |
app.UseCookiePolicy(); |
||||
if (encryptionConfiguration.Exists()) |
app.UseCorrelationId(); |
||||
{ |
app.UseStaticFiles(); |
||||
options.DefaultPassPhrase = encryptionConfiguration["PassPhrase"] ?? options.DefaultPassPhrase; |
app.UseRouting(); |
||||
options.DefaultSalt = encryptionConfiguration.GetSection("Salt").Exists() |
app.UseCors(DefaultCorsPolicyName); |
||||
? Encoding.ASCII.GetBytes(encryptionConfiguration["Salt"]) |
app.UseWeChatSignature(); |
||||
: options.DefaultSalt; |
app.UseMultiTenancy(); |
||||
options.InitVectorBytes = encryptionConfiguration.GetSection("InitVector").Exists() |
app.UseAuthentication(); |
||||
? Encoding.ASCII.GetBytes(encryptionConfiguration["InitVector"]) |
app.UseJwtTokenMiddleware(); |
||||
: options.InitVectorBytes; |
app.UseAbpRequestLocalization(); |
||||
|
app.UseIdentityServer(); |
||||
var keySizeConfig = encryptionConfiguration.GetSection("Keysize"); |
app.UseAuthorization(); |
||||
options.Keysize = keySizeConfig.Exists() |
app.UseAuditing(); |
||||
? keySizeConfig.Get<int>() |
app.UseAbpSerilogEnrichers(); |
||||
: options.Keysize; |
app.UseConfiguredEndpoints(); |
||||
} |
|
||||
}); |
SeedData(context); |
||||
|
} |
||||
Configure<AbpDistributedCacheOptions>(options => |
} |
||||
{ |
} |
||||
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
|
|
||||
options.KeyPrefix = "LINGYUN.Abp.Application"; |
|
||||
// 滑动过期30天
|
|
||||
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); |
|
||||
// 绝对过期60天
|
|
||||
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); |
|
||||
}); |
|
||||
|
|
||||
Configure<RedisCacheOptions>(options => |
|
||||
{ |
|
||||
var redisConfig = ConfigurationOptions.Parse(options.Configuration); |
|
||||
options.ConfigurationOptions = redisConfig; |
|
||||
options.InstanceName = configuration["Redis:InstanceName"]; |
|
||||
}); |
|
||||
|
|
||||
// 增加配置文件定义,在新建租户时需要
|
|
||||
Configure<IdentityOptions>(options => |
|
||||
{ |
|
||||
var identityConfiguration = configuration.GetSection("Identity"); |
|
||||
if (identityConfiguration.Exists()) |
|
||||
{ |
|
||||
identityConfiguration.Bind(options); |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
Configure<AbpVirtualFileSystemOptions>(options => |
|
||||
{ |
|
||||
options.FileSets.AddEmbedded<AuthIdentityServerModule>("AuthServer"); |
|
||||
}); |
|
||||
|
|
||||
Configure<AbpLocalizationOptions>(options => |
|
||||
{ |
|
||||
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
|
||||
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
|
||||
|
|
||||
options.Resources |
|
||||
.Get<AccountResource>() |
|
||||
.AddVirtualJson("/Localization/Resources"); |
|
||||
}); |
|
||||
|
|
||||
Configure<AbpAuditingOptions>(options => |
|
||||
{ |
|
||||
// options.IsEnabledForGetRequests = true;
|
|
||||
options.ApplicationName = "Identity-Server-STS"; |
|
||||
}); |
|
||||
|
|
||||
Configure<AppUrlOptions>(options => |
|
||||
{ |
|
||||
options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; |
|
||||
// 邮件登录地址
|
|
||||
options.Applications["MVC"].Urls["EmailVerifyLogin"] = "Account/VerifyCode"; |
|
||||
}); |
|
||||
|
|
||||
context.Services.ConfigureNonBreakingSameSiteCookies(); |
|
||||
|
|
||||
// context.Services.AddAuthentication();
|
|
||||
context.Services.AddAuthentication() |
|
||||
.AddJwtBearer(options => |
|
||||
{ |
|
||||
options.Authority = configuration["AuthServer:Authority"]; |
|
||||
options.RequireHttpsMetadata = false; |
|
||||
options.Audience = configuration["AuthServer:ApiName"]; |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
|
|
||||
if (!hostingEnvironment.IsDevelopment()) |
|
||||
{ |
|
||||
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
|
||||
context.Services |
|
||||
.AddDataProtection() |
|
||||
.PersistKeysToStackExchangeRedis(redis, "AuthServer-Protection-Keys"); |
|
||||
} |
|
||||
|
|
||||
Configure<AbpMultiTenancyOptions>(options => |
|
||||
{ |
|
||||
options.IsEnabled = true; |
|
||||
}); |
|
||||
|
|
||||
var tenantResolveCfg = configuration.GetSection("App:Domains"); |
|
||||
if (tenantResolveCfg.Exists()) |
|
||||
{ |
|
||||
Configure<AbpTenantResolveOptions>(options => |
|
||||
{ |
|
||||
var domains = tenantResolveCfg.Get<string[]>(); |
|
||||
foreach (var domain in domains) |
|
||||
{ |
|
||||
options.AddDomainTenantResolver(domain); |
|
||||
} |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
context.Services.AddCors(options => |
|
||||
{ |
|
||||
options.AddPolicy(DefaultCorsPolicyName, builder => |
|
||||
{ |
|
||||
builder |
|
||||
.WithOrigins( |
|
||||
configuration["App:CorsOrigins"] |
|
||||
.Split(",", StringSplitOptions.RemoveEmptyEntries) |
|
||||
.Select(o => o.RemovePostFix("/")) |
|
||||
.ToArray() |
|
||||
) |
|
||||
.WithAbpExposedHeaders() |
|
||||
.SetIsOriginAllowedToAllowWildcardSubdomains() |
|
||||
.AllowAnyHeader() |
|
||||
.AllowAnyMethod() |
|
||||
.AllowCredentials(); |
|
||||
}); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|
||||
{ |
|
||||
var app = context.GetApplicationBuilder(); |
|
||||
var env = context.GetEnvironment(); |
|
||||
|
|
||||
if (env.IsDevelopment()) |
|
||||
{ |
|
||||
app.UseDeveloperExceptionPage(); |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
// 需要实现一个错误页面
|
|
||||
app.UseErrorPage(); |
|
||||
app.UseHsts(); |
|
||||
} |
|
||||
|
|
||||
// app.UseHttpsRedirection();
|
|
||||
app.UseCookiePolicy(); |
|
||||
app.UseCorrelationId(); |
|
||||
app.UseStaticFiles(); |
|
||||
app.UseRouting(); |
|
||||
app.UseCors(DefaultCorsPolicyName); |
|
||||
app.UseWeChatSignature(); |
|
||||
app.UseMultiTenancy(); |
|
||||
app.UseAuthentication(); |
|
||||
app.UseJwtTokenMiddleware(); |
|
||||
app.UseAbpRequestLocalization(); |
|
||||
app.UseIdentityServer(); |
|
||||
app.UseAuthorization(); |
|
||||
app.UseAuditing(); |
|
||||
app.UseConfiguredEndpoints(); |
|
||||
|
|
||||
if (context.GetEnvironment().IsDevelopment()) |
|
||||
{ |
|
||||
SeedData(context); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private void SeedData(ApplicationInitializationContext context) |
|
||||
{ |
|
||||
AsyncHelper.RunSync(async () => |
|
||||
{ |
|
||||
using var scope = context.ServiceProvider.CreateScope(); |
|
||||
await scope.ServiceProvider.GetRequiredService<IDataSeeder>().SeedAsync(); |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|||||
@ -0,0 +1,118 @@ |
|||||
|
{ |
||||
|
"App": { |
||||
|
"TrackingEntitiesChanged": true, |
||||
|
"SelfUrl": "http://localhost:44385/", |
||||
|
"CorsOrigins": "http://localhost:4200,http://localhost:9527,http://localhost:3100" |
||||
|
}, |
||||
|
"AppSelfUrl": "http://localhost:44385/", |
||||
|
"ConnectionStrings": { |
||||
|
"Default": "Server=localhost;Database=IdentityServer;User Id=root;Password=123456", |
||||
|
"AbpIdentity": "Server=localhost;Database=IdentityServer;User Id=root;Password=123456", |
||||
|
"AbpIdentityServer": "Server=localhost;Database=IdentityServer;User Id=root;Password=123456", |
||||
|
"AbpTenantManagement": "Server=localhost;Database=Platform;User Id=root;Password=123456", |
||||
|
"AbpSettingManagement": "Server=localhost;Database=Platform;User Id=root;Password=123456", |
||||
|
"AbpPermissionManagement": "Server=localhost;Database=Platform;User Id=root;Password=123456", |
||||
|
"AbpFeatureManagement": "Server=localhost;Database=Platform;User Id=root;Password=123456" |
||||
|
}, |
||||
|
"CAP": { |
||||
|
"EventBus": { |
||||
|
"DefaultGroupName": "AuthServer", |
||||
|
"Version": "v1", |
||||
|
"FailedRetryInterval": 300, |
||||
|
"FailedRetryCount": 10 |
||||
|
}, |
||||
|
"MySql": { |
||||
|
"TableNamePrefix": "auth", |
||||
|
"ConnectionString": "Server=localhost;Database=IdentityServer;User Id=root;Password=123456" |
||||
|
}, |
||||
|
"RabbitMQ": { |
||||
|
"HostName": "localhost", |
||||
|
"Port": 5672, |
||||
|
"UserName": "guest", |
||||
|
"Password": "guest", |
||||
|
"ExchangeName": "LINGYUN.Abp.Application", |
||||
|
"VirtualHost": "/" |
||||
|
} |
||||
|
}, |
||||
|
"Redis": { |
||||
|
"Configuration": "localhost", |
||||
|
"InstanceName": "LINGYUN.Abp.Application", |
||||
|
"DefaultDatabase": 10 |
||||
|
}, |
||||
|
"AuthServer": { |
||||
|
"Authority": "http://localhost:44385/", |
||||
|
"ApiName": "lingyun-abp-application" |
||||
|
}, |
||||
|
"IdentityServer": { |
||||
|
"Clients": { |
||||
|
"AuthManagement": { |
||||
|
"ClientId": "auth-management", |
||||
|
"RootUrl": "http://localhost:44313/" |
||||
|
}, |
||||
|
"AuthVueAdmin": { |
||||
|
"ClientId": "vue-admin-element" |
||||
|
}, |
||||
|
"AuthApiGateway": { |
||||
|
"ClientId": "ApigatewayHostClient" |
||||
|
}, |
||||
|
"InternalService": { |
||||
|
"ClientId": "internal-service-client" |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
"Identity": { |
||||
|
"Password": { |
||||
|
"RequiredLength": 6, |
||||
|
"RequiredUniqueChars": 0, |
||||
|
"RequireNonAlphanumeric": false, |
||||
|
"RequireLowercase": false, |
||||
|
"RequireUppercase": false, |
||||
|
"RequireDigit": false |
||||
|
}, |
||||
|
"Lockout": { |
||||
|
"AllowedForNewUsers": false, |
||||
|
"LockoutDuration": 5, |
||||
|
"MaxFailedAccessAttempts": 5 |
||||
|
}, |
||||
|
"SignIn": { |
||||
|
"RequireConfirmedEmail": false, |
||||
|
"RequireConfirmedPhoneNumber": false |
||||
|
} |
||||
|
}, |
||||
|
"AuditLogging": { |
||||
|
"Elasticsearch": { |
||||
|
"IndexPrefix": "lingyun.abp.auditing" |
||||
|
} |
||||
|
}, |
||||
|
"Elasticsearch": { |
||||
|
"NodeUris": "http://localhost:9200" |
||||
|
}, |
||||
|
"Serilog": { |
||||
|
"MinimumLevel": { |
||||
|
"Default": "Debug", |
||||
|
"Override": { |
||||
|
"System": "Warning", |
||||
|
"Microsoft": "Warning", |
||||
|
"DotNetCore": "Debug" |
||||
|
} |
||||
|
}, |
||||
|
"WriteTo": [ |
||||
|
{ |
||||
|
"Name": "Console", |
||||
|
"Args": { |
||||
|
"restrictedToMinimumLevel": "Debug", |
||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
"Name": "Elasticsearch", |
||||
|
"Args": { |
||||
|
"nodeUris": "http://localhost:9200", |
||||
|
"indexFormat": "lingyun.abp.logging-{0:yyyy.MM.dd}", |
||||
|
"autoRegisterTemplate": true, |
||||
|
"autoRegisterTemplateVersion": "ESv7" |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
} |
||||
@ -1,103 +1,72 @@ |
|||||
{ |
{ |
||||
"ApiGateway": { |
"StringEncryption": { |
||||
"AppId": "TEST-APP"//这里是用于Ocelot主机去API服务器获取参数的标识,指定需要获取什么类型的网关配置 |
"DefaultPassPhrase": "s46c5q55nxpeS8Ra", |
||||
}, |
"InitVectorBytes": "s83ng0abvd02js84", |
||||
"Redis": { |
"DefaultSalt": "sf&5)s3#" |
||||
"Configuration": "127.0.0.1,defaultDatabase=10", |
}, |
||||
"InstanceName": "LINGYUN.AbpApplication" |
"Serilog": { |
||||
}, |
"MinimumLevel": { |
||||
"RemoteServices": { |
"Default": "Debug", |
||||
"ApiGateway": { |
"Override": { |
||||
"BaseUrl": "http://localhost:30001/", |
"System": "Warning", |
||||
"IdentityClient": "ApigatewayHostClient" |
"Microsoft": "Warning", |
||||
} |
"DotNetCore": "Information" |
||||
}, |
} |
||||
"IdentityClients": { |
}, |
||||
"ApigatewayHostClient": { |
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId", "WithEnvironmentName", "WithMachineName" ], |
||||
"Authority": "http://localhost:44385", |
"WriteTo": [ |
||||
"RequireHttps": false, |
{ |
||||
"GrantType": "client_credentials", |
"Name": "Console", |
||||
"ClientId": "ApigatewayHostClient", |
"Args": { |
||||
"ClientSecret": "1q2w3e*", |
"restrictedToMinimumLevel": "Debug", |
||||
"Scope": "lingyun-abp-application" |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
} |
} |
||||
}, |
}, |
||||
"EnabledDynamicOcelot": true, |
{ |
||||
"CAP": { |
"Name": "File", |
||||
"EventBus": { |
"Args": { |
||||
"DefaultGroupName": "ApiGateway-Host", |
"path": "Logs/Debug-.log", |
||||
"Version": "v1", |
"restrictedToMinimumLevel": "Debug", |
||||
"FailedRetryInterval": 300, |
"rollingInterval": "Day", |
||||
"FailedRetryCount": 10 |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
}, |
} |
||||
"RabbitMQ": { |
}, |
||||
"HostName": "127.0.0.1", |
{ |
||||
"Port": 5672, |
"Name": "File", |
||||
"UserName": "admin", |
"Args": { |
||||
"Password": "admin", |
"path": "Logs/Info-.log", |
||||
"ExchangeName": "LINGYUN.ApiGateway", |
"restrictedToMinimumLevel": "Information", |
||||
"VirtualHost": "multi.service.test" |
"rollingInterval": "Day", |
||||
} |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
}, |
} |
||||
"AuthServer": { |
}, |
||||
"Authority": "http://localhost:44385/", |
{ |
||||
"ApiName": "lingyun-abp-application" |
"Name": "File", |
||||
}, |
"Args": { |
||||
"Serilog": { |
"path": "Logs/Warn-.log", |
||||
"MinimumLevel": { |
"restrictedToMinimumLevel": "Warning", |
||||
"Default": "Debug", |
"rollingInterval": "Day", |
||||
"Override": { |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"System": "Warning", |
} |
||||
"Microsoft": "Warning" |
}, |
||||
} |
{ |
||||
}, |
"Name": "File", |
||||
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId" ], |
"Args": { |
||||
"WriteTo": [ |
"path": "Logs/Error-.log", |
||||
{ |
"restrictedToMinimumLevel": "Error", |
||||
"Name": "File", |
"rollingInterval": "Day", |
||||
"Args": { |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"path": "Logs/Debug-.log", |
} |
||||
"restrictedToMinimumLevel": "Debug", |
}, |
||||
"rollingInterval": "Day", |
{ |
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
"Name": "File", |
||||
} |
"Args": { |
||||
}, |
"path": "Logs/Fatal-.log", |
||||
{ |
"restrictedToMinimumLevel": "Fatal", |
||||
"Name": "File", |
"rollingInterval": "Day", |
||||
"Args": { |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"path": "Logs/Info-.log", |
} |
||||
"restrictedToMinimumLevel": "Information", |
} |
||||
"rollingInterval": "Day", |
] |
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
} |
||||
} |
} |
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Warn-.log", |
|
||||
"restrictedToMinimumLevel": "Warning", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Error-.log", |
|
||||
"restrictedToMinimumLevel": "Error", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Fatal-.log", |
|
||||
"restrictedToMinimumLevel": "Fatal", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
} |
|
||||
] |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,259 @@ |
|||||
|
using DotNetCore.CAP; |
||||
|
using LINGYUN.Abp.ExceptionHandling; |
||||
|
using LINGYUN.Abp.ExceptionHandling.Emailing; |
||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer; |
||||
|
using Microsoft.AspNetCore.DataProtection; |
||||
|
using Microsoft.Extensions.Caching.StackExchangeRedis; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.OpenApi.Models; |
||||
|
using StackExchange.Redis; |
||||
|
using System; |
||||
|
using System.Text.Encodings.Web; |
||||
|
using System.Text.Unicode; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Volo.Abp.Authorization.Permissions; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.Domain.Entities.Events.Distributed; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Abp.Identity.Localization; |
||||
|
using Volo.Abp.Json.SystemTextJson; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.PermissionManagement; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
|
||||
|
namespace LINGYUN.Abp.BackendAdmin |
||||
|
{ |
||||
|
public partial class BackendAdminHostModule |
||||
|
{ |
||||
|
private void PreConfigureCAP(IConfiguration configuration) |
||||
|
{ |
||||
|
PreConfigure<CapOptions>(options => |
||||
|
{ |
||||
|
options |
||||
|
.UseMySql(configuration.GetConnectionString("Default")) |
||||
|
.UseRabbitMQ(rabbitMQOptions => |
||||
|
{ |
||||
|
configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); |
||||
|
}) |
||||
|
.UseDashboard(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureDbContext() |
||||
|
{ |
||||
|
// 配置Ef
|
||||
|
Configure<AbpDbContextOptions>(options => |
||||
|
{ |
||||
|
options.UseMySQL(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureJsonSerializer() |
||||
|
{ |
||||
|
// 中文序列化的编码问题
|
||||
|
Configure<AbpSystemTextJsonSerializerOptions>(options => |
||||
|
{ |
||||
|
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigurePermissionManagement() |
||||
|
{ |
||||
|
Configure<PermissionManagementOptions>(options => |
||||
|
{ |
||||
|
// Rename IdentityServer.Client.ManagePermissions
|
||||
|
// See https://github.com/abpframework/abp/blob/dev/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs
|
||||
|
options.ProviderPolicies[ClientPermissionValueProvider.ProviderName] = |
||||
|
LINGYUN.Abp.IdentityServer.AbpIdentityServerPermissions.Clients.ManagePermissions; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureExceptionHandling() |
||||
|
{ |
||||
|
// 自定义需要处理的异常
|
||||
|
Configure<AbpExceptionHandlingOptions>(options => |
||||
|
{ |
||||
|
// 加入需要处理的异常类型
|
||||
|
options.Handlers.Add<Volo.Abp.Data.AbpDbConcurrencyException>(); |
||||
|
options.Handlers.Add<AbpInitializationException>(); |
||||
|
options.Handlers.Add<ObjectDisposedException>(); |
||||
|
options.Handlers.Add<StackOverflowException>(); |
||||
|
options.Handlers.Add<OutOfMemoryException>(); |
||||
|
options.Handlers.Add<System.Data.Common.DbException>(); |
||||
|
options.Handlers.Add<Microsoft.EntityFrameworkCore.DbUpdateException>(); |
||||
|
options.Handlers.Add<System.Data.DBConcurrencyException>(); |
||||
|
}); |
||||
|
|
||||
|
// 自定义需要发送邮件通知的异常类型
|
||||
|
Configure<AbpEmailExceptionHandlingOptions>(options => |
||||
|
{ |
||||
|
// 是否发送堆栈信息
|
||||
|
options.SendStackTrace = true; |
||||
|
// 未指定异常接收者的默认接收邮件
|
||||
|
// 请指定自己的邮件地址
|
||||
|
// options.DefaultReceiveEmail = "colin.in@foxmail.com";
|
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureCaching(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpDistributedCacheOptions>(options => |
||||
|
{ |
||||
|
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
|
||||
|
options.KeyPrefix = "LINGYUN.Abp.Application"; |
||||
|
// 滑动过期30天
|
||||
|
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); |
||||
|
// 绝对过期60天
|
||||
|
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); |
||||
|
}); |
||||
|
|
||||
|
Configure<AbpDistributedEntityEventOptions>(options => |
||||
|
{ |
||||
|
options.AutoEventSelectors.AddNamespace("Volo.Abp.TenantManagement"); |
||||
|
}); |
||||
|
|
||||
|
Configure<RedisCacheOptions>(options => |
||||
|
{ |
||||
|
var redisConfig = ConfigurationOptions.Parse(options.Configuration); |
||||
|
options.ConfigurationOptions = redisConfig; |
||||
|
options.InstanceName = configuration["Redis:InstanceName"]; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureVirtualFileSystem() |
||||
|
{ |
||||
|
Configure<AbpVirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<BackendAdminHostModule>("LINGYUN.Abp.BackendAdmin"); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureMultiTenancy(IConfiguration configuration) |
||||
|
{ |
||||
|
// 多租户
|
||||
|
Configure<AbpMultiTenancyOptions>(options => |
||||
|
{ |
||||
|
options.IsEnabled = true; |
||||
|
}); |
||||
|
|
||||
|
var tenantResolveCfg = configuration.GetSection("App:Domains"); |
||||
|
if (tenantResolveCfg.Exists()) |
||||
|
{ |
||||
|
Configure<AbpTenantResolveOptions>(options => |
||||
|
{ |
||||
|
var domains = tenantResolveCfg.Get<string[]>(); |
||||
|
foreach (var domain in domains) |
||||
|
{ |
||||
|
options.AddDomainTenantResolver(domain); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void ConfigureAuditing(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpAuditingOptions>(options => |
||||
|
{ |
||||
|
options.ApplicationName = "Backend-Admin"; |
||||
|
// 是否启用实体变更记录
|
||||
|
var entitiesChangedConfig = configuration.GetSection("App:TrackingEntitiesChanged"); |
||||
|
if (entitiesChangedConfig.Exists() && entitiesChangedConfig.Get<bool>()) |
||||
|
{ |
||||
|
options |
||||
|
.EntityHistorySelectors |
||||
|
.AddAllEntities(); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSwagger(IServiceCollection services) |
||||
|
{ |
||||
|
// Swagger
|
||||
|
services.AddSwaggerGen( |
||||
|
options => |
||||
|
{ |
||||
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "BackendAdmin API", Version = "v1" }); |
||||
|
options.DocInclusionPredicate((docName, description) => true); |
||||
|
options.CustomSchemaIds(type => type.FullName); |
||||
|
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme |
||||
|
{ |
||||
|
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", |
||||
|
Name = "Authorization", |
||||
|
In = ParameterLocation.Header, |
||||
|
Scheme = "bearer", |
||||
|
Type = SecuritySchemeType.Http, |
||||
|
BearerFormat = "JWT" |
||||
|
}); |
||||
|
options.AddSecurityRequirement(new OpenApiSecurityRequirement |
||||
|
{ |
||||
|
{ |
||||
|
new OpenApiSecurityScheme |
||||
|
{ |
||||
|
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } |
||||
|
}, |
||||
|
new string[] { } |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureLocalization() |
||||
|
{ |
||||
|
// 支持本地化语言类型
|
||||
|
Configure<AbpLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
||||
|
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
||||
|
|
||||
|
options.Resources |
||||
|
.Get<IdentityResource>() |
||||
|
.AddVirtualJson("/Localization"); |
||||
|
options |
||||
|
.AddLanguagesMapOrUpdate( |
||||
|
"vue-admin-element-ui", |
||||
|
new NameValue("zh-Hans", "zh"), |
||||
|
new NameValue("en", "en")); |
||||
|
|
||||
|
// vben admin 语言映射
|
||||
|
options |
||||
|
.AddLanguagesMapOrUpdate( |
||||
|
"vben-admin-ui", |
||||
|
new NameValue("zh_CN", "zh-Hans")); |
||||
|
|
||||
|
options |
||||
|
.AddLanguageFilesMapOrUpdate( |
||||
|
"vue-admin-element-ui", |
||||
|
new NameValue("zh-Hans", "zh"), |
||||
|
new NameValue("en", "en")); |
||||
|
options |
||||
|
.AddLanguageFilesMapOrUpdate( |
||||
|
"vben-admin-ui", |
||||
|
new NameValue("zh_CN", "zh-Hans")); |
||||
|
|
||||
|
options.Resources.AddDynamic(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSecurity(IServiceCollection services, IConfiguration configuration, bool isDevelopment = false) |
||||
|
{ |
||||
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) |
||||
|
.AddJwtBearer(options => |
||||
|
{ |
||||
|
options.Authority = configuration["AuthServer:Authority"]; |
||||
|
options.RequireHttpsMetadata = false; |
||||
|
options.Audience = configuration["AuthServer:ApiName"]; |
||||
|
}); |
||||
|
|
||||
|
if (!isDevelopment) |
||||
|
{ |
||||
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
||||
|
services |
||||
|
.AddDataProtection() |
||||
|
.PersistKeysToStackExchangeRedis(redis, "BackendAdmin-Protection-Keys"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace LINGYUN.Abp.BackendAdmin |
||||
|
{ |
||||
|
public partial class BackendAdminHostModule |
||||
|
{ |
||||
|
private void UseDevelopment(IApplicationBuilder app, ApplicationInitializationContext context) |
||||
|
{ |
||||
|
if (context.GetEnvironment().IsDevelopment()) |
||||
|
{ |
||||
|
app.UseProxyConnectTest(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.Threading; |
||||
|
|
||||
|
namespace LINGYUN.Abp.BackendAdmin |
||||
|
{ |
||||
|
public partial class BackendAdminHostModule |
||||
|
{ |
||||
|
private static void SeedData(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
if (context.GetEnvironment().IsDevelopment()) |
||||
|
{ |
||||
|
AsyncHelper.RunSync(async () => |
||||
|
{ |
||||
|
using var scope = context.ServiceProvider.CreateScope(); |
||||
|
await scope.ServiceProvider.GetRequiredService<IDataSeeder>().SeedAsync(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,30 +1,28 @@ |
|||||
using Microsoft.EntityFrameworkCore; |
using Microsoft.EntityFrameworkCore; |
||||
using Volo.Abp.AuditLogging.EntityFrameworkCore; |
using Volo.Abp.EntityFrameworkCore; |
||||
using Volo.Abp.EntityFrameworkCore; |
using Volo.Abp.FeatureManagement.EntityFrameworkCore; |
||||
using Volo.Abp.FeatureManagement.EntityFrameworkCore; |
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
||||
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
||||
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
||||
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
|
||||
|
namespace LINGYUN.Abp.BackendAdmin.EntityFrameworkCore |
||||
namespace LINGYUN.Abp.BackendAdmin.EntityFrameworkCore |
{ |
||||
{ |
public class BackendAdminHostMigrationsDbContext : AbpDbContext<BackendAdminHostMigrationsDbContext> |
||||
public class BackendAdminHostMigrationsDbContext : AbpDbContext<BackendAdminHostMigrationsDbContext> |
{ |
||||
{ |
public BackendAdminHostMigrationsDbContext(DbContextOptions<BackendAdminHostMigrationsDbContext> options) |
||||
public BackendAdminHostMigrationsDbContext(DbContextOptions<BackendAdminHostMigrationsDbContext> options) |
: base(options) |
||||
: base(options) |
{ |
||||
{ |
|
||||
|
} |
||||
} |
|
||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder) |
||||
protected override void OnModelCreating(ModelBuilder modelBuilder) |
{ |
||||
{ |
base.OnModelCreating(modelBuilder); |
||||
base.OnModelCreating(modelBuilder); |
|
||||
|
modelBuilder.ConfigureFeatureManagement(); |
||||
modelBuilder.ConfigureAuditLogging(); |
modelBuilder.ConfigureTenantManagement(); |
||||
modelBuilder.ConfigureFeatureManagement(); |
modelBuilder.ConfigureSettingManagement(); |
||||
modelBuilder.ConfigureTenantManagement(); |
modelBuilder.ConfigurePermissionManagement(); |
||||
modelBuilder.ConfigureSettingManagement(); |
} |
||||
modelBuilder.ConfigurePermissionManagement(); |
} |
||||
} |
} |
||||
} |
|
||||
} |
|
||||
|
|||||
@ -0,0 +1,92 @@ |
|||||
|
{ |
||||
|
"App": { |
||||
|
"TrackingEntitiesChanged": true, |
||||
|
"Forwarded": { |
||||
|
"ForwardedHeaders": 5, |
||||
|
"KnownProxies": [ |
||||
|
"localhost" |
||||
|
] |
||||
|
} |
||||
|
}, |
||||
|
"ConnectionStrings": { |
||||
|
"Default": "Server=localhost;Database=Platform;User Id=colin;Password=123456", |
||||
|
"AbpIdentity": "Server=localhost;Database=IdentityServer;User Id=colin;Password=123456", |
||||
|
"AbpIdentityServer": "Server=localhost;Database=IdentityServer;User Id=colin;Password=123456", |
||||
|
"AbpTenantManagement": "Server=localhost;Database=Platform;User Id=colin;Password=123456", |
||||
|
"AbpSettingManagement": "Server=localhost;Database=Platform;User Id=colin;Password=123456", |
||||
|
"AbpFeatureManagement": "Server=localhost;Database=Platform;User Id=colin;Password=123456", |
||||
|
"AbpPermissionManagement": "Server=localhost;Database=Platform;User Id=colin;Password=123456", |
||||
|
"AbpLocalizationManagement": "Server=localhost;Database=Platform;User Id=colin;Password=123456" |
||||
|
}, |
||||
|
"CAP": { |
||||
|
"EventBus": { |
||||
|
"DefaultGroup": "BackendAdmin", |
||||
|
"Version": "v1", |
||||
|
"FailedRetryInterval": 300, |
||||
|
"FailedRetryCount": 10 |
||||
|
}, |
||||
|
"MySql": { |
||||
|
"TableNamePrefix": "admin", |
||||
|
"ConnectionString": "Server=localhost;Database=Platform;User Id=root;Password=123456" |
||||
|
}, |
||||
|
"RabbitMQ": { |
||||
|
"HostName": "localhost", |
||||
|
"Port": 5672, |
||||
|
"UserName": "guest", |
||||
|
"Password": "guest", |
||||
|
"ExchangeName": "LINGYUN.Abp.Application", |
||||
|
"VirtualHost": "/" |
||||
|
} |
||||
|
}, |
||||
|
"Redis": { |
||||
|
"Configuration": "localhost,defaultDatabase=10", |
||||
|
"InstanceName": "LINGYUN.Abp.Application" |
||||
|
}, |
||||
|
"AuthServer": { |
||||
|
"Authority": "http://localhost:44385/", |
||||
|
"ApiName": "lingyun-abp-application" |
||||
|
}, |
||||
|
"Logging": { |
||||
|
"Serilog": { |
||||
|
"Elasticsearch": { |
||||
|
"IndexFormat": "lingyun.abp.logging-{0:yyyy.MM.dd}" |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
"AuditLogging": { |
||||
|
"Elasticsearch": { |
||||
|
"IndexPrefix": "lingyun.abp.auditing" |
||||
|
} |
||||
|
}, |
||||
|
"Elasticsearch": { |
||||
|
"NodeUris": "http://localhost:9200" |
||||
|
}, |
||||
|
"Serilog": { |
||||
|
"MinimumLevel": { |
||||
|
"Default": "Debug", |
||||
|
"Override": { |
||||
|
"System": "Warning", |
||||
|
"Microsoft": "Warning", |
||||
|
"DotNetCore": "Debug" |
||||
|
} |
||||
|
}, |
||||
|
"WriteTo": [ |
||||
|
{ |
||||
|
"Name": "Console", |
||||
|
"Args": { |
||||
|
"restrictedToMinimumLevel": "Debug", |
||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
"Name": "Elasticsearch", |
||||
|
"Args": { |
||||
|
"nodeUris": "http://localhost:9200", |
||||
|
"indexFormat": "lingyun.abp.logging-{0:yyyy.MM.dd}", |
||||
|
"autoRegisterTemplate": true, |
||||
|
"autoRegisterTemplateVersion": "ESv7" |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,72 @@ |
|||||
|
{ |
||||
|
"StringEncryption": { |
||||
|
"DefaultPassPhrase": "s46c5q55nxpeS8Ra", |
||||
|
"InitVectorBytes": "s83ng0abvd02js84", |
||||
|
"DefaultSalt": "sf&5)s3#" |
||||
|
}, |
||||
|
"Serilog": { |
||||
|
"MinimumLevel": { |
||||
|
"Default": "Information", |
||||
|
"Override": { |
||||
|
"System": "Warning", |
||||
|
"Microsoft": "Warning", |
||||
|
"DotNetCore": "Information" |
||||
|
} |
||||
|
}, |
||||
|
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId", "WithEnvironmentName", "WithMachineName" ], |
||||
|
"WriteTo": [ |
||||
|
{ |
||||
|
"Name": "Console", |
||||
|
"Args": { |
||||
|
"restrictedToMinimumLevel": "Debug", |
||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
"Name": "File", |
||||
|
"Args": { |
||||
|
"path": "Logs/Debug-.log", |
||||
|
"restrictedToMinimumLevel": "Debug", |
||||
|
"rollingInterval": "Day", |
||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
"Name": "File", |
||||
|
"Args": { |
||||
|
"path": "Logs/Info-.log", |
||||
|
"restrictedToMinimumLevel": "Information", |
||||
|
"rollingInterval": "Day", |
||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
"Name": "File", |
||||
|
"Args": { |
||||
|
"path": "Logs/Warn-.log", |
||||
|
"restrictedToMinimumLevel": "Warning", |
||||
|
"rollingInterval": "Day", |
||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
"Name": "File", |
||||
|
"Args": { |
||||
|
"path": "Logs/Error-.log", |
||||
|
"restrictedToMinimumLevel": "Error", |
||||
|
"rollingInterval": "Day", |
||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
"Name": "File", |
||||
|
"Args": { |
||||
|
"path": "Logs/Fatal-.log", |
||||
|
"restrictedToMinimumLevel": "Fatal", |
||||
|
"rollingInterval": "Day", |
||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,79 @@ |
|||||
|
{ |
||||
|
"EnabledDynamicOcelot": true, |
||||
|
"ApiGateway": { |
||||
|
"AppId": "TEST-APP" //这里是用于Ocelot主机去API服务器获取参数的标识,指定需要获取什么类型的网关配置 |
||||
|
}, |
||||
|
"Redis": { |
||||
|
"Configuration": "localhost,defaultDatabase=10", |
||||
|
"InstanceName": "LINGYUN.Abp.Application" |
||||
|
}, |
||||
|
"RemoteServices": { |
||||
|
"ApiGateway": { |
||||
|
"BaseUrl": "http://localhost:30001/", |
||||
|
"IdentityClient": "ApigatewayHostClient" |
||||
|
} |
||||
|
}, |
||||
|
"IdentityClients": { |
||||
|
"ApigatewayHostClient": { |
||||
|
"Authority": "http://localhost:44385", |
||||
|
"RequireHttps": false, |
||||
|
"GrantType": "client_credentials", |
||||
|
"ClientId": "ApigatewayHostClient", |
||||
|
"ClientSecret": "1q2w3e*", |
||||
|
"Scope": "lingyun-abp-application" |
||||
|
} |
||||
|
}, |
||||
|
"CAP": { |
||||
|
"Abp": { |
||||
|
"NotifyFailedCallback": true, |
||||
|
"CleanUpExpiresMessageBatch": 1000, |
||||
|
"CleanUpExpiresMessageInterval": 3600000 |
||||
|
}, |
||||
|
"EventBus": { |
||||
|
"DefaultGroupName": "ApiGateway-Host", |
||||
|
"Version": "v1", |
||||
|
"FailedRetryInterval": 300, |
||||
|
"FailedRetryCount": 10 |
||||
|
}, |
||||
|
"RabbitMQ": { |
||||
|
"HostName": "localhost", |
||||
|
"Port": 5672, |
||||
|
"UserName": "guest", |
||||
|
"Password": "guest", |
||||
|
"ExchangeName": "LINGYUN.ApiGateway", |
||||
|
"VirtualHost": "/" |
||||
|
} |
||||
|
}, |
||||
|
"AuthServer": { |
||||
|
"Authority": "http://localhost:44385/", |
||||
|
"ApiName": "lingyun-abp-application" |
||||
|
}, |
||||
|
"Serilog": { |
||||
|
"MinimumLevel": { |
||||
|
"Default": "Debug", |
||||
|
"Override": { |
||||
|
"System": "Warning", |
||||
|
"Microsoft": "Warning", |
||||
|
"DotNetCore": "Debug" |
||||
|
} |
||||
|
}, |
||||
|
"WriteTo": [ |
||||
|
{ |
||||
|
"Name": "Console", |
||||
|
"Args": { |
||||
|
"restrictedToMinimumLevel": "Debug", |
||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
"Name": "Elasticsearch", |
||||
|
"Args": { |
||||
|
"nodeUris": "http://localhost:9200", |
||||
|
"indexFormat": "lingyun.abp.logging-{0:yyyy.MM.dd}", |
||||
|
"autoRegisterTemplate": true, |
||||
|
"autoRegisterTemplateVersion": "ESv7" |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
} |
||||
@ -1,94 +1,73 @@ |
|||||
{ |
{ |
||||
"App": { |
"StringEncryption": { |
||||
"TrackingEntitiesChanged": true, |
"DefaultPassPhrase": "s46c5q55nxpeS8Ra", |
||||
"SelfUrl": "http://localhost:44385/" |
"InitVectorBytes": "s83ng0abvd02js84", |
||||
}, |
"DefaultSalt": "sf&5)s3#" |
||||
"ConnectionStrings": { |
}, |
||||
"Default": "Server=127.0.0.1;Database=ApiGateway;User Id=root;Password=123456", |
"Serilog": { |
||||
"ApiGateway": "Server=127.0.0.1;Database=ApiGateway;User Id=root;Password=123456", |
"MinimumLevel": { |
||||
"AbpTenantManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
"Default": "Debug", |
||||
"AbpSettingManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
"Override": { |
||||
"AbpPermissionManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456" |
"System": "Warning", |
||||
}, |
"Microsoft": "Warning" |
||||
"Redis": { |
} |
||||
"Configuration": "127.0.0.1,defaultDatabase=10", |
}, |
||||
"InstanceName": "LINGYUN.AbpApplication" |
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId", "WithEnvironmentName", "WithMachineName" ], |
||||
}, |
"WriteTo": [ |
||||
"CAP": { |
{ |
||||
"EventBus": { |
"Name": "Console", |
||||
"DefaultGroupName": "ApiGateway-Admin", |
"Args": { |
||||
"Version": "v1", |
"initialMinimumLevel": "Information", |
||||
"FailedRetryInterval": 300, |
"standardErrorFromLevel": "Information", |
||||
"FailedRetryCount": 10 |
"restrictedToMinimumLevel": "Information", |
||||
}, |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"RabbitMQ": { |
} |
||||
"HostName": "127.0.0.1", |
}, |
||||
"Port": 5672, |
{ |
||||
"UserName": "admin", |
"Name": "File", |
||||
"Password": "admin", |
"Args": { |
||||
"ExchangeName": "LINGYUN.ApiGateway", |
"path": "Logs/Debug-.log", |
||||
"VirtualHost": "multi.service.test" |
"restrictedToMinimumLevel": "Debug", |
||||
} |
"rollingInterval": "Day", |
||||
}, |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"AuthServer": { |
} |
||||
"Authority": "http://localhost:44385/", |
}, |
||||
"ApiName": "lingyun-abp-application" |
{ |
||||
}, |
"Name": "File", |
||||
"Serilog": { |
"Args": { |
||||
"MinimumLevel": { |
"path": "Logs/Info-.log", |
||||
"Default": "Debug", |
"restrictedToMinimumLevel": "Information", |
||||
"Override": { |
"rollingInterval": "Day", |
||||
"System": "Warning", |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"Microsoft": "Warning" |
} |
||||
} |
}, |
||||
}, |
{ |
||||
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId" ], |
"Name": "File", |
||||
"WriteTo": [ |
"Args": { |
||||
{ |
"path": "Logs/Warn-.log", |
||||
"Name": "File", |
"restrictedToMinimumLevel": "Warning", |
||||
"Args": { |
"rollingInterval": "Day", |
||||
"path": "Logs/Debug-.log", |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"restrictedToMinimumLevel": "Debug", |
} |
||||
"rollingInterval": "Day", |
}, |
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
{ |
||||
} |
"Name": "File", |
||||
}, |
"Args": { |
||||
{ |
"path": "Logs/Error-.log", |
||||
"Name": "File", |
"restrictedToMinimumLevel": "Error", |
||||
"Args": { |
"rollingInterval": "Day", |
||||
"path": "Logs/Info-.log", |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"restrictedToMinimumLevel": "Information", |
} |
||||
"rollingInterval": "Day", |
}, |
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
{ |
||||
} |
"Name": "File", |
||||
}, |
"Args": { |
||||
{ |
"path": "Logs/Fatal-.log", |
||||
"Name": "File", |
"restrictedToMinimumLevel": "Fatal", |
||||
"Args": { |
"rollingInterval": "Day", |
||||
"path": "Logs/Warn-.log", |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"restrictedToMinimumLevel": "Warning", |
} |
||||
"rollingInterval": "Day", |
} |
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
] |
||||
} |
} |
||||
}, |
} |
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Error-.log", |
|
||||
"restrictedToMinimumLevel": "Error", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Fatal-.log", |
|
||||
"restrictedToMinimumLevel": "Fatal", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
} |
|
||||
] |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,179 @@ |
|||||
|
using DotNetCore.CAP; |
||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer; |
||||
|
using Microsoft.AspNetCore.DataProtection; |
||||
|
using Microsoft.Extensions.Caching.StackExchangeRedis; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.OpenApi.Models; |
||||
|
using StackExchange.Redis; |
||||
|
using System; |
||||
|
using System.Text.Encodings.Web; |
||||
|
using System.Text.Unicode; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Volo.Abp.AutoMapper; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Abp.Json.SystemTextJson; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
|
||||
|
namespace LINGYUN.ApiGateway |
||||
|
{ |
||||
|
public partial class ApiGatewayHttpApiHostModule |
||||
|
{ |
||||
|
private void PreConfigureCAP(IConfiguration configuration) |
||||
|
{ |
||||
|
PreConfigure<CapOptions>(options => |
||||
|
{ |
||||
|
options |
||||
|
.UseMySql(configuration.GetConnectionString("Default")) |
||||
|
.UseRabbitMQ(rabbitMQOptions => |
||||
|
{ |
||||
|
configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private void ConfigureAutoMapper() |
||||
|
{ |
||||
|
Configure<AbpAutoMapperOptions>(options => |
||||
|
{ |
||||
|
options.AddProfile<ApiGatewayHttpApiHostAutoMapperProfile>(validate: true); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureDbContext() |
||||
|
{ |
||||
|
// 配置Ef
|
||||
|
Configure<AbpDbContextOptions>(options => |
||||
|
{ |
||||
|
options.UseMySQL(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureJsonSerializer() |
||||
|
{ |
||||
|
// 中文序列化的编码问题
|
||||
|
Configure<AbpSystemTextJsonSerializerOptions>(options => |
||||
|
{ |
||||
|
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureCaching(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpDistributedCacheOptions>(options => |
||||
|
{ |
||||
|
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
|
||||
|
options.KeyPrefix = "LINGYUN.Abp.Application"; |
||||
|
// 滑动过期30天
|
||||
|
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); |
||||
|
// 绝对过期60天
|
||||
|
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(60); |
||||
|
}); |
||||
|
|
||||
|
Configure<RedisCacheOptions>(options => |
||||
|
{ |
||||
|
var redisConfig = ConfigurationOptions.Parse(options.Configuration); |
||||
|
options.ConfigurationOptions = redisConfig; |
||||
|
options.InstanceName = configuration["Redis:InstanceName"]; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureVirtualFileSystem() |
||||
|
{ |
||||
|
Configure<AbpVirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<ApiGatewayHttpApiHostModule>(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureMultiTenancy(IConfiguration configuration) |
||||
|
{ |
||||
|
// 多租户
|
||||
|
Configure<AbpMultiTenancyOptions>(options => |
||||
|
{ |
||||
|
options.IsEnabled = false; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureAuditing(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpAuditingOptions>(options => |
||||
|
{ |
||||
|
options.ApplicationName = "ApiGateWay-Admin"; |
||||
|
// 是否启用实体变更记录
|
||||
|
var entitiesChangedConfig = configuration.GetSection("App:TrackingEntitiesChanged"); |
||||
|
if (entitiesChangedConfig.Exists() && entitiesChangedConfig.Get<bool>()) |
||||
|
{ |
||||
|
options |
||||
|
.EntityHistorySelectors |
||||
|
.AddAllEntities(); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSwagger(IServiceCollection services) |
||||
|
{ |
||||
|
// Swagger
|
||||
|
services.AddSwaggerGen( |
||||
|
options => |
||||
|
{ |
||||
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "ApiGateway API", Version = "v1" }); |
||||
|
options.DocInclusionPredicate((docName, description) => true); |
||||
|
options.CustomSchemaIds(type => type.FullName); |
||||
|
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme |
||||
|
{ |
||||
|
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", |
||||
|
Name = "Authorization", |
||||
|
In = ParameterLocation.Header, |
||||
|
Scheme = "bearer", |
||||
|
Type = SecuritySchemeType.Http, |
||||
|
BearerFormat = "JWT" |
||||
|
}); |
||||
|
options.AddSecurityRequirement(new OpenApiSecurityRequirement |
||||
|
{ |
||||
|
{ |
||||
|
new OpenApiSecurityScheme |
||||
|
{ |
||||
|
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } |
||||
|
}, |
||||
|
new string[] { } |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureLocalization() |
||||
|
{ |
||||
|
// 支持本地化语言类型
|
||||
|
Configure<AbpLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
||||
|
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSecurity(IServiceCollection services, IConfiguration configuration, bool isDevelopment = false) |
||||
|
{ |
||||
|
services |
||||
|
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) |
||||
|
.AddJwtBearer(options => |
||||
|
{ |
||||
|
options.Authority = configuration["AuthServer:Authority"]; |
||||
|
options.RequireHttpsMetadata = false; |
||||
|
options.Audience = configuration["AuthServer:ApiName"]; |
||||
|
}); |
||||
|
|
||||
|
if (!isDevelopment) |
||||
|
{ |
||||
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
||||
|
services |
||||
|
.AddDataProtection() |
||||
|
.PersistKeysToStackExchangeRedis(redis, "ApiGatewayAdmin-Protection-Keys"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.Threading; |
||||
|
|
||||
|
namespace LINGYUN.ApiGateway |
||||
|
{ |
||||
|
public partial class ApiGatewayHttpApiHostModule |
||||
|
{ |
||||
|
private void SeedData(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
var configuration = context.GetConfiguration(); |
||||
|
if (configuration.GetSection("ApiGateway:SeedInitScript").Get<bool>()) |
||||
|
{ |
||||
|
AsyncHelper.RunSync(async () => |
||||
|
{ |
||||
|
using var scope = context.ServiceProvider.CreateScope(); |
||||
|
await scope.ServiceProvider.GetRequiredService<IDataSeeder>().SeedAsync(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,259 +1,97 @@ |
|||||
using DotNetCore.CAP; |
using LINGYUN.Abp.AspNetCore.HttpOverrides; |
||||
using LINGYUN.Abp.AspNetCore.HttpOverrides; |
using LINGYUN.Abp.AuditLogging.Elasticsearch; |
||||
using LINGYUN.Abp.EventBus.CAP; |
using LINGYUN.Abp.EventBus.CAP; |
||||
using LINGYUN.Abp.MultiTenancy.DbFinder; |
using LINGYUN.Abp.MultiTenancy.DbFinder; |
||||
using LINGYUN.ApiGateway.EntityFrameworkCore; |
using LINGYUN.ApiGateway.EntityFrameworkCore; |
||||
using Microsoft.AspNetCore.Authentication.JwtBearer; |
using Microsoft.AspNetCore.Builder; |
||||
using Microsoft.AspNetCore.Builder; |
using Microsoft.AspNetCore.Hosting; |
||||
using Microsoft.AspNetCore.DataProtection; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Microsoft.AspNetCore.Hosting; |
using Microsoft.Extensions.Hosting; |
||||
using Microsoft.Extensions.Caching.StackExchangeRedis; |
using Volo.Abp; |
||||
using Microsoft.Extensions.Configuration; |
using Volo.Abp.AspNetCore.Serilog; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Volo.Abp.Autofac; |
||||
using Microsoft.Extensions.Hosting; |
using Volo.Abp.Caching.StackExchangeRedis; |
||||
using Microsoft.OpenApi.Models; |
using Volo.Abp.EntityFrameworkCore.MySQL; |
||||
using StackExchange.Redis; |
using Volo.Abp.Modularity; |
||||
using System; |
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
||||
using System.Text; |
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
||||
using System.Text.Encodings.Web; |
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
||||
using System.Text.Unicode; |
|
||||
using Volo.Abp; |
namespace LINGYUN.ApiGateway |
||||
using Volo.Abp.AspNetCore.Security.Claims; |
{ |
||||
using Volo.Abp.Auditing; |
[DependsOn( |
||||
using Volo.Abp.AuditLogging.EntityFrameworkCore; |
typeof(AbpAspNetCoreSerilogModule), |
||||
using Volo.Abp.Autofac; |
typeof(AbpAuditLoggingElasticsearchModule), |
||||
using Volo.Abp.AutoMapper; |
typeof(ApiGatewayApplicationModule), |
||||
using Volo.Abp.Caching; |
typeof(ApiGatewayEntityFrameworkCoreModule), |
||||
using Volo.Abp.Caching.StackExchangeRedis; |
typeof(ApiGatewayHttpApiModule), |
||||
using Volo.Abp.Data; |
typeof(AbpEntityFrameworkCoreMySQLModule), |
||||
using Volo.Abp.EntityFrameworkCore; |
typeof(AbpTenantManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.EntityFrameworkCore.MySQL; |
typeof(AbpSettingManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.Json; |
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.Json.SystemTextJson; |
typeof(AbpCAPEventBusModule), |
||||
using Volo.Abp.Localization; |
typeof(AbpDbFinderMultiTenancyModule), |
||||
using Volo.Abp.Modularity; |
typeof(AbpCachingStackExchangeRedisModule), |
||||
using Volo.Abp.MultiTenancy; |
typeof(AbpAspNetCoreHttpOverridesModule), |
||||
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
typeof(AbpAutofacModule) |
||||
using Volo.Abp.Security.Claims; |
)] |
||||
using Volo.Abp.Security.Encryption; |
public partial class ApiGatewayHttpApiHostModule : AbpModule |
||||
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
{ |
||||
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
public override void PreConfigureServices(ServiceConfigurationContext context) |
||||
using Volo.Abp.Threading; |
{ |
||||
|
var configuration = context.Services.GetConfiguration(); |
||||
namespace LINGYUN.ApiGateway |
|
||||
{ |
PreConfigureCAP(configuration); |
||||
[DependsOn( |
} |
||||
typeof(ApiGatewayApplicationModule), |
|
||||
typeof(ApiGatewayEntityFrameworkCoreModule), |
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
typeof(ApiGatewayHttpApiModule), |
{ |
||||
typeof(AbpEntityFrameworkCoreMySQLModule), |
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
||||
typeof(AbpAuditLoggingEntityFrameworkCoreModule), |
var configuration = hostingEnvironment.BuildConfiguration(); |
||||
typeof(AbpTenantManagementEntityFrameworkCoreModule), |
|
||||
typeof(AbpSettingManagementEntityFrameworkCoreModule), |
ConfigureDbContext(); |
||||
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
ConfigureAutoMapper(); |
||||
typeof(AbpCAPEventBusModule), |
ConfigureJsonSerializer(); |
||||
typeof(AbpDbFinderMultiTenancyModule), |
ConfigureVirtualFileSystem(); |
||||
typeof(AbpCachingStackExchangeRedisModule), |
ConfigureCaching(configuration); |
||||
typeof(AbpAspNetCoreHttpOverridesModule), |
ConfigureMultiTenancy(configuration); |
||||
typeof(AbpAutofacModule) |
ConfigureAuditing(configuration); |
||||
)] |
ConfigureSwagger(context.Services); |
||||
public class ApiGatewayHttpApiHostModule : AbpModule |
ConfigureLocalization(); |
||||
{ |
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); |
||||
public override void PreConfigureServices(ServiceConfigurationContext context) |
} |
||||
{ |
|
||||
var configuration = context.Services.GetConfiguration(); |
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
||||
|
{ |
||||
PreConfigure<CapOptions>(options => |
var app = context.GetApplicationBuilder(); |
||||
{ |
// http调用链
|
||||
options |
app.UseCorrelationId(); |
||||
.UseMySql(configuration.GetConnectionString("Default")) |
// 虚拟文件系统
|
||||
.UseRabbitMQ(rabbitMQOptions => |
app.UseStaticFiles(); |
||||
{ |
//路由
|
||||
configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); |
app.UseRouting(); |
||||
}); |
// 认证
|
||||
}); |
app.UseAuthentication(); |
||||
} |
// 多租户
|
||||
|
// app.UseMultiTenancy();
|
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
// 本地化
|
||||
{ |
app.UseAbpRequestLocalization(); |
||||
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
// 认证
|
||||
var configuration = hostingEnvironment.BuildConfiguration(); |
app.UseAuthorization(); |
||||
|
// Swagger
|
||||
// 配置Ef
|
app.UseSwagger(); |
||||
Configure<AbpDbContextOptions>(options => |
// Swagger可视化界面
|
||||
{ |
app.UseSwaggerUI(options => |
||||
options.UseMySQL(); |
{ |
||||
}); |
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support ApiGateway API"); |
||||
|
}); |
||||
// 中文序列化的编码问题
|
// 审计日志
|
||||
Configure<AbpSystemTextJsonSerializerOptions>(options => |
app.UseAuditing(); |
||||
{ |
app.UseAbpSerilogEnrichers(); |
||||
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); |
// 路由
|
||||
}); |
app.UseConfiguredEndpoints(); |
||||
|
|
||||
// 加解密
|
SeedData(context); |
||||
Configure<AbpStringEncryptionOptions>(options => |
} |
||||
{ |
} |
||||
var encryptionConfiguration = configuration.GetSection("Encryption"); |
} |
||||
if (encryptionConfiguration.Exists()) |
|
||||
{ |
|
||||
options.DefaultPassPhrase = encryptionConfiguration["PassPhrase"] ?? options.DefaultPassPhrase; |
|
||||
options.DefaultSalt = encryptionConfiguration.GetSection("Salt").Exists() |
|
||||
? Encoding.ASCII.GetBytes(encryptionConfiguration["Salt"]) |
|
||||
: options.DefaultSalt; |
|
||||
options.InitVectorBytes = encryptionConfiguration.GetSection("InitVector").Exists() |
|
||||
? Encoding.ASCII.GetBytes(encryptionConfiguration["InitVector"]) |
|
||||
: options.InitVectorBytes; |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
Configure<AbpDistributedCacheOptions>(options => |
|
||||
{ |
|
||||
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
|
|
||||
options.KeyPrefix = "LINGYUN.Abp.Application"; |
|
||||
// 滑动过期30天
|
|
||||
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); |
|
||||
// 绝对过期60天
|
|
||||
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(60); |
|
||||
}); |
|
||||
|
|
||||
Configure<RedisCacheOptions>(options => |
|
||||
{ |
|
||||
var redisConfig = ConfigurationOptions.Parse(options.Configuration); |
|
||||
options.ConfigurationOptions = redisConfig; |
|
||||
options.InstanceName = configuration["Redis:InstanceName"]; |
|
||||
}); |
|
||||
|
|
||||
// 多租户
|
|
||||
Configure<AbpMultiTenancyOptions>(options => |
|
||||
{ |
|
||||
options.IsEnabled = false; |
|
||||
}); |
|
||||
|
|
||||
Configure<AbpAuditingOptions>(options => |
|
||||
{ |
|
||||
options.ApplicationName = "ApiGateWay-Admin"; |
|
||||
// 是否启用实体变更记录
|
|
||||
var entitiesChangedConfig = configuration.GetSection("App:TrackingEntitiesChanged"); |
|
||||
if (entitiesChangedConfig.Exists() && entitiesChangedConfig.Get<bool>()) |
|
||||
{ |
|
||||
options |
|
||||
.EntityHistorySelectors |
|
||||
.AddAllEntities(); |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
//Configure<AbpTenantResolveOptions>(options =>
|
|
||||
//{
|
|
||||
// options.TenantResolvers.Insert(0, new AuthorizationTenantResolveContributor());
|
|
||||
//});
|
|
||||
|
|
||||
// Swagger
|
|
||||
context.Services.AddSwaggerGen( |
|
||||
options => |
|
||||
{ |
|
||||
options.SwaggerDoc("v1", new OpenApiInfo { Title = "ApiGateway API", Version = "v1" }); |
|
||||
options.DocInclusionPredicate((docName, description) => true); |
|
||||
options.CustomSchemaIds(type => type.FullName); |
|
||||
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme |
|
||||
{ |
|
||||
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", |
|
||||
Name = "Authorization", |
|
||||
In = ParameterLocation.Header, |
|
||||
Scheme = "bearer", |
|
||||
Type = SecuritySchemeType.Http, |
|
||||
BearerFormat = "JWT" |
|
||||
}); |
|
||||
options.AddSecurityRequirement(new OpenApiSecurityRequirement |
|
||||
{ |
|
||||
{ |
|
||||
new OpenApiSecurityScheme |
|
||||
{ |
|
||||
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } |
|
||||
}, |
|
||||
new string[] { } |
|
||||
} |
|
||||
}); |
|
||||
}); |
|
||||
|
|
||||
// 支持本地化语言类型
|
|
||||
Configure<AbpLocalizationOptions>(options => |
|
||||
{ |
|
||||
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
|
||||
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
|
||||
}); |
|
||||
|
|
||||
Configure<AbpClaimsMapOptions>(options => |
|
||||
{ |
|
||||
options.Maps.TryAdd("name", () => AbpClaimTypes.UserName); |
|
||||
}); |
|
||||
|
|
||||
context.Services |
|
||||
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) |
|
||||
.AddJwtBearer(options => |
|
||||
{ |
|
||||
options.Authority = configuration["AuthServer:Authority"]; |
|
||||
options.RequireHttpsMetadata = false; |
|
||||
options.Audience = configuration["AuthServer:ApiName"]; |
|
||||
}); |
|
||||
|
|
||||
if (!hostingEnvironment.IsDevelopment()) |
|
||||
{ |
|
||||
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
|
||||
context.Services |
|
||||
.AddDataProtection() |
|
||||
.PersistKeysToStackExchangeRedis(redis, "ApiGatewayAdmin-Protection-Keys"); |
|
||||
} |
|
||||
|
|
||||
Configure<AbpAutoMapperOptions>(options => |
|
||||
{ |
|
||||
options.AddProfile<ApiGatewayHttpApiHostAutoMapperProfile>(validate: true); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|
||||
{ |
|
||||
var app = context.GetApplicationBuilder(); |
|
||||
var configuration = context.GetConfiguration(); |
|
||||
// http调用链
|
|
||||
app.UseCorrelationId(); |
|
||||
// 虚拟文件系统
|
|
||||
app.UseStaticFiles(); |
|
||||
//路由
|
|
||||
app.UseRouting(); |
|
||||
// 认证
|
|
||||
app.UseAuthentication(); |
|
||||
// 多租户
|
|
||||
// app.UseMultiTenancy();
|
|
||||
// 本地化
|
|
||||
app.UseAbpRequestLocalization(); |
|
||||
// 认证
|
|
||||
app.UseAuthorization(); |
|
||||
// Swagger
|
|
||||
app.UseSwagger(); |
|
||||
// Swagger可视化界面
|
|
||||
app.UseSwaggerUI(options => |
|
||||
{ |
|
||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support ApiGateway API"); |
|
||||
}); |
|
||||
// 审计日志
|
|
||||
app.UseAuditing(); |
|
||||
// 路由
|
|
||||
app.UseConfiguredEndpoints(); |
|
||||
|
|
||||
if (configuration.GetSection("ApiGateway:SeedInitScript").Get<bool>()) |
|
||||
{ |
|
||||
SeedData(context); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private void SeedData(ApplicationInitializationContext context) |
|
||||
{ |
|
||||
AsyncHelper.RunSync(async () => |
|
||||
{ |
|
||||
using var scope = context.ServiceProvider.CreateScope(); |
|
||||
await scope.ServiceProvider.GetRequiredService<IDataSeeder>().SeedAsync(); |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|||||
@ -0,0 +1,72 @@ |
|||||
|
{ |
||||
|
"App": { |
||||
|
"TrackingEntitiesChanged": true, |
||||
|
"SelfUrl": "http://localhost:30001/" |
||||
|
}, |
||||
|
"ConnectionStrings": { |
||||
|
"Default": "Server=localhost;Database=ApiGateway;User Id=root;Password=123456", |
||||
|
"ApiGateway": "Server=localhost;Database=ApiGateway;User Id=root;Password=123456", |
||||
|
"AbpTenantManagement": "Server=localhost;Database=Platform;User Id=root;Password=123456", |
||||
|
"AbpSettingManagement": "Server=localhost;Database=Platform;User Id=root;Password=123456", |
||||
|
"AbpPermissionManagement": "Server=localhost;Database=Platform;User Id=root;Password=123456" |
||||
|
}, |
||||
|
"Redis": { |
||||
|
"Configuration": "localhost,defaultDatabase=10", |
||||
|
"InstanceName": "LINGYUN.Abp.Application" |
||||
|
}, |
||||
|
"CAP": { |
||||
|
"EventBus": { |
||||
|
"DefaultGroupName": "ApiGateway-Admin", |
||||
|
"Version": "v1", |
||||
|
"FailedRetryInterval": 300, |
||||
|
"FailedRetryCount": 10 |
||||
|
}, |
||||
|
"MySql": { |
||||
|
"TableNamePrefix": "apa", |
||||
|
"ConnectionString": "Server=localhost;Database=ApiGateway;User Id=root;Password=123456" |
||||
|
}, |
||||
|
"RabbitMQ": { |
||||
|
"HostName": "localhost", |
||||
|
"Port": 5672, |
||||
|
"UserName": "guest", |
||||
|
"Password": "guest", |
||||
|
"ExchangeName": "LINGYUN.ApiGateway", |
||||
|
"VirtualHost": "/" |
||||
|
} |
||||
|
}, |
||||
|
"AuthServer": { |
||||
|
"Authority": "http://localhost:44385/", |
||||
|
"ApiName": "lingyun-abp-application" |
||||
|
}, |
||||
|
"Elasticsearch": { |
||||
|
"NodeUris": "http://localhost:9200" |
||||
|
}, |
||||
|
"Serilog": { |
||||
|
"MinimumLevel": { |
||||
|
"Default": "Debug", |
||||
|
"Override": { |
||||
|
"System": "Warning", |
||||
|
"Microsoft": "Warning", |
||||
|
"DotNetCore": "Debug" |
||||
|
} |
||||
|
}, |
||||
|
"WriteTo": [ |
||||
|
{ |
||||
|
"Name": "Console", |
||||
|
"Args": { |
||||
|
"restrictedToMinimumLevel": "Debug", |
||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
"Name": "Elasticsearch", |
||||
|
"Args": { |
||||
|
"nodeUris": "http://localhost:9200", |
||||
|
"indexFormat": "lingyun.abp.logging-{0:yyyy.MM.dd}", |
||||
|
"autoRegisterTemplate": true, |
||||
|
"autoRegisterTemplateVersion": "ESv7" |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
} |
||||
@ -1,91 +1,72 @@ |
|||||
{ |
{ |
||||
"ConnectionStrings": { |
"StringEncryption": { |
||||
"Default": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
"DefaultPassPhrase": "s46c5q55nxpeS8Ra", |
||||
"AbpLocalizationManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
"InitVectorBytes": "s83ng0abvd02js84", |
||||
"AbpTenantManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
"DefaultSalt": "sf&5)s3#" |
||||
"AbpSettingManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
}, |
||||
"AbpPermissionManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456" |
"Serilog": { |
||||
}, |
"MinimumLevel": { |
||||
"CAP": { |
"Default": "Debug", |
||||
"EventBus": { |
"Override": { |
||||
"DefaultGroupName": "Platform", |
"System": "Warning", |
||||
"Version": "v1", |
"Microsoft": "Warning", |
||||
"FailedRetryInterval": 300, |
"DotNetCore": "Debug" |
||||
"FailedRetryCount": 10 |
} |
||||
}, |
}, |
||||
"RabbitMQ": { |
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId", "WithEnvironmentName", "WithMachineName" ], |
||||
"HostName": "Your RabbitMQ server connection address", |
"WriteTo": [ |
||||
"Port": 5672, |
{ |
||||
"UserName": "Your RabbitMQ server connection user", |
"Name": "Console", |
||||
"Password": "Your RabbitMQ server connection user password", |
"Args": { |
||||
"ExchangeName": "The name of your RabbitMQ server switch", |
"restrictedToMinimumLevel": "Debug", |
||||
"VirtualHost": "Name of your RabbitMQ server VirtualHost" |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
} |
} |
||||
}, |
}, |
||||
"Redis": { |
{ |
||||
"Configuration": "127.0.0.1,defaultDatabase=11", |
"Name": "File", |
||||
"InstanceName": "LINGYUN.Abp.Application" |
"Args": { |
||||
}, |
"path": "Logs/Debug-.log", |
||||
"AuthServer": { |
"restrictedToMinimumLevel": "Debug", |
||||
"Authority": "http://localhost:44385/", |
"rollingInterval": "Day", |
||||
"ApiName": "lingyun-abp-application" |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
}, |
} |
||||
"Serilog": { |
}, |
||||
"MinimumLevel": { |
{ |
||||
"Default": "Debug", |
"Name": "File", |
||||
"Override": { |
"Args": { |
||||
"Microsoft.EntityFrameworkCore": "Debug", |
"path": "Logs/Info-.log", |
||||
"System": "Warning", |
"restrictedToMinimumLevel": "Information", |
||||
"Microsoft": "Warning" |
"rollingInterval": "Day", |
||||
} |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
}, |
} |
||||
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId" ], |
}, |
||||
"WriteTo": [ |
{ |
||||
{ |
"Name": "File", |
||||
"Name": "File", |
"Args": { |
||||
"Args": { |
"path": "Logs/Warn-.log", |
||||
"path": "Logs/Debug-.log", |
"restrictedToMinimumLevel": "Warning", |
||||
"restrictedToMinimumLevel": "Debug", |
"rollingInterval": "Day", |
||||
"rollingInterval": "Day", |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
} |
||||
} |
}, |
||||
}, |
{ |
||||
{ |
"Name": "File", |
||||
"Name": "File", |
"Args": { |
||||
"Args": { |
"path": "Logs/Error-.log", |
||||
"path": "Logs/Info-.log", |
"restrictedToMinimumLevel": "Error", |
||||
"restrictedToMinimumLevel": "Information", |
"rollingInterval": "Day", |
||||
"rollingInterval": "Day", |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
} |
||||
} |
}, |
||||
}, |
{ |
||||
{ |
"Name": "File", |
||||
"Name": "File", |
"Args": { |
||||
"Args": { |
"path": "Logs/Fatal-.log", |
||||
"path": "Logs/Warn-.log", |
"restrictedToMinimumLevel": "Fatal", |
||||
"restrictedToMinimumLevel": "Warning", |
"rollingInterval": "Day", |
||||
"rollingInterval": "Day", |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
} |
||||
} |
} |
||||
}, |
] |
||||
{ |
} |
||||
"Name": "File", |
} |
||||
"Args": { |
|
||||
"path": "Logs/Error-.log", |
|
||||
"restrictedToMinimumLevel": "Error", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Fatal-.log", |
|
||||
"restrictedToMinimumLevel": "Fatal", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
} |
|
||||
] |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,247 @@ |
|||||
|
using DotNetCore.CAP; |
||||
|
using LINGYUN.Abp.ExceptionHandling; |
||||
|
using LINGYUN.Abp.ExceptionHandling.Emailing; |
||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer; |
||||
|
using Microsoft.AspNetCore.DataProtection; |
||||
|
using Microsoft.AspNetCore.Identity; |
||||
|
using Microsoft.Extensions.Caching.StackExchangeRedis; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.OpenApi.Models; |
||||
|
using StackExchange.Redis; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text.Encodings.Web; |
||||
|
using System.Text.Unicode; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Volo.Abp.Authorization.Permissions; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.Domain.Entities.Events.Distributed; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Abp.Identity.Localization; |
||||
|
using Volo.Abp.Json.SystemTextJson; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.PermissionManagement; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
|
||||
|
namespace LINGYUN.Abp.IdentityServer4 |
||||
|
{ |
||||
|
public partial class AbpIdentityServerAdminHttpApiHostModule |
||||
|
{ |
||||
|
private void PreConfigureCAP(IConfiguration configuration) |
||||
|
{ |
||||
|
PreConfigure<CapOptions>(options => |
||||
|
{ |
||||
|
options |
||||
|
.UseMySql(configuration.GetConnectionString("Default")) |
||||
|
.UseRabbitMQ(rabbitMQOptions => |
||||
|
{ |
||||
|
configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); |
||||
|
}) |
||||
|
.UseDashboard(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void PreConfigureIdentity() |
||||
|
{ |
||||
|
PreConfigure<IdentityBuilder>(builder => |
||||
|
{ |
||||
|
builder.AddDefaultTokenProviders(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureDbContext() |
||||
|
{ |
||||
|
// 配置Ef
|
||||
|
Configure<AbpDbContextOptions>(options => |
||||
|
{ |
||||
|
options.UseMySQL(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureJsonSerializer() |
||||
|
{ |
||||
|
// 中文序列化的编码问题
|
||||
|
Configure<AbpSystemTextJsonSerializerOptions>(options => |
||||
|
{ |
||||
|
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigurePermissionManagement() |
||||
|
{ |
||||
|
Configure<PermissionManagementOptions>(options => |
||||
|
{ |
||||
|
// Rename IdentityServer.Client.ManagePermissions
|
||||
|
// See https://github.com/abpframework/abp/blob/dev/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs
|
||||
|
options.ProviderPolicies[ClientPermissionValueProvider.ProviderName] = |
||||
|
LINGYUN.Abp.IdentityServer.AbpIdentityServerPermissions.Clients.ManagePermissions; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigreExceptionHandling() |
||||
|
{ |
||||
|
// 自定义需要处理的异常
|
||||
|
Configure<AbpExceptionHandlingOptions>(options => |
||||
|
{ |
||||
|
// 加入需要处理的异常类型
|
||||
|
options.Handlers.Add<Volo.Abp.Data.AbpDbConcurrencyException>(); |
||||
|
options.Handlers.Add<AbpInitializationException>(); |
||||
|
options.Handlers.Add<ObjectDisposedException>(); |
||||
|
options.Handlers.Add<StackOverflowException>(); |
||||
|
options.Handlers.Add<OutOfMemoryException>(); |
||||
|
options.Handlers.Add<System.Data.Common.DbException>(); |
||||
|
options.Handlers.Add<Microsoft.EntityFrameworkCore.DbUpdateException>(); |
||||
|
options.Handlers.Add<System.Data.DBConcurrencyException>(); |
||||
|
}); |
||||
|
// 自定义需要发送邮件通知的异常类型
|
||||
|
Configure<AbpEmailExceptionHandlingOptions>(options => |
||||
|
{ |
||||
|
// 是否发送堆栈信息
|
||||
|
options.SendStackTrace = true; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureAuditing(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpAuditingOptions>(options => |
||||
|
{ |
||||
|
options.ApplicationName = "Identity-Server-Admin"; |
||||
|
// 是否启用实体变更记录
|
||||
|
var entitiesChangedConfig = configuration.GetSection("App:TrackingEntitiesChanged"); |
||||
|
if (entitiesChangedConfig.Exists() && entitiesChangedConfig.Get<bool>()) |
||||
|
{ |
||||
|
options |
||||
|
.EntityHistorySelectors |
||||
|
.AddAllEntities(); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureCaching(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpDistributedCacheOptions>(options => |
||||
|
{ |
||||
|
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
|
||||
|
options.KeyPrefix = "LINGYUN.Abp.Application"; |
||||
|
// 滑动过期30天
|
||||
|
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); |
||||
|
// 绝对过期60天
|
||||
|
options.GlobalCacheEntryOptions.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(60); |
||||
|
}); |
||||
|
|
||||
|
Configure<AbpDistributedEntityEventOptions>(options => |
||||
|
{ |
||||
|
options.AutoEventSelectors.AddNamespace("Volo.Abp.Identity"); |
||||
|
options.AutoEventSelectors.AddNamespace("Volo.Abp.IdentityServer"); |
||||
|
}); |
||||
|
|
||||
|
Configure<RedisCacheOptions>(options => |
||||
|
{ |
||||
|
var redisConfig = ConfigurationOptions.Parse(options.Configuration); |
||||
|
options.ConfigurationOptions = redisConfig; |
||||
|
options.InstanceName = configuration["Redis:InstanceName"]; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureVirtualFileSystem() |
||||
|
{ |
||||
|
Configure<AbpVirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<AbpIdentityServerAdminHttpApiHostModule>("LINGYUN.Abp.IdentityServer4"); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureMultiTenancy(IConfiguration configuration) |
||||
|
{ |
||||
|
// 多租户
|
||||
|
Configure<AbpMultiTenancyOptions>(options => |
||||
|
{ |
||||
|
options.IsEnabled = true; |
||||
|
}); |
||||
|
|
||||
|
var tenantResolveCfg = configuration.GetSection("App:Domains"); |
||||
|
if (tenantResolveCfg.Exists()) |
||||
|
{ |
||||
|
Configure<AbpTenantResolveOptions>(options => |
||||
|
{ |
||||
|
var domains = tenantResolveCfg.Get<string[]>(); |
||||
|
foreach (var domain in domains) |
||||
|
{ |
||||
|
options.AddDomainTenantResolver(domain); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSwagger(IServiceCollection services) |
||||
|
{ |
||||
|
// Swagger
|
||||
|
services.AddSwaggerGen( |
||||
|
options => |
||||
|
{ |
||||
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "IdentityServer4 API", Version = "v1" }); |
||||
|
options.DocInclusionPredicate((docName, description) => true); |
||||
|
options.CustomSchemaIds(type => type.FullName); |
||||
|
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme |
||||
|
{ |
||||
|
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", |
||||
|
Name = "Authorization", |
||||
|
In = ParameterLocation.Header, |
||||
|
Scheme = "bearer", |
||||
|
Type = SecuritySchemeType.Http, |
||||
|
BearerFormat = "JWT" |
||||
|
}); |
||||
|
options.AddSecurityRequirement(new OpenApiSecurityRequirement |
||||
|
{ |
||||
|
{ |
||||
|
new OpenApiSecurityScheme |
||||
|
{ |
||||
|
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } |
||||
|
}, |
||||
|
new string[] { } |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureLocalization() |
||||
|
{ |
||||
|
// 支持本地化语言类型
|
||||
|
Configure<AbpLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
||||
|
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
||||
|
|
||||
|
options.Resources |
||||
|
.Get<IdentityResource>() |
||||
|
.AddVirtualJson("/LINGYUN/Abp/IdentityServer4/Localization"); |
||||
|
|
||||
|
options.Resources.AddDynamic(typeof(IdentityResource)); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSecurity(IServiceCollection services, IConfiguration configuration, bool isDevelopment = false) |
||||
|
{ |
||||
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) |
||||
|
.AddJwtBearer(options => |
||||
|
{ |
||||
|
options.Authority = configuration["AuthServer:Authority"]; |
||||
|
options.RequireHttpsMetadata = false; |
||||
|
options.Audience = configuration["AuthServer:ApiName"]; |
||||
|
}); |
||||
|
|
||||
|
if (!isDevelopment) |
||||
|
{ |
||||
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
||||
|
services |
||||
|
.AddDataProtection() |
||||
|
.PersistKeysToStackExchangeRedis(redis, "IDS-Admin-Protection-Keys"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace LINGYUN.Abp.IdentityServer4 |
||||
|
{ |
||||
|
public partial class AbpIdentityServerAdminHttpApiHostModule |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -1,311 +1,112 @@ |
|||||
using DotNetCore.CAP; |
using LINGYUN.Abp.AspNetCore.HttpOverrides; |
||||
using LINGYUN.Abp.AspNetCore.HttpOverrides; |
using LINGYUN.Abp.AuditLogging.Elasticsearch; |
||||
using LINGYUN.Abp.EventBus.CAP; |
using LINGYUN.Abp.EventBus.CAP; |
||||
using LINGYUN.Abp.ExceptionHandling; |
using LINGYUN.Abp.ExceptionHandling.Emailing; |
||||
using LINGYUN.Abp.ExceptionHandling.Emailing; |
using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore; |
||||
using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore; |
using LINGYUN.Abp.MultiTenancy.DbFinder; |
||||
using LINGYUN.Abp.MultiTenancy.DbFinder; |
using LINGYUN.Abp.Sms.Aliyun; |
||||
using LINGYUN.Abp.Sms.Aliyun; |
using Microsoft.AspNetCore.Builder; |
||||
using Microsoft.AspNetCore.Authentication.JwtBearer; |
using Microsoft.AspNetCore.Hosting; |
||||
using Microsoft.AspNetCore.Builder; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Microsoft.AspNetCore.DataProtection; |
using Microsoft.Extensions.Hosting; |
||||
using Microsoft.AspNetCore.Hosting; |
using Volo.Abp; |
||||
using Microsoft.AspNetCore.Identity; |
using Volo.Abp.AspNetCore.Authentication.JwtBearer; |
||||
using Microsoft.Extensions.Caching.StackExchangeRedis; |
using Volo.Abp.AspNetCore.MultiTenancy; |
||||
using Microsoft.Extensions.Configuration; |
using Volo.Abp.AspNetCore.Serilog; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Volo.Abp.Autofac; |
||||
using Microsoft.Extensions.Hosting; |
using Volo.Abp.Caching.StackExchangeRedis; |
||||
using Microsoft.OpenApi.Models; |
using Volo.Abp.EntityFrameworkCore.MySQL; |
||||
using StackExchange.Redis; |
using Volo.Abp.Modularity; |
||||
using System; |
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
||||
using System.Text; |
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
||||
using System.Text.Encodings.Web; |
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
||||
using System.Text.Unicode; |
|
||||
using Volo.Abp; |
namespace LINGYUN.Abp.IdentityServer4 |
||||
using Volo.Abp.AspNetCore.Authentication.JwtBearer; |
{ |
||||
using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; |
[DependsOn( |
||||
using Volo.Abp.AspNetCore.Security.Claims; |
typeof(AbpAspNetCoreSerilogModule), |
||||
using Volo.Abp.Auditing; |
typeof(AbpAuditLoggingElasticsearchModule), |
||||
using Volo.Abp.AuditLogging.EntityFrameworkCore; |
typeof(AbpAspNetCoreMultiTenancyModule), |
||||
using Volo.Abp.Authorization.Permissions; |
typeof(LINGYUN.Abp.Account.AbpAccountApplicationModule), |
||||
using Volo.Abp.Autofac; |
typeof(LINGYUN.Abp.Account.AbpAccountHttpApiModule), |
||||
using Volo.Abp.Caching; |
typeof(LINGYUN.Abp.Identity.AbpIdentityApplicationModule), |
||||
using Volo.Abp.Caching.StackExchangeRedis; |
typeof(LINGYUN.Abp.Identity.AbpIdentityHttpApiModule), |
||||
using Volo.Abp.Domain.Entities.Events.Distributed; |
typeof(LINGYUN.Abp.IdentityServer.AbpIdentityServerApplicationModule), |
||||
using Volo.Abp.EntityFrameworkCore; |
typeof(LINGYUN.Abp.IdentityServer.AbpIdentityServerHttpApiModule), |
||||
using Volo.Abp.EntityFrameworkCore.MySQL; |
typeof(LINGYUN.Abp.Identity.EntityFrameworkCore.AbpIdentityEntityFrameworkCoreModule), |
||||
using Volo.Abp.Identity.Localization; |
typeof(LINGYUN.Abp.IdentityServer.EntityFrameworkCore.AbpIdentityServerEntityFrameworkCoreModule), |
||||
using Volo.Abp.Json; |
typeof(AbpEntityFrameworkCoreMySQLModule), |
||||
using Volo.Abp.Json.SystemTextJson; |
typeof(AbpTenantManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.Localization; |
typeof(AbpSettingManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.Modularity; |
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.MultiTenancy; |
typeof(AbpLocalizationManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.PermissionManagement; |
typeof(AbpAspNetCoreAuthenticationJwtBearerModule), |
||||
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
typeof(AbpEmailingExceptionHandlingModule), |
||||
using Volo.Abp.Security.Claims; |
typeof(AbpCAPEventBusModule), |
||||
using Volo.Abp.Security.Encryption; |
typeof(AbpAliyunSmsModule), |
||||
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
typeof(AbpDbFinderMultiTenancyModule), |
||||
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
typeof(AbpCachingStackExchangeRedisModule), |
||||
using Volo.Abp.VirtualFileSystem; |
typeof(AbpAspNetCoreHttpOverridesModule), |
||||
|
typeof(AbpAutofacModule) |
||||
namespace LINGYUN.Abp.IdentityServer4 |
)] |
||||
{ |
public partial class AbpIdentityServerAdminHttpApiHostModule : AbpModule |
||||
[DependsOn( |
{ |
||||
typeof(AbpAspNetCoreMvcUiMultiTenancyModule), |
public override void PreConfigureServices(ServiceConfigurationContext context) |
||||
typeof(LINGYUN.Abp.Account.AbpAccountApplicationModule), |
{ |
||||
typeof(LINGYUN.Abp.Account.AbpAccountHttpApiModule), |
var configuration = context.Services.GetConfiguration(); |
||||
typeof(LINGYUN.Abp.Identity.AbpIdentityApplicationModule), |
|
||||
typeof(LINGYUN.Abp.Identity.AbpIdentityHttpApiModule), |
PreConfigureCAP(configuration); |
||||
typeof(LINGYUN.Abp.IdentityServer.AbpIdentityServerApplicationModule), |
PreConfigureIdentity(); |
||||
typeof(LINGYUN.Abp.IdentityServer.AbpIdentityServerHttpApiModule), |
} |
||||
typeof(LINGYUN.Abp.Identity.EntityFrameworkCore.AbpIdentityEntityFrameworkCoreModule), |
|
||||
typeof(LINGYUN.Abp.IdentityServer.EntityFrameworkCore.AbpIdentityServerEntityFrameworkCoreModule), |
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
typeof(AbpEntityFrameworkCoreMySQLModule), |
{ |
||||
typeof(AbpAuditLoggingEntityFrameworkCoreModule), |
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
||||
typeof(AbpTenantManagementEntityFrameworkCoreModule), |
var configuration = hostingEnvironment.BuildConfiguration(); |
||||
typeof(AbpSettingManagementEntityFrameworkCoreModule), |
|
||||
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
ConfigureDbContext(); |
||||
typeof(AbpLocalizationManagementEntityFrameworkCoreModule), |
ConfigureJsonSerializer(); |
||||
typeof(AbpAspNetCoreAuthenticationJwtBearerModule), |
ConfigurePermissionManagement(); |
||||
typeof(AbpEmailingExceptionHandlingModule), |
ConfigreExceptionHandling(); |
||||
typeof(AbpCAPEventBusModule), |
ConfigureAuditing(configuration); |
||||
typeof(AbpAliyunSmsModule), |
ConfigureCaching(configuration); |
||||
typeof(AbpDbFinderMultiTenancyModule), |
ConfigureVirtualFileSystem(); |
||||
typeof(AbpCachingStackExchangeRedisModule), |
ConfigureMultiTenancy(configuration); |
||||
typeof(AbpAspNetCoreHttpOverridesModule), |
ConfigureSwagger(context.Services); |
||||
typeof(AbpAutofacModule) |
ConfigureLocalization(); |
||||
)] |
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); |
||||
public class AbpIdentityServerAdminHttpApiHostModule : AbpModule |
} |
||||
{ |
|
||||
public override void PreConfigureServices(ServiceConfigurationContext context) |
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
||||
{ |
{ |
||||
var configuration = context.Services.GetConfiguration(); |
var app = context.GetApplicationBuilder(); |
||||
|
// http调用链
|
||||
PreConfigure<CapOptions>(options => |
app.UseCorrelationId(); |
||||
{ |
// 虚拟文件系统
|
||||
options |
app.UseStaticFiles(); |
||||
.UseMySql(configuration.GetConnectionString("Default")) |
// 本地化
|
||||
.UseRabbitMQ(rabbitMQOptions => |
app.UseAbpRequestLocalization(); |
||||
{ |
//路由
|
||||
configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); |
app.UseRouting(); |
||||
}) |
// 认证
|
||||
.UseDashboard(); |
app.UseAuthentication(); |
||||
}); |
app.UseAbpClaimsMap(); |
||||
|
// jwt
|
||||
PreConfigure<IdentityBuilder>(builder => |
app.UseJwtTokenMiddleware(); |
||||
{ |
// 多租户
|
||||
builder.AddDefaultTokenProviders(); |
app.UseMultiTenancy(); |
||||
}); |
// Swagger
|
||||
} |
app.UseSwagger(); |
||||
|
// Swagger可视化界面
|
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
app.UseSwaggerUI(options => |
||||
{ |
{ |
||||
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support IdentityServer4 API"); |
||||
var configuration = hostingEnvironment.BuildConfiguration(); |
}); |
||||
|
// 审计日志
|
||||
// 配置Ef
|
app.UseAuditing(); |
||||
Configure<AbpDbContextOptions>(options => |
app.UseAbpSerilogEnrichers(); |
||||
{ |
// 路由
|
||||
options.UseMySQL(); |
app.UseConfiguredEndpoints(); |
||||
}); |
} |
||||
|
} |
||||
// 中文序列化的编码问题
|
|
||||
Configure<AbpSystemTextJsonSerializerOptions>(options => |
|
||||
{ |
|
||||
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); |
|
||||
}); |
|
||||
|
|
||||
// 加解密
|
|
||||
Configure<AbpStringEncryptionOptions>(options => |
|
||||
{ |
|
||||
var encryptionConfiguration = configuration.GetSection("Encryption"); |
|
||||
if (encryptionConfiguration.Exists()) |
|
||||
{ |
|
||||
options.DefaultPassPhrase = encryptionConfiguration["PassPhrase"] ?? options.DefaultPassPhrase; |
|
||||
options.DefaultSalt = encryptionConfiguration.GetSection("Salt").Exists() |
|
||||
? Encoding.ASCII.GetBytes(encryptionConfiguration["Salt"]) |
|
||||
: options.DefaultSalt; |
|
||||
options.InitVectorBytes = encryptionConfiguration.GetSection("InitVector").Exists() |
|
||||
? Encoding.ASCII.GetBytes(encryptionConfiguration["InitVector"]) |
|
||||
: options.InitVectorBytes; |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
Configure<PermissionManagementOptions>(options => |
|
||||
{ |
|
||||
// Rename IdentityServer.Client.ManagePermissions
|
|
||||
// See https://github.com/abpframework/abp/blob/dev/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs
|
|
||||
options.ProviderPolicies[ClientPermissionValueProvider.ProviderName] = |
|
||||
LINGYUN.Abp.IdentityServer.AbpIdentityServerPermissions.Clients.ManagePermissions; |
|
||||
}); |
|
||||
|
|
||||
// 自定义需要处理的异常
|
|
||||
Configure<AbpExceptionHandlingOptions>(options => |
|
||||
{ |
|
||||
// 加入需要处理的异常类型
|
|
||||
options.Handlers.Add<Volo.Abp.Data.AbpDbConcurrencyException>(); |
|
||||
options.Handlers.Add<AbpInitializationException>(); |
|
||||
options.Handlers.Add<ObjectDisposedException>(); |
|
||||
options.Handlers.Add<StackOverflowException>(); |
|
||||
options.Handlers.Add<OutOfMemoryException>(); |
|
||||
options.Handlers.Add<System.Data.Common.DbException>(); |
|
||||
options.Handlers.Add<Microsoft.EntityFrameworkCore.DbUpdateException>(); |
|
||||
options.Handlers.Add<System.Data.DBConcurrencyException>(); |
|
||||
}); |
|
||||
// 自定义需要发送邮件通知的异常类型
|
|
||||
Configure<AbpEmailExceptionHandlingOptions>(options => |
|
||||
{ |
|
||||
// 是否发送堆栈信息
|
|
||||
options.SendStackTrace = true; |
|
||||
}); |
|
||||
|
|
||||
Configure<AbpAuditingOptions>(options => |
|
||||
{ |
|
||||
options.ApplicationName = "Identity-Server-Admin"; |
|
||||
// 是否启用实体变更记录
|
|
||||
var entitiesChangedConfig = configuration.GetSection("App:TrackingEntitiesChanged"); |
|
||||
if (entitiesChangedConfig.Exists() && entitiesChangedConfig.Get<bool>()) |
|
||||
{ |
|
||||
options |
|
||||
.EntityHistorySelectors |
|
||||
.AddAllEntities(); |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
Configure<AbpDistributedCacheOptions>(options => |
|
||||
{ |
|
||||
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
|
|
||||
options.KeyPrefix = "LINGYUN.Abp.Application"; |
|
||||
// 滑动过期30天
|
|
||||
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); |
|
||||
// 绝对过期60天
|
|
||||
options.GlobalCacheEntryOptions.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(60); |
|
||||
}); |
|
||||
|
|
||||
Configure<AbpDistributedEntityEventOptions>(options => |
|
||||
{ |
|
||||
options.AutoEventSelectors.AddNamespace("Volo.Abp.Identity"); |
|
||||
options.AutoEventSelectors.AddNamespace("Volo.Abp.IdentityServer"); |
|
||||
}); |
|
||||
|
|
||||
Configure<RedisCacheOptions>(options => |
|
||||
{ |
|
||||
var redisConfig = ConfigurationOptions.Parse(options.Configuration); |
|
||||
options.ConfigurationOptions = redisConfig; |
|
||||
options.InstanceName = configuration["Redis:InstanceName"]; |
|
||||
}); |
|
||||
|
|
||||
Configure<AbpVirtualFileSystemOptions>(options => |
|
||||
{ |
|
||||
options.FileSets.AddEmbedded<AbpIdentityServerAdminHttpApiHostModule>("LINGYUN.Abp.IdentityServer4"); |
|
||||
}); |
|
||||
|
|
||||
// 多租户
|
|
||||
Configure<AbpMultiTenancyOptions>(options => |
|
||||
{ |
|
||||
options.IsEnabled = true; |
|
||||
}); |
|
||||
|
|
||||
var tenantResolveCfg = configuration.GetSection("App:Domains"); |
|
||||
if (tenantResolveCfg.Exists()) |
|
||||
{ |
|
||||
Configure<AbpTenantResolveOptions>(options => |
|
||||
{ |
|
||||
var domains = tenantResolveCfg.Get<string[]>(); |
|
||||
foreach (var domain in domains) |
|
||||
{ |
|
||||
options.AddDomainTenantResolver(domain); |
|
||||
} |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
// Swagger
|
|
||||
context.Services.AddSwaggerGen( |
|
||||
options => |
|
||||
{ |
|
||||
options.SwaggerDoc("v1", new OpenApiInfo { Title = "IdentityServer4 API", Version = "v1" }); |
|
||||
options.DocInclusionPredicate((docName, description) => true); |
|
||||
options.CustomSchemaIds(type => type.FullName); |
|
||||
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme |
|
||||
{ |
|
||||
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", |
|
||||
Name = "Authorization", |
|
||||
In = ParameterLocation.Header, |
|
||||
Scheme = "bearer", |
|
||||
Type = SecuritySchemeType.Http, |
|
||||
BearerFormat = "JWT" |
|
||||
}); |
|
||||
options.AddSecurityRequirement(new OpenApiSecurityRequirement |
|
||||
{ |
|
||||
{ |
|
||||
new OpenApiSecurityScheme |
|
||||
{ |
|
||||
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } |
|
||||
}, |
|
||||
new string[] { } |
|
||||
} |
|
||||
}); |
|
||||
}); |
|
||||
|
|
||||
// 支持本地化语言类型
|
|
||||
Configure<AbpLocalizationOptions>(options => |
|
||||
{ |
|
||||
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
|
||||
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
|
||||
|
|
||||
options.Resources |
|
||||
.Get<IdentityResource>() |
|
||||
.AddVirtualJson("/LINGYUN/Abp/IdentityServer4/Localization"); |
|
||||
|
|
||||
options.Resources.AddDynamic(typeof(IdentityResource)); |
|
||||
}); |
|
||||
|
|
||||
context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) |
|
||||
.AddJwtBearer(options => |
|
||||
{ |
|
||||
options.Authority = configuration["AuthServer:Authority"]; |
|
||||
options.RequireHttpsMetadata = false; |
|
||||
options.Audience = configuration["AuthServer:ApiName"]; |
|
||||
}); |
|
||||
|
|
||||
if (!hostingEnvironment.IsDevelopment()) |
|
||||
{ |
|
||||
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
|
||||
context.Services |
|
||||
.AddDataProtection() |
|
||||
.PersistKeysToStackExchangeRedis(redis, "BackendAdmin-Protection-Keys"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|
||||
{ |
|
||||
var app = context.GetApplicationBuilder(); |
|
||||
// http调用链
|
|
||||
app.UseCorrelationId(); |
|
||||
// 虚拟文件系统
|
|
||||
app.UseStaticFiles(); |
|
||||
// 本地化
|
|
||||
app.UseAbpRequestLocalization(); |
|
||||
//路由
|
|
||||
app.UseRouting(); |
|
||||
// 认证
|
|
||||
app.UseAuthentication(); |
|
||||
app.UseAbpClaimsMap(); |
|
||||
// jwt
|
|
||||
app.UseJwtTokenMiddleware(); |
|
||||
// 多租户
|
|
||||
app.UseMultiTenancy(); |
|
||||
// Swagger
|
|
||||
app.UseSwagger(); |
|
||||
// Swagger可视化界面
|
|
||||
app.UseSwaggerUI(options => |
|
||||
{ |
|
||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support IdentityServer4 API"); |
|
||||
}); |
|
||||
// 审计日志
|
|
||||
app.UseAuditing(); |
|
||||
// 路由
|
|
||||
app.UseConfiguredEndpoints(); |
|
||||
} |
|
||||
} |
|
||||
} |
} |
||||
@ -0,0 +1,74 @@ |
|||||
|
{ |
||||
|
"App": { |
||||
|
"TrackingEntitiesChanged": true |
||||
|
}, |
||||
|
"ConnectionStrings": { |
||||
|
"Default": "Server=localhost;Database=IdentityServer;User Id=root;Password=123456", |
||||
|
"AbpIdentity": "Server=localhost;Database=IdentityServer;User Id=root;Password=123456", |
||||
|
"AbpIdentityServer": "Server=localhost;Database=IdentityServer;User Id=root;Password=123456", |
||||
|
"AbpTenantManagement": "Server=localhost;Database=Platform;User Id=root;Password=123456", |
||||
|
"AbpSettingManagement": "Server=localhost;Database=Platform;User Id=root;Password=123456", |
||||
|
"AbpFeatureManagement": "Server=localhost;Database=Platform;User Id=root;Password=123456", |
||||
|
"AbpPermissionManagement": "Server=localhost;Database=Platform;User Id=root;Password=123456", |
||||
|
"AbpLocalizationManagement": "Server=localhost;Database=Platform;User Id=root;Password=123456" |
||||
|
}, |
||||
|
"CAP": { |
||||
|
"EventBus": { |
||||
|
"DefaultGroupName": "IdentityServer4Admin", |
||||
|
"Version": "v1", |
||||
|
"FailedRetryInterval": 300, |
||||
|
"FailedRetryCount": 10 |
||||
|
}, |
||||
|
"MySql": { |
||||
|
"TableNamePrefix": "ida", |
||||
|
"ConnectionString": "Server=localhost;Database=IdentityServer;User Id=root;Password=123456" |
||||
|
}, |
||||
|
"RabbitMQ": { |
||||
|
"HostName": "localhost", |
||||
|
"Port": 5672, |
||||
|
"UserName": "guest", |
||||
|
"Password": "guest", |
||||
|
"ExchangeName": "LINGYUN.Abp.Application", |
||||
|
"VirtualHost": "/" |
||||
|
} |
||||
|
}, |
||||
|
"Redis": { |
||||
|
"Configuration": "localhost,defaultDatabase=10", |
||||
|
"InstanceName": "LINGYUN.Abp.Application" |
||||
|
}, |
||||
|
"AuthServer": { |
||||
|
"Authority": "http://localhost:44385/", |
||||
|
"ApiName": "lingyun-abp-application" |
||||
|
}, |
||||
|
"Elasticsearch": { |
||||
|
"NodeUris": "http://localhost:9200" |
||||
|
}, |
||||
|
"Serilog": { |
||||
|
"MinimumLevel": { |
||||
|
"Default": "Debug", |
||||
|
"Override": { |
||||
|
"System": "Warning", |
||||
|
"Microsoft": "Warning", |
||||
|
"DotNetCore": "Debug" |
||||
|
} |
||||
|
}, |
||||
|
"WriteTo": [ |
||||
|
{ |
||||
|
"Name": "Console", |
||||
|
"Args": { |
||||
|
"restrictedToMinimumLevel": "Debug", |
||||
|
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
"Name": "Elasticsearch", |
||||
|
"Args": { |
||||
|
"nodeUris": "http://localhost:9200", |
||||
|
"indexFormat": "lingyun.abp.logging-{0:yyyy.MM.dd}", |
||||
|
"autoRegisterTemplate": true, |
||||
|
"autoRegisterTemplateVersion": "ESv7" |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
} |
||||
@ -1,97 +1,72 @@ |
|||||
{ |
{ |
||||
"App": { |
"StringEncryption": { |
||||
"TrackingEntitiesChanged": true |
"DefaultPassPhrase": "s46c5q55nxpeS8Ra", |
||||
}, |
"InitVectorBytes": "s83ng0abvd02js84", |
||||
"ConnectionStrings": { |
"DefaultSalt": "sf&5)s3#" |
||||
"Default": "Server=127.0.0.1;Database=IdentityServer;User Id=root;Password=123456", |
}, |
||||
"AbpIdentity": "Server=127.0.0.1;Database=IdentityServer;User Id=root;Password=123456", |
"Serilog": { |
||||
"AbpIdentityServer": "Server=127.0.0.1;Database=IdentityServer;User Id=root;Password=123456", |
"MinimumLevel": { |
||||
"AbpTenantManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
"Default": "Debug", |
||||
"AbpSettingManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
"Override": { |
||||
"AbpFeatureManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
"System": "Warning", |
||||
"AbpPermissionManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", |
"Microsoft": "Warning", |
||||
"AbpLocalizationManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456" |
"DotNetCore": "Debug" |
||||
}, |
} |
||||
"CAP": { |
}, |
||||
"EventBus": { |
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId", "WithEnvironmentName", "WithMachineName" ], |
||||
"DefaultGroupName": "IdentityServer4Admin", |
"WriteTo": [ |
||||
"Version": "v1", |
{ |
||||
"FailedRetryInterval": 300, |
"Name": "Console", |
||||
"FailedRetryCount": 10 |
"Args": { |
||||
}, |
"restrictedToMinimumLevel": "Debug", |
||||
"RabbitMQ": { |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"HostName": "127.0.0.1", |
} |
||||
"Port": 5672, |
}, |
||||
"UserName": "admin", |
{ |
||||
"Password": "123456", |
"Name": "File", |
||||
"ExchangeName": "LINGYUN.AbpApplication", |
"Args": { |
||||
"VirtualHost": "multi.service.test" |
"path": "Logs/Debug-.log", |
||||
} |
"restrictedToMinimumLevel": "Debug", |
||||
}, |
"rollingInterval": "Day", |
||||
"Redis": { |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"Configuration": "127.0.0.1,defaultDatabase=10", |
} |
||||
"InstanceName": "LINGYUN.AbpApplication" |
}, |
||||
}, |
{ |
||||
"AuthServer": { |
"Name": "File", |
||||
"Authority": "http://localhost:44385/", |
"Args": { |
||||
"ApiName": "lingyun-abp-application" |
"path": "Logs/Info-.log", |
||||
}, |
"restrictedToMinimumLevel": "Information", |
||||
"Serilog": { |
"rollingInterval": "Day", |
||||
"MinimumLevel": { |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
"Default": "Debug", |
} |
||||
"Override": { |
}, |
||||
"Microsoft.EntityFrameworkCore": "Debug", |
{ |
||||
"System": "Warning", |
"Name": "File", |
||||
"Microsoft": "Warning" |
"Args": { |
||||
} |
"path": "Logs/Warn-.log", |
||||
}, |
"restrictedToMinimumLevel": "Warning", |
||||
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId" ], |
"rollingInterval": "Day", |
||||
"WriteTo": [ |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
{ |
} |
||||
"Name": "File", |
}, |
||||
"Args": { |
{ |
||||
"path": "Logs/Debug-.log", |
"Name": "File", |
||||
"restrictedToMinimumLevel": "Debug", |
"Args": { |
||||
"rollingInterval": "Day", |
"path": "Logs/Error-.log", |
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
"restrictedToMinimumLevel": "Error", |
||||
} |
"rollingInterval": "Day", |
||||
}, |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
{ |
} |
||||
"Name": "File", |
}, |
||||
"Args": { |
{ |
||||
"path": "Logs/Info-.log", |
"Name": "File", |
||||
"restrictedToMinimumLevel": "Information", |
"Args": { |
||||
"rollingInterval": "Day", |
"path": "Logs/Fatal-.log", |
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
"restrictedToMinimumLevel": "Fatal", |
||||
} |
"rollingInterval": "Day", |
||||
}, |
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
||||
{ |
} |
||||
"Name": "File", |
} |
||||
"Args": { |
] |
||||
"path": "Logs/Warn-.log", |
} |
||||
"restrictedToMinimumLevel": "Warning", |
} |
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Error-.log", |
|
||||
"restrictedToMinimumLevel": "Error", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
}, |
|
||||
{ |
|
||||
"Name": "File", |
|
||||
"Args": { |
|
||||
"path": "Logs/Fatal-.log", |
|
||||
"restrictedToMinimumLevel": "Fatal", |
|
||||
"rollingInterval": "Day", |
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|
||||
} |
|
||||
} |
|
||||
] |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,198 @@ |
|||||
|
using DotNetCore.CAP; |
||||
|
using LINGYUN.Abp.ExceptionHandling; |
||||
|
using LINGYUN.Abp.ExceptionHandling.Emailing; |
||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer; |
||||
|
using Microsoft.AspNetCore.DataProtection; |
||||
|
using Microsoft.Extensions.Caching.StackExchangeRedis; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.OpenApi.Models; |
||||
|
using StackExchange.Redis; |
||||
|
using System; |
||||
|
using System.Text.Encodings.Web; |
||||
|
using System.Text.Unicode; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Abp.Json.SystemTextJson; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
|
||||
|
|
||||
|
namespace LINGYUN.Abp.LocalizationManagement |
||||
|
{ |
||||
|
public partial class AbpLocalizationManagementHttpApiHostModule |
||||
|
{ |
||||
|
private void PreConfigureCAP(IConfiguration configuration) |
||||
|
{ |
||||
|
PreConfigure<CapOptions>(options => |
||||
|
{ |
||||
|
options |
||||
|
.UseMySql(configuration.GetConnectionString("Default")) |
||||
|
.UseRabbitMQ(rabbitMQOptions => |
||||
|
{ |
||||
|
configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); |
||||
|
}) |
||||
|
.UseDashboard(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureDbContext() |
||||
|
{ |
||||
|
// 配置Ef
|
||||
|
Configure<AbpDbContextOptions>(options => |
||||
|
{ |
||||
|
options.UseMySQL(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureJsonSerializer() |
||||
|
{ |
||||
|
// 中文序列化的编码问题
|
||||
|
Configure<AbpSystemTextJsonSerializerOptions>(options => |
||||
|
{ |
||||
|
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigreExceptionHandling() |
||||
|
{ |
||||
|
// 自定义需要处理的异常
|
||||
|
Configure<AbpExceptionHandlingOptions>(options => |
||||
|
{ |
||||
|
// 加入需要处理的异常类型
|
||||
|
options.Handlers.Add<Volo.Abp.Data.AbpDbConcurrencyException>(); |
||||
|
options.Handlers.Add<AbpInitializationException>(); |
||||
|
options.Handlers.Add<ObjectDisposedException>(); |
||||
|
options.Handlers.Add<StackOverflowException>(); |
||||
|
options.Handlers.Add<OutOfMemoryException>(); |
||||
|
options.Handlers.Add<System.Data.Common.DbException>(); |
||||
|
options.Handlers.Add<Microsoft.EntityFrameworkCore.DbUpdateException>(); |
||||
|
options.Handlers.Add<System.Data.DBConcurrencyException>(); |
||||
|
}); |
||||
|
// 自定义需要发送邮件通知的异常类型
|
||||
|
Configure<AbpEmailExceptionHandlingOptions>(options => |
||||
|
{ |
||||
|
// 是否发送堆栈信息
|
||||
|
options.SendStackTrace = true; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureAuditing(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpAuditingOptions>(options => |
||||
|
{ |
||||
|
options.ApplicationName = "Localization"; |
||||
|
// 是否启用实体变更记录
|
||||
|
var entitiesChangedConfig = configuration.GetSection("App:TrackingEntitiesChanged"); |
||||
|
if (entitiesChangedConfig.Exists() && entitiesChangedConfig.Get<bool>()) |
||||
|
{ |
||||
|
options |
||||
|
.EntityHistorySelectors |
||||
|
.AddAllEntities(); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureCaching(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpDistributedCacheOptions>(options => |
||||
|
{ |
||||
|
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
|
||||
|
options.KeyPrefix = "LINGYUN.Abp.Application"; |
||||
|
// 滑动过期30天
|
||||
|
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); |
||||
|
// 绝对过期60天
|
||||
|
options.GlobalCacheEntryOptions.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(60); |
||||
|
}); |
||||
|
|
||||
|
Configure<RedisCacheOptions>(options => |
||||
|
{ |
||||
|
var redisConfig = ConfigurationOptions.Parse(options.Configuration); |
||||
|
options.ConfigurationOptions = redisConfig; |
||||
|
options.InstanceName = configuration["Redis:InstanceName"]; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureVirtualFileSystem() |
||||
|
{ |
||||
|
Configure<AbpVirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<AbpLocalizationManagementHttpApiHostModule>("LINGYUN.Abp.LocalizationManagement"); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureMultiTenancy(IConfiguration configuration) |
||||
|
{ |
||||
|
// 多租户
|
||||
|
Configure<AbpMultiTenancyOptions>(options => |
||||
|
{ |
||||
|
options.IsEnabled = false; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSwagger(IServiceCollection services) |
||||
|
{ |
||||
|
// Swagger
|
||||
|
services.AddSwaggerGen( |
||||
|
options => |
||||
|
{ |
||||
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Localization Management API", Version = "v1" }); |
||||
|
options.DocInclusionPredicate((docName, description) => true); |
||||
|
options.CustomSchemaIds(type => type.FullName); |
||||
|
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme |
||||
|
{ |
||||
|
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", |
||||
|
Name = "Authorization", |
||||
|
In = ParameterLocation.Header, |
||||
|
Scheme = "bearer", |
||||
|
Type = SecuritySchemeType.Http, |
||||
|
BearerFormat = "JWT" |
||||
|
}); |
||||
|
options.AddSecurityRequirement(new OpenApiSecurityRequirement |
||||
|
{ |
||||
|
{ |
||||
|
new OpenApiSecurityScheme |
||||
|
{ |
||||
|
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } |
||||
|
}, |
||||
|
new string[] { } |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureLocalization() |
||||
|
{ |
||||
|
// 默认支持的本地化语言类型
|
||||
|
Configure<AbpLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
||||
|
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
||||
|
|
||||
|
options.Resources.AddDynamic(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSecurity(IServiceCollection services, IConfiguration configuration, bool isDevelopment = false) |
||||
|
{ |
||||
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) |
||||
|
.AddJwtBearer(options => |
||||
|
{ |
||||
|
options.Authority = configuration["AuthServer:Authority"]; |
||||
|
options.RequireHttpsMetadata = false; |
||||
|
options.Audience = configuration["AuthServer:ApiName"]; |
||||
|
}); |
||||
|
|
||||
|
if (!isDevelopment) |
||||
|
{ |
||||
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
||||
|
services |
||||
|
.AddDataProtection() |
||||
|
.PersistKeysToStackExchangeRedis(redis, "Localization-Protection-Keys"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.Threading; |
||||
|
|
||||
|
namespace LINGYUN.Abp.LocalizationManagement |
||||
|
{ |
||||
|
public partial class AbpLocalizationManagementHttpApiHostModule |
||||
|
{ |
||||
|
private void SeedData(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
if (context.GetEnvironment().IsDevelopment()) |
||||
|
{ |
||||
|
AsyncHelper.RunSync(async () => |
||||
|
await context.ServiceProvider.GetRequiredService<IDataSeeder>() |
||||
|
.SeedAsync()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,265 +1,104 @@ |
|||||
using DotNetCore.CAP; |
using LINGYUN.Abp.AspNetCore.HttpOverrides; |
||||
using LINGYUN.Abp.AspNetCore.HttpOverrides; |
using LINGYUN.Abp.AuditLogging.Elasticsearch; |
||||
using LINGYUN.Abp.EventBus.CAP; |
using LINGYUN.Abp.EventBus.CAP; |
||||
using LINGYUN.Abp.ExceptionHandling; |
using LINGYUN.Abp.ExceptionHandling.Emailing; |
||||
using LINGYUN.Abp.ExceptionHandling.Emailing; |
using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore; |
||||
using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore; |
using LINGYUN.Abp.MultiTenancy.DbFinder; |
||||
using LINGYUN.Abp.MultiTenancy.DbFinder; |
using Microsoft.AspNetCore.Builder; |
||||
using Localization.Resources.AbpUi; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Microsoft.AspNetCore.Authentication.JwtBearer; |
using Microsoft.Extensions.Hosting; |
||||
using Microsoft.AspNetCore.Builder; |
using Volo.Abp; |
||||
using Microsoft.AspNetCore.DataProtection; |
using Volo.Abp.AspNetCore.Authentication.JwtBearer; |
||||
using Microsoft.Extensions.Caching.StackExchangeRedis; |
using Volo.Abp.AspNetCore.MultiTenancy; |
||||
using Microsoft.Extensions.Configuration; |
using Volo.Abp.AspNetCore.Serilog; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Volo.Abp.Autofac; |
||||
using Microsoft.Extensions.Hosting; |
using Volo.Abp.Caching.StackExchangeRedis; |
||||
using Microsoft.OpenApi.Models; |
using Volo.Abp.EntityFrameworkCore.MySQL; |
||||
using StackExchange.Redis; |
using Volo.Abp.Modularity; |
||||
using System; |
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
||||
using System.Text; |
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
||||
using System.Text.Encodings.Web; |
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
||||
using System.Text.Unicode; |
|
||||
using Volo.Abp; |
namespace LINGYUN.Abp.LocalizationManagement |
||||
using Volo.Abp.AspNetCore.Authentication.JwtBearer; |
{ |
||||
using Volo.Abp.AspNetCore.MultiTenancy; |
[DependsOn( |
||||
using Volo.Abp.Autofac; |
typeof(AbpAspNetCoreSerilogModule), |
||||
using Volo.Abp.Caching; |
typeof(AbpAuditLoggingElasticsearchModule), |
||||
using Volo.Abp.Caching.StackExchangeRedis; |
typeof(AbpAspNetCoreMultiTenancyModule), |
||||
using Volo.Abp.Data; |
typeof(AbpLocalizationManagementApplicationModule), |
||||
using Volo.Abp.EntityFrameworkCore; |
typeof(AbpLocalizationManagementHttpApiModule), |
||||
using Volo.Abp.EntityFrameworkCore.MySQL; |
typeof(AbpLocalizationManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.Json; |
typeof(AbpEntityFrameworkCoreMySQLModule), |
||||
using Volo.Abp.Json.SystemTextJson; |
typeof(AbpTenantManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.Localization; |
typeof(AbpSettingManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.Modularity; |
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
||||
using Volo.Abp.MultiTenancy; |
typeof(AbpAspNetCoreAuthenticationJwtBearerModule), |
||||
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
typeof(AbpEmailingExceptionHandlingModule), |
||||
using Volo.Abp.Security.Encryption; |
typeof(AbpCAPEventBusModule), |
||||
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
typeof(AbpDbFinderMultiTenancyModule), |
||||
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
typeof(AbpCachingStackExchangeRedisModule), |
||||
using Volo.Abp.Threading; |
typeof(AbpAspNetCoreHttpOverridesModule), |
||||
using Volo.Abp.Validation.Localization; |
typeof(AbpAutofacModule) |
||||
|
)] |
||||
namespace LINGYUN.Abp.LocalizationManagement |
public partial class AbpLocalizationManagementHttpApiHostModule : AbpModule |
||||
{ |
{ |
||||
[DependsOn( |
public override void PreConfigureServices(ServiceConfigurationContext context) |
||||
typeof(AbpLocalizationManagementApplicationModule), |
{ |
||||
typeof(AbpLocalizationManagementHttpApiModule), |
var configuration = context.Services.GetConfiguration(); |
||||
typeof(AbpLocalizationManagementEntityFrameworkCoreModule), |
|
||||
typeof(AbpAspNetCoreMultiTenancyModule), |
PreConfigureCAP(configuration); |
||||
typeof(AbpEntityFrameworkCoreMySQLModule), |
} |
||||
typeof(AbpTenantManagementEntityFrameworkCoreModule), |
|
||||
typeof(AbpSettingManagementEntityFrameworkCoreModule), |
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
{ |
||||
typeof(AbpAspNetCoreAuthenticationJwtBearerModule), |
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
||||
typeof(AbpEmailingExceptionHandlingModule), |
var configuration = context.Services.GetConfiguration(); |
||||
typeof(AbpCAPEventBusModule), |
|
||||
typeof(AbpDbFinderMultiTenancyModule), |
ConfigureDbContext(); |
||||
typeof(AbpCachingStackExchangeRedisModule), |
ConfigureJsonSerializer(); |
||||
typeof(AbpAspNetCoreHttpOverridesModule), |
ConfigreExceptionHandling(); |
||||
typeof(AbpAutofacModule) |
ConfigureAuditing(configuration); |
||||
)] |
ConfigureCaching(configuration); |
||||
public class AbpLocalizationManagementHttpApiHostModule : AbpModule |
ConfigureVirtualFileSystem(); |
||||
{ |
ConfigureMultiTenancy(configuration); |
||||
public override void PreConfigureServices(ServiceConfigurationContext context) |
ConfigureLocalization(); |
||||
{ |
ConfigureSwagger(context.Services); |
||||
var configuration = context.Services.GetConfiguration(); |
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); |
||||
|
} |
||||
PreConfigure<CapOptions>(options => |
|
||||
{ |
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
||||
options |
{ |
||||
.UseMySql(configuration.GetConnectionString("Default")) |
var app = context.GetApplicationBuilder(); |
||||
.UseRabbitMQ(rabbitMQOptions => |
var env = context.GetEnvironment(); |
||||
{ |
|
||||
configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); |
// http调用链
|
||||
}) |
app.UseCorrelationId(); |
||||
.UseDashboard(); |
// 虚拟文件系统
|
||||
}); |
app.UseStaticFiles(); |
||||
} |
// 本地化
|
||||
|
app.UseAbpRequestLocalization(); |
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
//路由
|
||||
{ |
app.UseRouting(); |
||||
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
// 认证
|
||||
var configuration = context.Services.GetConfiguration(); |
app.UseAuthentication(); |
||||
|
// jwt
|
||||
// 配置Ef
|
app.UseJwtTokenMiddleware(); |
||||
Configure<AbpDbContextOptions>(options => |
// 授权
|
||||
{ |
app.UseAuthorization(); |
||||
options.UseMySQL(); |
// Swagger
|
||||
}); |
app.UseSwagger(); |
||||
|
// Swagger可视化界面
|
||||
// 中文序列化的编码问题
|
app.UseSwaggerUI(options => |
||||
Configure<AbpSystemTextJsonSerializerOptions>(options => |
{ |
||||
{ |
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support Localization Management API"); |
||||
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); |
}); |
||||
}); |
// 审计日志
|
||||
|
app.UseAuditing(); |
||||
// 加解密
|
app.UseAbpSerilogEnrichers(); |
||||
Configure<AbpStringEncryptionOptions>(options => |
// 路由
|
||||
{ |
app.UseConfiguredEndpoints(); |
||||
var encryptionConfiguration = configuration.GetSection("Encryption"); |
|
||||
if (encryptionConfiguration.Exists()) |
SeedData(context); |
||||
{ |
} |
||||
options.DefaultPassPhrase = encryptionConfiguration["PassPhrase"] ?? options.DefaultPassPhrase; |
} |
||||
options.DefaultSalt = encryptionConfiguration.GetSection("Salt").Exists() |
} |
||||
? Encoding.ASCII.GetBytes(encryptionConfiguration["Salt"]) |
|
||||
: options.DefaultSalt; |
|
||||
options.InitVectorBytes = encryptionConfiguration.GetSection("InitVector").Exists() |
|
||||
? Encoding.ASCII.GetBytes(encryptionConfiguration["InitVector"]) |
|
||||
: options.InitVectorBytes; |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
// 自定义需要处理的异常
|
|
||||
Configure<AbpExceptionHandlingOptions>(options => |
|
||||
{ |
|
||||
// 加入需要处理的异常类型
|
|
||||
options.Handlers.Add<Volo.Abp.Data.AbpDbConcurrencyException>(); |
|
||||
options.Handlers.Add<AbpInitializationException>(); |
|
||||
options.Handlers.Add<ObjectDisposedException>(); |
|
||||
options.Handlers.Add<StackOverflowException>(); |
|
||||
options.Handlers.Add<OutOfMemoryException>(); |
|
||||
options.Handlers.Add<System.Data.Common.DbException>(); |
|
||||
options.Handlers.Add<Microsoft.EntityFrameworkCore.DbUpdateException>(); |
|
||||
options.Handlers.Add<System.Data.DBConcurrencyException>(); |
|
||||
}); |
|
||||
// 自定义需要发送邮件通知的异常类型
|
|
||||
Configure<AbpEmailExceptionHandlingOptions>(options => |
|
||||
{ |
|
||||
// 是否发送堆栈信息
|
|
||||
options.SendStackTrace = true; |
|
||||
// 未指定异常接收者的默认接收邮件
|
|
||||
// 指定自己的邮件地址
|
|
||||
// options.DefaultReceiveEmail = "colin.in@foxmail.com";
|
|
||||
}); |
|
||||
|
|
||||
Configure<AbpDistributedCacheOptions>(options => |
|
||||
{ |
|
||||
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
|
|
||||
options.KeyPrefix = "LINGYUN.Abp.Application"; |
|
||||
// 滑动过期30天
|
|
||||
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); |
|
||||
// 绝对过期60天
|
|
||||
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); |
|
||||
}); |
|
||||
|
|
||||
Configure<RedisCacheOptions>(options => |
|
||||
{ |
|
||||
var redisConfig = ConfigurationOptions.Parse(options.Configuration); |
|
||||
options.ConfigurationOptions = redisConfig; |
|
||||
options.InstanceName = configuration["Redis:InstanceName"]; |
|
||||
}); |
|
||||
|
|
||||
// 可以禁用多租户
|
|
||||
Configure<AbpMultiTenancyOptions>(options => |
|
||||
{ |
|
||||
options.IsEnabled = false; |
|
||||
}); |
|
||||
|
|
||||
// 添加动态本地化组件
|
|
||||
Configure<AbpLocalizationOptions>(options => |
|
||||
{ |
|
||||
options.Resources.AddDynamic(); |
|
||||
}); |
|
||||
|
|
||||
// Swagger
|
|
||||
context.Services.AddSwaggerGen( |
|
||||
options => |
|
||||
{ |
|
||||
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Localization Management API", Version = "v1" }); |
|
||||
options.DocInclusionPredicate((docName, description) => true); |
|
||||
options.CustomSchemaIds(type => type.FullName); |
|
||||
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme |
|
||||
{ |
|
||||
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", |
|
||||
Name = "Authorization", |
|
||||
In = ParameterLocation.Header, |
|
||||
Scheme = "bearer", |
|
||||
Type = SecuritySchemeType.Http, |
|
||||
BearerFormat = "JWT" |
|
||||
}); |
|
||||
options.AddSecurityRequirement(new OpenApiSecurityRequirement |
|
||||
{ |
|
||||
{ |
|
||||
new OpenApiSecurityScheme |
|
||||
{ |
|
||||
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } |
|
||||
}, |
|
||||
new string[] { } |
|
||||
} |
|
||||
}); |
|
||||
}); |
|
||||
|
|
||||
// 默认支持的本地化语言类型
|
|
||||
Configure<AbpLocalizationOptions>(options => |
|
||||
{ |
|
||||
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
|
||||
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
|
||||
}); |
|
||||
|
|
||||
context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) |
|
||||
.AddJwtBearer(options => |
|
||||
{ |
|
||||
options.Authority = configuration["AuthServer:Authority"]; |
|
||||
options.RequireHttpsMetadata = false; |
|
||||
options.Audience = configuration["AuthServer:ApiName"]; |
|
||||
}); |
|
||||
|
|
||||
if (!hostingEnvironment.IsDevelopment()) |
|
||||
{ |
|
||||
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
|
||||
context.Services |
|
||||
.AddDataProtection() |
|
||||
.PersistKeysToStackExchangeRedis(redis, "Localization-Management-Protection-Keys"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
//public override void OnPostApplicationInitialization(ApplicationInitializationContext context)
|
|
||||
//{
|
|
||||
// // 注释代码取消启动时缓存本地化信息
|
|
||||
// var initialize = context.ServiceProvider.GetRequiredService<ILocalizationCacheInitialize>();
|
|
||||
// AsyncHelper.RunSync(async () => await initialize.InitializeAsync());
|
|
||||
//}
|
|
||||
|
|
||||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|
||||
{ |
|
||||
var app = context.GetApplicationBuilder(); |
|
||||
var env = context.GetEnvironment(); |
|
||||
|
|
||||
// http调用链
|
|
||||
app.UseCorrelationId(); |
|
||||
// 虚拟文件系统
|
|
||||
app.UseStaticFiles(); |
|
||||
// 本地化
|
|
||||
app.UseAbpRequestLocalization(); |
|
||||
// 多租户
|
|
||||
// app.UseMultiTenancy();
|
|
||||
//路由
|
|
||||
app.UseRouting(); |
|
||||
// 认证
|
|
||||
app.UseAuthentication(); |
|
||||
// jwt
|
|
||||
app.UseJwtTokenMiddleware(); |
|
||||
// 授权
|
|
||||
app.UseAuthorization(); |
|
||||
// Swagger
|
|
||||
app.UseSwagger(); |
|
||||
// Swagger可视化界面
|
|
||||
app.UseSwaggerUI(options => |
|
||||
{ |
|
||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support Localization Management API"); |
|
||||
}); |
|
||||
// 审计日志
|
|
||||
app.UseAuditing(); |
|
||||
// 路由
|
|
||||
app.UseConfiguredEndpoints(); |
|
||||
|
|
||||
if (env.IsDevelopment()) |
|
||||
{ |
|
||||
AsyncHelper.RunSync(async () => |
|
||||
await app.ApplicationServices.GetRequiredService<IDataSeeder>() |
|
||||
.SeedAsync()); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|||||
@ -0,0 +1,239 @@ |
|||||
|
using DotNetCore.CAP; |
||||
|
using LINGYUN.Abp.ExceptionHandling; |
||||
|
using LINGYUN.Abp.MessageService.Localization; |
||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer; |
||||
|
using Microsoft.AspNetCore.Cors; |
||||
|
using Microsoft.AspNetCore.DataProtection; |
||||
|
using Microsoft.Extensions.Caching.StackExchangeRedis; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.OpenApi.Models; |
||||
|
using StackExchange.Redis; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text.Encodings.Web; |
||||
|
using System.Text.Unicode; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.AspNetCore.Auditing; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Abp.Json.SystemTextJson; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
|
||||
|
namespace LINGYUN.Abp.MessageService |
||||
|
{ |
||||
|
public partial class AbpMessageServiceHttpApiHostModule |
||||
|
{ |
||||
|
private void PreConfigureCAP(IConfiguration configuration) |
||||
|
{ |
||||
|
PreConfigure<CapOptions>(options => |
||||
|
{ |
||||
|
options |
||||
|
.UseMySql(configuration.GetConnectionString("Default")) |
||||
|
.UseRabbitMQ(rabbitMQOptions => |
||||
|
{ |
||||
|
configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); |
||||
|
}) |
||||
|
.UseDashboard(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureDbContext() |
||||
|
{ |
||||
|
// 配置Ef
|
||||
|
Configure<AbpDbContextOptions>(options => |
||||
|
{ |
||||
|
options.UseMySQL(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureJsonSerializer() |
||||
|
{ |
||||
|
// 中文序列化的编码问题
|
||||
|
Configure<AbpSystemTextJsonSerializerOptions>(options => |
||||
|
{ |
||||
|
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigreExceptionHandling() |
||||
|
{ |
||||
|
// 自定义需要处理的异常
|
||||
|
Configure<AbpExceptionHandlingOptions>(options => |
||||
|
{ |
||||
|
// 加入需要处理的异常类型
|
||||
|
options.Handlers.Add<Volo.Abp.Data.AbpDbConcurrencyException>(); |
||||
|
options.Handlers.Add<AbpInitializationException>(); |
||||
|
options.Handlers.Add<ObjectDisposedException>(); |
||||
|
options.Handlers.Add<StackOverflowException>(); |
||||
|
options.Handlers.Add<OutOfMemoryException>(); |
||||
|
options.Handlers.Add<System.Data.Common.DbException>(); |
||||
|
options.Handlers.Add<Microsoft.EntityFrameworkCore.DbUpdateException>(); |
||||
|
options.Handlers.Add<System.Data.DBConcurrencyException>(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureAuditing(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpAspNetCoreAuditingOptions>(options => |
||||
|
{ |
||||
|
options.IgnoredUrls.AddIfNotContains("/hangfire"); |
||||
|
}); |
||||
|
|
||||
|
Configure<AbpAuditingOptions>(options => |
||||
|
{ |
||||
|
options.ApplicationName = "Localization"; |
||||
|
// 是否启用实体变更记录
|
||||
|
var entitiesChangedConfig = configuration.GetSection("App:TrackingEntitiesChanged"); |
||||
|
if (entitiesChangedConfig.Exists() && entitiesChangedConfig.Get<bool>()) |
||||
|
{ |
||||
|
options |
||||
|
.EntityHistorySelectors |
||||
|
.AddAllEntities(); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureCaching(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpDistributedCacheOptions>(options => |
||||
|
{ |
||||
|
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
|
||||
|
options.KeyPrefix = "LINGYUN.Abp.Application"; |
||||
|
// 滑动过期30天
|
||||
|
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); |
||||
|
// 绝对过期60天
|
||||
|
options.GlobalCacheEntryOptions.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(60); |
||||
|
}); |
||||
|
|
||||
|
Configure<RedisCacheOptions>(options => |
||||
|
{ |
||||
|
var redisConfig = ConfigurationOptions.Parse(options.Configuration); |
||||
|
options.ConfigurationOptions = redisConfig; |
||||
|
options.InstanceName = configuration["Redis:InstanceName"]; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureVirtualFileSystem() |
||||
|
{ |
||||
|
Configure<AbpVirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<AbpMessageServiceHttpApiHostModule>("LINGYUN.Abp.MessageService"); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureMultiTenancy(IConfiguration configuration) |
||||
|
{ |
||||
|
// 多租户
|
||||
|
Configure<AbpMultiTenancyOptions>(options => |
||||
|
{ |
||||
|
options.IsEnabled = true; |
||||
|
}); |
||||
|
|
||||
|
var tenantResolveCfg = configuration.GetSection("App:Domains"); |
||||
|
if (tenantResolveCfg.Exists()) |
||||
|
{ |
||||
|
Configure<AbpTenantResolveOptions>(options => |
||||
|
{ |
||||
|
var domains = tenantResolveCfg.Get<string[]>(); |
||||
|
foreach (var domain in domains) |
||||
|
{ |
||||
|
options.AddDomainTenantResolver(domain); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSwagger(IServiceCollection services) |
||||
|
{ |
||||
|
// Swagger
|
||||
|
services.AddSwaggerGen( |
||||
|
options => |
||||
|
{ |
||||
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "MessageService API", Version = "v1" }); |
||||
|
options.DocInclusionPredicate((docName, description) => true); |
||||
|
options.CustomSchemaIds(type => type.FullName); |
||||
|
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme |
||||
|
{ |
||||
|
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", |
||||
|
Name = "Authorization", |
||||
|
In = ParameterLocation.Header, |
||||
|
Scheme = "bearer", |
||||
|
Type = SecuritySchemeType.Http, |
||||
|
BearerFormat = "JWT" |
||||
|
}); |
||||
|
options.AddSecurityRequirement(new OpenApiSecurityRequirement |
||||
|
{ |
||||
|
{ |
||||
|
new OpenApiSecurityScheme |
||||
|
{ |
||||
|
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } |
||||
|
}, |
||||
|
new string[] { } |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureCors(IServiceCollection services, IConfiguration configuration) |
||||
|
{ |
||||
|
services.AddCors(options => |
||||
|
{ |
||||
|
options.AddPolicy(DefaultCorsPolicyName, builder => |
||||
|
{ |
||||
|
builder |
||||
|
.WithOrigins( |
||||
|
configuration["App:CorsOrigins"] |
||||
|
.Split(",", StringSplitOptions.RemoveEmptyEntries) |
||||
|
.Select(o => o.RemovePostFix("/")) |
||||
|
.ToArray() |
||||
|
) |
||||
|
.WithAbpExposedHeaders() |
||||
|
.SetIsOriginAllowedToAllowWildcardSubdomains() |
||||
|
.AllowAnyHeader() |
||||
|
.AllowAnyMethod() |
||||
|
.AllowCredentials(); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureLocalization() |
||||
|
{ |
||||
|
// 支持本地化语言类型
|
||||
|
Configure<AbpLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
||||
|
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
||||
|
|
||||
|
options.Resources |
||||
|
.Get<MessageServiceResource>() |
||||
|
.AddVirtualJson("/Localization/HttpApiHost"); |
||||
|
|
||||
|
options.Resources.AddDynamic(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSecurity(IServiceCollection services, IConfiguration configuration, bool isDevelopment = false) |
||||
|
{ |
||||
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) |
||||
|
.AddJwtBearer(options => |
||||
|
{ |
||||
|
options.Authority = configuration["AuthServer:Authority"]; |
||||
|
options.RequireHttpsMetadata = false; |
||||
|
options.Audience = configuration["AuthServer:ApiName"]; |
||||
|
}); |
||||
|
|
||||
|
if (!isDevelopment) |
||||
|
{ |
||||
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
||||
|
services |
||||
|
.AddDataProtection() |
||||
|
.PersistKeysToStackExchangeRedis(redis, "MessageService-Protection-Keys"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.Threading; |
||||
|
|
||||
|
namespace LINGYUN.Abp.MessageService |
||||
|
{ |
||||
|
public partial class AbpMessageServiceHttpApiHostModule |
||||
|
{ |
||||
|
private void SeedData(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
if (context.GetEnvironment().IsDevelopment()) |
||||
|
{ |
||||
|
AsyncHelper.RunSync(async () => |
||||
|
await context.ServiceProvider.GetRequiredService<IDataSeeder>() |
||||
|
.SeedAsync()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,243 @@ |
|||||
|
using DotNetCore.CAP; |
||||
|
using LINGYUN.Abp.ExceptionHandling; |
||||
|
using LINGYUN.Abp.ExceptionHandling.Emailing; |
||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer; |
||||
|
using Microsoft.AspNetCore.DataProtection; |
||||
|
using Microsoft.AspNetCore.Server.Kestrel.Core; |
||||
|
using Microsoft.Extensions.Caching.StackExchangeRedis; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.OpenApi.Models; |
||||
|
using StackExchange.Redis; |
||||
|
using System; |
||||
|
using System.IO; |
||||
|
using System.Text.Encodings.Web; |
||||
|
using System.Text.Unicode; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Volo.Abp.BlobStoring; |
||||
|
using Volo.Abp.BlobStoring.FileSystem; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Abp.Json.SystemTextJson; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
|
||||
|
namespace LINGYUN.Platform |
||||
|
{ |
||||
|
public partial class AppPlatformHttpApiHostModule |
||||
|
{ |
||||
|
private void PreConfigureCAP(IConfiguration configuration) |
||||
|
{ |
||||
|
PreConfigure<CapOptions>(options => |
||||
|
{ |
||||
|
options |
||||
|
.UseMySql(configuration.GetConnectionString("Default")) |
||||
|
.UseRabbitMQ(rabbitMQOptions => |
||||
|
{ |
||||
|
configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); |
||||
|
}) |
||||
|
.UseDashboard(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureDbContext() |
||||
|
{ |
||||
|
// 配置Ef
|
||||
|
Configure<AbpDbContextOptions>(options => |
||||
|
{ |
||||
|
options.UseMySQL(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureJsonSerializer() |
||||
|
{ |
||||
|
// 中文序列化的编码问题
|
||||
|
Configure<AbpSystemTextJsonSerializerOptions>(options => |
||||
|
{ |
||||
|
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureKestrelServer() |
||||
|
{ |
||||
|
Configure<KestrelServerOptions>(options => |
||||
|
{ |
||||
|
options.Limits.MaxRequestBodySize = null; |
||||
|
options.Limits.MaxRequestBufferSize = null; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureBlobStoring() |
||||
|
{ |
||||
|
Configure<AbpBlobStoringOptions>(options => |
||||
|
{ |
||||
|
options.Containers.ConfigureAll((containerName, containerConfiguration) => |
||||
|
{ |
||||
|
containerConfiguration.UseFileSystem(fileSystem => |
||||
|
{ |
||||
|
fileSystem.BasePath = Path.Combine(Directory.GetCurrentDirectory(), "file-blob-storing"); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigreExceptionHandling() |
||||
|
{ |
||||
|
// 自定义需要处理的异常
|
||||
|
Configure<AbpExceptionHandlingOptions>(options => |
||||
|
{ |
||||
|
// 加入需要处理的异常类型
|
||||
|
options.Handlers.Add<Volo.Abp.Data.AbpDbConcurrencyException>(); |
||||
|
options.Handlers.Add<AbpInitializationException>(); |
||||
|
options.Handlers.Add<ObjectDisposedException>(); |
||||
|
options.Handlers.Add<StackOverflowException>(); |
||||
|
options.Handlers.Add<OutOfMemoryException>(); |
||||
|
options.Handlers.Add<System.Data.Common.DbException>(); |
||||
|
options.Handlers.Add<Microsoft.EntityFrameworkCore.DbUpdateException>(); |
||||
|
options.Handlers.Add<System.Data.DBConcurrencyException>(); |
||||
|
}); |
||||
|
// 自定义需要发送邮件通知的异常类型
|
||||
|
Configure<AbpEmailExceptionHandlingOptions>(options => |
||||
|
{ |
||||
|
// 是否发送堆栈信息
|
||||
|
options.SendStackTrace = true; |
||||
|
}); |
||||
|
|
||||
|
Configure<Volo.Abp.AspNetCore.ExceptionHandling.AbpExceptionHandlingOptions>(options => |
||||
|
{ |
||||
|
// 是否发送错误详情
|
||||
|
options.SendExceptionsDetailsToClients = false; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureAuditing(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpAuditingOptions>(options => |
||||
|
{ |
||||
|
options.ApplicationName = "Platform"; |
||||
|
// 是否启用实体变更记录
|
||||
|
var entitiesChangedConfig = configuration.GetSection("App:TrackingEntitiesChanged"); |
||||
|
if (entitiesChangedConfig.Exists() && entitiesChangedConfig.Get<bool>()) |
||||
|
{ |
||||
|
options |
||||
|
.EntityHistorySelectors |
||||
|
.AddAllEntities(); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureCaching(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AbpDistributedCacheOptions>(options => |
||||
|
{ |
||||
|
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
|
||||
|
options.KeyPrefix = "LINGYUN.Abp.Application"; |
||||
|
// 滑动过期30天
|
||||
|
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); |
||||
|
// 绝对过期60天
|
||||
|
options.GlobalCacheEntryOptions.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(60); |
||||
|
}); |
||||
|
|
||||
|
Configure<RedisCacheOptions>(options => |
||||
|
{ |
||||
|
var redisConfig = ConfigurationOptions.Parse(options.Configuration); |
||||
|
options.ConfigurationOptions = redisConfig; |
||||
|
options.InstanceName = configuration["Redis:InstanceName"]; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureVirtualFileSystem() |
||||
|
{ |
||||
|
Configure<AbpVirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<AppPlatformHttpApiHostModule>("LINGYUN.Platform"); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureMultiTenancy(IConfiguration configuration) |
||||
|
{ |
||||
|
// 多租户
|
||||
|
Configure<AbpMultiTenancyOptions>(options => |
||||
|
{ |
||||
|
options.IsEnabled = true; |
||||
|
}); |
||||
|
|
||||
|
var tenantResolveCfg = configuration.GetSection("App:Domains"); |
||||
|
if (tenantResolveCfg.Exists()) |
||||
|
{ |
||||
|
Configure<AbpTenantResolveOptions>(options => |
||||
|
{ |
||||
|
var domains = tenantResolveCfg.Get<string[]>(); |
||||
|
foreach (var domain in domains) |
||||
|
{ |
||||
|
options.AddDomainTenantResolver(domain); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSwagger(IServiceCollection services) |
||||
|
{ |
||||
|
// Swagger
|
||||
|
services.AddSwaggerGen( |
||||
|
options => |
||||
|
{ |
||||
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Platform API", Version = "v1" }); |
||||
|
options.DocInclusionPredicate((docName, description) => true); |
||||
|
options.CustomSchemaIds(type => type.FullName); |
||||
|
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme |
||||
|
{ |
||||
|
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", |
||||
|
Name = "Authorization", |
||||
|
In = ParameterLocation.Header, |
||||
|
Scheme = "bearer", |
||||
|
Type = SecuritySchemeType.Http, |
||||
|
BearerFormat = "JWT" |
||||
|
}); |
||||
|
options.AddSecurityRequirement(new OpenApiSecurityRequirement |
||||
|
{ |
||||
|
{ |
||||
|
new OpenApiSecurityScheme |
||||
|
{ |
||||
|
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } |
||||
|
}, |
||||
|
new string[] { } |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureLocalization() |
||||
|
{ |
||||
|
// 支持本地化语言类型
|
||||
|
Configure<AbpLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
||||
|
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
||||
|
|
||||
|
options.Resources.AddDynamic(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSecurity(IServiceCollection services, IConfiguration configuration, bool isDevelopment = false) |
||||
|
{ |
||||
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) |
||||
|
.AddJwtBearer(options => |
||||
|
{ |
||||
|
options.Authority = configuration["AuthServer:Authority"]; |
||||
|
options.RequireHttpsMetadata = false; |
||||
|
options.Audience = configuration["AuthServer:ApiName"]; |
||||
|
}); |
||||
|
|
||||
|
if (!isDevelopment) |
||||
|
{ |
||||
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); |
||||
|
services |
||||
|
.AddDataProtection() |
||||
|
.PersistKeysToStackExchangeRedis(redis, "Platform-Protection-Keys"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.Threading; |
||||
|
|
||||
|
namespace LINGYUN.Platform |
||||
|
{ |
||||
|
public partial class AppPlatformHttpApiHostModule |
||||
|
{ |
||||
|
private void SeedData(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
if (context.GetEnvironment().IsDevelopment()) |
||||
|
{ |
||||
|
AsyncHelper.RunSync(async () => |
||||
|
await context.ServiceProvider.GetRequiredService<IDataSeeder>() |
||||
|
.SeedAsync()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue