Browse Source

use forwarded headers middleware

pull/144/head
cKey 5 years ago
parent
commit
5c44b98692
  1. 3
      .vs/ProjectSettings.json
  2. BIN
      .vs/slnx.sqlite
  3. 4
      aspnet-core/LINGYUN.MicroService.All.sln
  4. 14
      aspnet-core/LINGYUN.MicroService.ApiGateway.sln
  5. 9
      aspnet-core/configuration/account/AuthServer.Host/appsettings.Development.json
  6. 12
      aspnet-core/configuration/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/appsettings.Development.json
  7. 10
      aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json
  8. 11
      aspnet-core/configuration/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/appsettings.Development.json
  9. 8
      aspnet-core/configuration/messages/LINGYUN.Abp.MessageService.HttpApi.Host/appsettings.Development.json
  10. 9
      aspnet-core/configuration/platform/LINGYUN.Platform.HttpApi.Host/appsettings.Development.json
  11. 26
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN.ApiGateWay.Admin.Domain.Shared.csproj
  12. 32
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/ApiGateWayAdminDomainSharedModule.cs
  13. 8
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/HostAndPortConsts.cs
  14. 7
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/Http/HttpDelegatingHandlerConsts.cs
  15. 10
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/Localization/ApiGateWayAdminResource.cs
  16. 5
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/Localization/Resources/en.json
  17. 6
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/Localization/Resources/zh-Hans.json
  18. 13
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/RouteGroupAppKey.cs
  19. 17
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN.ApiGateWay.Admin.Domain.csproj
  20. 12
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/ApiGateWayAdminDomainModule.cs
  21. 12
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Globals/Global.cs
  22. 62
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/HostAndPort.cs
  23. 13
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/DownstreamHttpMethod.cs
  24. 45
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/HttpDelegatingHandler.cs
  25. 43
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/HttpHandler.cs
  26. 51
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/HttpHeader.cs
  27. 45
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/HttpMethod.cs
  28. 51
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/HttpQuery.cs
  29. 13
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/UpstreamHttpMethod.cs
  30. 37
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/LoadBalancer.cs
  31. 32
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/QoS.cs
  32. 57
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/RateLimitRule.cs
  33. 348
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/Route.cs
  34. 20
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteAddRequestHttpHeader.cs
  35. 20
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteAddToRequestClaim.cs
  36. 20
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteAddToRequestHttpQuery.cs
  37. 45
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteAllowedScope.cs
  38. 53
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteAuthentication.cs
  39. 22
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteCache.cs
  40. 19
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteDownstreamHostAndPort.cs
  41. 21
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteDownstreamHttpMethod.cs
  42. 20
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteDownstreamTransformHttpHeader.cs
  43. 21
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteHttpDelegatingHandler.cs
  44. 20
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteHttpHandler.cs
  45. 11
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteHttpMethod.cs
  46. 23
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteLoadBalancer.cs
  47. 22
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteQos.cs
  48. 23
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteRateLimitRule.cs
  49. 20
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteRequirementClaim.cs
  50. 21
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteUpstreamHttpMethod.cs
  51. 20
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteUpstreamTransformHttpHeader.cs
  52. 50
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Security/Claim.cs
  53. 34
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Security/RouteClientWhite.cs
  54. 40
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Security/RouteIPBlock.cs
  55. 41
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Security/RouteIPWhite.cs
  56. 56
      aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Security/RouteSecurity.cs
  57. 2
      aspnet-core/modules/common/LINGYUN.Abp.Settings/Volo/Abp/Settings/ISettingProviderExtensions.cs
  58. 30
      aspnet-core/modules/permissions-management/LINGYUN.Abp.PermissionManagement.Domain/LINGYUN/Abp/PermissionManagement/FixClientPermissionValueProvider.cs
  59. 3
      aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/SettingAppService.cs
  60. 35
      aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs
  61. 31
      aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs
  62. 35
      aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/MultiTenancy/AuthorizationTenantResolveContributor.cs
  63. 2
      aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/Properties/launchSettings.json
  64. 44
      aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/Tests/ProxyConnectTestMiddleware.cs
  65. 12
      aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/Tests/ProxyConnectTestMiddlewareExtensions.cs
  66. 3
      aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs
  67. 12
      aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs
  68. 28
      aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs
  69. 35
      aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/MultiTenancy/AuthorizationTenantResolveContributor.cs
  70. 27
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs
  71. 35
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/MultiTenancy/AuthorizationTenantResolveContributor.cs
  72. 31
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs
  73. 35
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/MultiTenancy/AuthorizationTenantResolveContributor.cs

3
.vs/ProjectSettings.json

@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}

BIN
.vs/slnx.sqlite

Binary file not shown.

4
aspnet-core/LINGYUN.MicroService.All.sln

@ -265,9 +265,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cloud-aliyun", "cloud-aliyu
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cloud-tencent", "cloud-tencent", "{3B96F4D8-4993-419B-BCEB-AFE4ED39449F}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cloud-tencent", "cloud-tencent", "{3B96F4D8-4993-419B-BCEB-AFE4ED39449F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Aliyun", "modules\cloud-aliyun\LINGYUN.Abp.Aliyun\LINGYUN.Abp.Aliyun.csproj", "{FCFAF1AF-B3F6-45F3-85AB-8249EB8432CC}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Aliyun", "modules\cloud-aliyun\LINGYUN.Abp.Aliyun\LINGYUN.Abp.Aliyun.csproj", "{FCFAF1AF-B3F6-45F3-85AB-8249EB8432CC}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Tencent", "modules\cloud-tencent\LINGYUN.Abp.Tencent\LINGYUN.Abp.Tencent.csproj", "{97B4A37E-B93E-48C9-95D5-689CB9495D8B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Tencent", "modules\cloud-tencent\LINGYUN.Abp.Tencent\LINGYUN.Abp.Tencent.csproj", "{97B4A37E-B93E-48C9-95D5-689CB9495D8B}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.Sms", "modules\common\LINGYUN.Abp.Notifications.Sms\LINGYUN.Abp.Notifications.Sms.csproj", "{8C3312E7-F51E-4780-A893-CE0E0B80B579}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.Sms", "modules\common\LINGYUN.Abp.Notifications.Sms\LINGYUN.Abp.Notifications.Sms.csproj", "{8C3312E7-F51E-4780-A893-CE0E0B80B579}"
EndProject EndProject

14
aspnet-core/LINGYUN.MicroService.ApiGateway.sln

@ -31,6 +31,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{D6629D
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.EventBus.CAP", "modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.csproj", "{1DA1835B-9EA4-4095-A8CF-10E2778206D3}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.EventBus.CAP", "modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.csproj", "{1DA1835B-9EA4-4095-A8CF-10E2778206D3}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.ApiGateWay.Admin.Domain.Shared", "modules\apigateway\LINGYUN.ApiGateWay.Admin.Domain.Shared\LINGYUN.ApiGateWay.Admin.Domain.Shared.csproj", "{1CC3B44E-213A-4853-8128-9935F2A4C5D4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.ApiGateWay.Admin.Domain", "modules\apigateway\LINGYUN.ApiGateWay.Admin.Domain\LINGYUN.ApiGateWay.Admin.Domain.csproj", "{1D548FA0-2A8F-455F-8814-F152751FB738}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -77,6 +81,14 @@ Global
{1DA1835B-9EA4-4095-A8CF-10E2778206D3}.Debug|Any CPU.Build.0 = Debug|Any CPU {1DA1835B-9EA4-4095-A8CF-10E2778206D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DA1835B-9EA4-4095-A8CF-10E2778206D3}.Release|Any CPU.ActiveCfg = Release|Any CPU {1DA1835B-9EA4-4095-A8CF-10E2778206D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DA1835B-9EA4-4095-A8CF-10E2778206D3}.Release|Any CPU.Build.0 = Release|Any CPU {1DA1835B-9EA4-4095-A8CF-10E2778206D3}.Release|Any CPU.Build.0 = Release|Any CPU
{1CC3B44E-213A-4853-8128-9935F2A4C5D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1CC3B44E-213A-4853-8128-9935F2A4C5D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1CC3B44E-213A-4853-8128-9935F2A4C5D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1CC3B44E-213A-4853-8128-9935F2A4C5D4}.Release|Any CPU.Build.0 = Release|Any CPU
{1D548FA0-2A8F-455F-8814-F152751FB738}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D548FA0-2A8F-455F-8814-F152751FB738}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D548FA0-2A8F-455F-8814-F152751FB738}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D548FA0-2A8F-455F-8814-F152751FB738}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -94,6 +106,8 @@ Global
{4757C7D9-6AE9-477D-9829-55D9906AC3E6} = {AD93DD04-989C-40BE-A3F4-25DABF290423} {4757C7D9-6AE9-477D-9829-55D9906AC3E6} = {AD93DD04-989C-40BE-A3F4-25DABF290423}
{D6629DD3-BA0F-44B5-A97F-3B992ECAB85D} = {630FB448-8C5C-438F-930D-B0209407DE6A} {D6629DD3-BA0F-44B5-A97F-3B992ECAB85D} = {630FB448-8C5C-438F-930D-B0209407DE6A}
{1DA1835B-9EA4-4095-A8CF-10E2778206D3} = {D6629DD3-BA0F-44B5-A97F-3B992ECAB85D} {1DA1835B-9EA4-4095-A8CF-10E2778206D3} = {D6629DD3-BA0F-44B5-A97F-3B992ECAB85D}
{1CC3B44E-213A-4853-8128-9935F2A4C5D4} = {AD93DD04-989C-40BE-A3F4-25DABF290423}
{1D548FA0-2A8F-455F-8814-F152751FB738} = {AD93DD04-989C-40BE-A3F4-25DABF290423}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B327C65A-BD15-480D-825E-9D5A870C521A} SolutionGuid = {B327C65A-BD15-480D-825E-9D5A870C521A}

9
aspnet-core/configuration/account/AuthServer.Host/appsettings.Development.json

@ -1,7 +1,14 @@
{ {
"App": { "App": {
"TrackingEntitiesChanged": true,
"SelfUrl": "http://localhost:44385/", "SelfUrl": "http://localhost:44385/",
"CorsOrigins": "http://localhost:4200,http://localhost:9528,http://127.0.0.1:63898" "CorsOrigins": "http://localhost:4200,http://localhost:9528,http://127.0.0.1:63898",
"Forwarded": {
"ForwardedHeaders": 5,
"KnownProxies": [
"127.0.0.1"
]
}
}, },
"AppSelfUrl": "http://localhost:44385/", "AppSelfUrl": "http://localhost:44385/",
"ConnectionStrings": { "ConnectionStrings": {

12
aspnet-core/configuration/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/appsettings.Development.json

@ -1,4 +1,14 @@
{ {
"App": {
"TrackingEntitiesChanged": true,
"SelfUrl": "http://localhost:44385/",
"Forwarded": {
"ForwardedHeaders": 5,
"KnownProxies": [
"127.0.0.1"
]
}
},
"ConnectionStrings": { "ConnectionStrings": {
"Default": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", "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", "AbpIdentity": "Server=127.0.0.1;Database=IdentityServer;User Id=root;Password=123456",
@ -24,7 +34,7 @@
"Aliyun": { "Aliyun": {
"Auth": { "Auth": {
"AccessKeyId": "你自己的阿里云Sms服务Key", "AccessKeyId": "你自己的阿里云Sms服务Key",
"AccessKeySecret": "你自己的阿里云Sms服务KeySecret", "AccessKeySecret": "你自己的阿里云Sms服务KeySecret"
}, },
"Sms": { "Sms": {
"RegionId": "cn-hangzhou", "RegionId": "cn-hangzhou",

10
aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json

@ -1,4 +1,14 @@
{ {
"App": {
"TrackingEntitiesChanged": true,
"SelfUrl": "http://localhost:44385/",
"Forwarded": {
"ForwardedHeaders": 5,
"KnownProxies": [
"127.0.0.1"
]
}
},
"ConnectionStrings": { "ConnectionStrings": {
"Default": "Server=127.0.0.1;Database=ApiGateway;User Id=root;Password=123456", "Default": "Server=127.0.0.1;Database=ApiGateway;User Id=root;Password=123456",
"ApiGateway": "Server=127.0.0.1;Database=ApiGateway;User Id=root;Password=123456", "ApiGateway": "Server=127.0.0.1;Database=ApiGateway;User Id=root;Password=123456",

11
aspnet-core/configuration/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/appsettings.Development.json

@ -1,4 +1,13 @@
{ {
"App": {
"TrackingEntitiesChanged": true,
"Forwarded": {
"ForwardedHeaders": 5,
"KnownProxies": [
"127.0.0.1"
]
}
},
"ConnectionStrings": { "ConnectionStrings": {
"Default": "Server=127.0.0.1;Database=IdentityServer;User Id=root;Password=123456", "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", "AbpIdentity": "Server=127.0.0.1;Database=IdentityServer;User Id=root;Password=123456",
@ -30,7 +39,7 @@
"Aliyun": { "Aliyun": {
"Auth": { "Auth": {
"AccessKeyId": "你自己的阿里云Sms服务Key", "AccessKeyId": "你自己的阿里云Sms服务Key",
"AccessKeySecret": "你自己的阿里云Sms服务KeySecret", "AccessKeySecret": "你自己的阿里云Sms服务KeySecret"
}, },
"Sms": { "Sms": {
"RegionId": "cn-hangzhou", "RegionId": "cn-hangzhou",

8
aspnet-core/configuration/messages/LINGYUN.Abp.MessageService.HttpApi.Host/appsettings.Development.json

@ -1,6 +1,12 @@
{ {
"App": { "App": {
"CorsOrigins": "http://localhost:9527,http://127.0.0.1:30000" "CorsOrigins": "http://localhost:9527,http://127.0.0.1:30000",
"Forwarded": {
"ForwardedHeaders": 5,
"KnownProxies": [
"127.0.0.1"
]
}
}, },
"ConnectionStrings": { "ConnectionStrings": {
"Default": "Server=127.0.0.1;Database=Messages;User Id=root;Password=123456", "Default": "Server=127.0.0.1;Database=Messages;User Id=root;Password=123456",

9
aspnet-core/configuration/platform/LINGYUN.Platform.HttpApi.Host/appsettings.Development.json

@ -1,4 +1,13 @@
{ {
"App": {
"CorsOrigins": "http://localhost:9527,http://127.0.0.1:30000",
"Forwarded": {
"ForwardedHeaders": 5,
"KnownProxies": [
"127.0.0.1"
]
}
},
"ConnectionStrings": { "ConnectionStrings": {
"Default": "Server=127.0.0.1;Database=Platform;User Id=colin;Password=123456", "Default": "Server=127.0.0.1;Database=Platform;User Id=colin;Password=123456",
"AppPlatform": "Server=127.0.0.1;Database=Platform;User Id=colin;Password=123456", "AppPlatform": "Server=127.0.0.1;Database=Platform;User Id=colin;Password=123456",

26
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN.ApiGateWay.Admin.Domain.Shared.csproj

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Localization" Version="2.9.0" />
</ItemGroup>
<ItemGroup>
<None Remove="LINGYUN\ApiGateWay\Admin\Localization\DomainShared\en.json" />
<None Remove="LINGYUN\ApiGateWay\Admin\Localization\DomainShared\zh-Hans.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="LINGYUN\ApiGateWay\Admin\Localization\DomainShared\en.json" />
<EmbeddedResource Include="LINGYUN\ApiGateWay\Admin\Localization\DomainShared\zh-Hans.json" />
</ItemGroup>
<ItemGroup>
<Folder Include="LINGYUN\ApiGateWay\Admin\Routes\" />
</ItemGroup>
</Project>

32
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/ApiGateWayAdminDomainSharedModule.cs

@ -0,0 +1,32 @@
using LINGYUN.ApiGateWay.Admin.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Localization.ExceptionHandling;
using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem;
namespace LINGYUN.ApiGateWay.Admin
{
[DependsOn(typeof(AbpLocalizationModule))]
public class ApiGateWayAdminDomainSharedModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<ApiGateWayAdminDomainSharedModule>();
});
Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Add<ApiGateWayAdminResource>("zh-Hans")
.AddVirtualJson("/LINGYUN/ApiGateWay/Admin/Localization/Resources");
});
Configure<AbpExceptionLocalizationOptions>(options =>
{
options.MapCodeNamespace("ApiGateWayAdmin", typeof(ApiGateWayAdminResource));
});
}
}
}

8
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/HostAndPortConsts.cs

@ -0,0 +1,8 @@
namespace LINGYUN.ApiGateWay.Admin
{
public class HostAndPortConsts
{
// 计算机名最大长度
public const int MaxHostLength = 255;
}
}

7
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/Http/HttpDelegatingHandlerConsts.cs

@ -0,0 +1,7 @@
namespace LINGYUN.ApiGateWay.Admin.Http
{
public class HttpDelegatingHandlerConsts
{
public const int MaxNameLength = 256;
}
}

10
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/Localization/ApiGateWayAdminResource.cs

@ -0,0 +1,10 @@
using Volo.Abp.Localization;
namespace LINGYUN.ApiGateWay.Admin.Localization
{
[LocalizationResourceName("ApiGatewayAdmin")]
public class ApiGateWayAdminResource
{
}
}

5
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/Localization/Resources/en.json

@ -0,0 +1,5 @@
{
"culture": "en",
"texts": {
}
}

6
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/Localization/Resources/zh-Hans.json

@ -0,0 +1,6 @@
{
"culture": "zh-Hans",
"texts": {
}
}

13
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain.Shared/LINGYUN/ApiGateWay/Admin/RouteGroupAppKey.cs

@ -0,0 +1,13 @@
namespace LINGYUN.ApiGateWay.Admin
{
public class RouteGroupAppKey
{
public string AppId { get; }
public string AppName { get; }
public RouteGroupAppKey(string appId, string appName)
{
AppId = appId;
AppName = appName;
}
}
}

17
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN.ApiGateWay.Admin.Domain.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Caching" Version="2.9.0" />
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="2.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.ApiGateWay.Admin.Domain.Shared\LINGYUN.ApiGateWay.Admin.Domain.Shared.csproj" />
</ItemGroup>
</Project>

12
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/ApiGateWayAdminDomainModule.cs

@ -0,0 +1,12 @@
using Volo.Abp.Domain;
using Volo.Abp.Modularity;
namespace LINGYUN.ApiGateWay.Admin
{
[DependsOn(
typeof(ApiGateWayAdminDomainSharedModule),
typeof(AbpDddDomainModule))]
public class ApiGateWayAdminDomainModule : AbpModule
{
}
}

12
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Globals/Global.cs

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.Domain.Entities.Auditing;
namespace LINGYUN.ApiGateWay.Admin.Globals
{
public class Global : FullAuditedAggregateRoot<Guid>
{
}
}

62
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/HostAndPort.cs

@ -0,0 +1,62 @@
using JetBrains.Annotations;
using System;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin
{
public class HostAndPort : Entity<Guid>
{
public virtual string Host { get; protected set; }
public virtual int? Port { get; protected set; }
protected HostAndPort()
{
}
public HostAndPort(Guid id, [NotNull] string host, int? port = null)
{
Id = id;
BindHost(host, port);
}
public void BindHost([NotNull] string host, int? port = null)
{
Check.NotNullOrWhiteSpace(host, nameof(host), HostAndPortConsts.MaxHostLength);
Host = host;
Port = port;
}
public override int GetHashCode()
{
if (!Host.IsNullOrWhiteSpace())
{
if (Port.HasValue)
{
return Host.GetHashCode() & Port.Value;
}
return Host.GetHashCode();
}
return base.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null ||
Host.IsNullOrWhiteSpace())
{
return false;
}
if (obj is HostAndPort hostAndPort)
{
if (Port.HasValue)
{
return hostAndPort.Host.Equals(Host) &&
Port.Equals(hostAndPort.Port);
}
return hostAndPort.Host.Equals(Host);
}
return false;
}
}
}

13
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/DownstreamHttpMethod.cs

@ -0,0 +1,13 @@
using System;
namespace LINGYUN.ApiGateWay.Admin.Http
{
public class DownstreamHttpMethod : HttpMethod
{
public DownstreamHttpMethod(Guid id, string method)
: base(id, method)
{
}
}
}

45
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/HttpDelegatingHandler.cs

@ -0,0 +1,45 @@
using JetBrains.Annotations;
using System;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Http
{
public class HttpDelegatingHandler : Entity<Guid>
{
public virtual string Name { get; protected set; }
protected HttpDelegatingHandler()
{
}
public HttpDelegatingHandler(Guid id, [NotNull] string name)
{
Id = id;
Name = Check.NotNullOrWhiteSpace(name, nameof(name), HttpDelegatingHandlerConsts.MaxNameLength);
}
public override int GetHashCode()
{
if (!Name.IsNullOrWhiteSpace())
{
return Name.GetHashCode();
}
return base.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null ||
Name.IsNullOrWhiteSpace())
{
return false;
}
if (obj is HttpDelegatingHandler handler)
{
return Name.Equals(handler.Name, StringComparison.CurrentCultureIgnoreCase);
}
return false;
}
}
}

43
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/HttpHandler.cs

@ -0,0 +1,43 @@
using System;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Http
{
public class HttpHandler : Entity<Guid>
{
/// <summary>
/// 每台服务器最大连接数
/// </summary>
public virtual int? MaxConnectionsPerServer { get; protected set; }
/// <summary>
/// 允许自动重定向
/// </summary>
public virtual bool AllowAutoRedirect { get; set; }
/// <summary>
/// 使用Cookie容器
/// </summary>
public virtual bool UseCookieContainer { get; set; }
/// <summary>
/// 启用跟踪
/// </summary>
public virtual bool UseTracing { get; set; }
/// <summary>
/// 启用代理
/// </summary>
public virtual bool UseProxy { get; set; }
protected HttpHandler()
{
}
public HttpHandler(Guid id)
{
Id = id;
}
public void ChangeMaxConnection(int? maxConnection = 1000)
{
MaxConnectionsPerServer = maxConnection;
}
}
}

51
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/HttpHeader.cs

@ -0,0 +1,51 @@
using JetBrains.Annotations;
using System;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Http
{
public abstract class HttpHeader : Entity<Guid>
{
public virtual string Key { get; protected set; }
public virtual string Value { get; protected set; }
protected HttpHeader()
{
}
protected HttpHeader(Guid id, [NotNull] string key, [NotNull] string value)
{
Id = id;
Key = Check.NotNullOrWhiteSpace(key, nameof(key));
Value = Check.NotNullOrWhiteSpace(value, nameof(value));
}
public override int GetHashCode()
{
if (!Key.IsNullOrWhiteSpace() &&
!Value.IsNullOrWhiteSpace())
{
return Key.GetHashCode() & Value.GetHashCode();
}
return base.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null ||
Key.IsNullOrWhiteSpace() ||
Value.IsNullOrWhiteSpace())
{
return false;
}
if (obj is HttpHeader httpHeader)
{
return httpHeader.Key.Equals(Key, StringComparison.CurrentCultureIgnoreCase) &&
httpHeader.Value.Equals(Value, StringComparison.CurrentCultureIgnoreCase);
}
return false;
}
}
}

45
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/HttpMethod.cs

@ -0,0 +1,45 @@
using System;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Http
{
public abstract class HttpMethod : Entity<Guid>
{
/// <summary>
/// Http调用方法
/// </summary>
public virtual string Method { get; protected set; }
protected HttpMethod()
{
}
protected HttpMethod(Guid id, string method)
{
Id = id;
Method = method;
}
public override int GetHashCode()
{
if (!Method.IsNullOrWhiteSpace())
{
return Method.GetHashCode();
}
return base.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null ||
Method.IsNullOrWhiteSpace())
{
return false;
}
if (obj is HttpMethod httpMethod)
{
return httpMethod.Method.Equals(Method);
}
return false;
}
}
}

51
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/HttpQuery.cs

@ -0,0 +1,51 @@
using JetBrains.Annotations;
using System;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Http
{
public class HttpQuery : Entity<Guid>
{
public virtual string Key { get; protected set; }
public virtual string Value { get; protected set; }
protected HttpQuery()
{
}
protected HttpQuery(Guid id, [NotNull] string key, [NotNull] string value)
{
Id = id;
Key = Check.NotNullOrWhiteSpace(key, nameof(key));
Value = Check.NotNullOrWhiteSpace(value, nameof(value));
}
public override int GetHashCode()
{
if (!Key.IsNullOrWhiteSpace() &&
!Value.IsNullOrWhiteSpace())
{
return Key.GetHashCode() & Value.GetHashCode();
}
return base.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null ||
Key.IsNullOrWhiteSpace() ||
Value.IsNullOrWhiteSpace())
{
return false;
}
if (obj is HttpQuery httpQuery)
{
return Key.Equals(httpQuery.Key, StringComparison.CurrentCultureIgnoreCase) &&
Value.Equals(httpQuery.Value, StringComparison.CurrentCultureIgnoreCase);
}
return false;
}
}
}

13
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Http/UpstreamHttpMethod.cs

@ -0,0 +1,13 @@
using System;
namespace LINGYUN.ApiGateWay.Admin.Http
{
public class UpstreamHttpMethod : HttpMethod
{
public UpstreamHttpMethod(Guid id, string method)
: base(id, method)
{
}
}
}

37
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/LoadBalancer.cs

@ -0,0 +1,37 @@
using System;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin
{
public class LoadBalancer : Entity<Guid>
{
/// <summary>
/// 负载均衡类型
/// </summary>
public virtual string Type { get; private set; }
/// <summary>
/// 用于Cookie会话密钥
/// </summary>
public virtual string Key { get; private set; }
/// <summary>
/// 会话阻断时间
/// </summary>
public virtual int? Expiry { get; private set; }
protected LoadBalancer()
{
}
public LoadBalancer(Guid id, string type, string key, int? expiry = null)
{
Id = id;
ApplyPolicy(type, key, expiry);
}
public void ApplyPolicy(string type, string key, int? expiry = null)
{
Type = type;
Key = key;
Expiry = expiry;
}
}
}

32
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/QoS.cs

@ -0,0 +1,32 @@
using System;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin
{
public class QoS : Entity<Guid>
{
public virtual int? ExceptionsAllowedBeforeBreaking { get; private set; }
public virtual int? DurationOfBreak { get; private set; }
public virtual int? TimeoutValue { get; private set; }
protected QoS()
{
}
public QoS(Guid id, int? exceptionsAllowdBeforeBreaking = null, int? durationOfBreak = null, int? timeOut = null)
{
Id = id;
ApplyPolicy(exceptionsAllowdBeforeBreaking, durationOfBreak, timeOut);
}
public void ApplyPolicy(int? exceptionsAllowdBeforeBreaking = null, int? durationOfBreak = null, int? timeOut = null)
{
ExceptionsAllowedBeforeBreaking = exceptionsAllowdBeforeBreaking;
DurationOfBreak = durationOfBreak;
TimeoutValue = timeOut;
}
}
}

57
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/RateLimitRule.cs

@ -0,0 +1,57 @@
using LINGYUN.ApiGateWay.Admin.Security;
using System;
using System.Collections.Generic;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin
{
public class RateLimitRule : Entity<Guid>
{
/// <summary>
/// 客户端白名单列表,多个以分号分隔
/// </summary>
public virtual ICollection<RouteClientWhite> ClientWhiteList { get; private set; }
/// <summary>
/// 是否启用流量现值
/// </summary>
public virtual bool EnableRateLimiting { get; private set; }
/// <summary>
/// 限速时段
/// </summary>
public virtual string Period { get; private set; }
/// <summary>
/// 速率极限周期
/// </summary>
public virtual double? PeriodTimespan { get; private set; }
/// <summary>
/// 客户端在定义的时间内可以发出的最大请求数
/// </summary>
public virtual long? Limit { get; private set; }
protected RateLimitRule()
{
ClientWhiteList = new List<RouteClientWhite>();
}
public RateLimitRule(Guid id, string period = "", double? periodTimespan = null,
long? limit = null, bool enabled = true)
{
Id = id;
ChangeRateLimitState(enabled);
ApplyPolicy(period, periodTimespan, limit);
}
public void ChangeRateLimitState(bool enabled = true)
{
EnableRateLimiting = enabled;
}
public void ApplyPolicy(string period = "", double? periodTimespan = null,
long? limit = null)
{
Period = period;
PeriodTimespan = periodTimespan;
Limit = limit;
}
}
}

348
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/Route.cs

@ -0,0 +1,348 @@
using LINGYUN.ApiGateWay.Admin.Security;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.Guids;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class Route : FullAuditedAggregateRoot<Guid>
{
/// <summary>
/// 应用标识
/// </summary>
public virtual string AppId { get; protected set; }
/// <summary>
/// 路由名称
/// </summary>
public virtual string Name { get; protected set; }
/// <summary>
/// 请求标识
/// </summary>
public virtual string RequestIdKey { get; set; }
/// <summary>
/// 是否区分大小写
/// </summary>
public virtual bool RouteIsCaseSensitive { get; set; }
/// <summary>
/// 服务名称
/// </summary>
public virtual string ServiceName { get; protected set; }
/// <summary>
/// 服务命名空间
/// </summary>
public virtual string ServiceNamespace { get; protected set; }
/// <summary>
/// 下游协议
/// </summary>
public virtual string DownstreamScheme { get; set; }
/// <summary>
/// 下游路由路径
/// </summary>
public virtual string DownstreamPathTemplate { get; protected set; }
/// <summary>
/// 上游路由路径
/// </summary>
public virtual string UpstreamPathTemplate { get; protected set; }
/// <summary>
/// 变更下游路径
/// </summary>
public virtual string ChangeDownstreamPathTemplate { get; protected set; }
/// <summary>
/// 上游主机
/// </summary>
public virtual string UpstreamHost { get; set; }
/// <summary>
/// 聚合标识
/// </summary>
public virtual string Key { get; set; }
/// <summary>
/// 优先级
/// </summary>
public virtual int? Priority { get; set; }
/// <summary>
/// 超时时间
/// </summary>
public virtual int? Timeout { get; set; }
/// <summary>
/// 忽略SSL警告
/// </summary>
public virtual bool DangerousAcceptAnyServerCertificateValidator { get; set; }
/// <summary>
/// 下游版本号
/// </summary>
public virtual string DownstreamHttpVersion { get; set; }
/// <summary>
/// 下游Http方法列表
/// </summary>
public virtual ICollection<RouteUpstreamHttpMethod> UpstreamHttpMethods { get; protected set; }
/// <summary>
/// 上游Http方法列表
/// </summary>
public virtual ICollection<RouteDownstreamHttpMethod> DownstreamHttpMethods { get; protected set; }
/// <summary>
/// 添加请求头参数
/// </summary>
public virtual ICollection<RouteAddRequestHttpHeader> AddHeadersToRequest { get; protected set; }
/// <summary>
/// 下游请求头转换
/// </summary>
public virtual ICollection<RouteUpstreamTransformHttpHeader> UpstreamHeaderTransform { get; protected set; }
/// <summary>
/// 上游请求头转换
/// </summary>
public virtual ICollection<RouteDownstreamTransformHttpHeader> DownstreamHeaderTransform { get; protected set; }
/// <summary>
/// 请求声明转换
/// </summary>
public virtual ICollection<RouteAddToRequestClaim> AddClaimsToRequest { get; protected set; }
/// <summary>
/// 请求必须的声明
/// </summary>
public virtual ICollection<RouteRequirementClaim> RouteClaimsRequirement { get; protected set; }
/// <summary>
/// 用户声明到请求头转换
/// </summary>
public virtual ICollection<RouteAddToRequestHttpQuery> AddQueriesToRequest { get; protected set; }
/// <summary>
/// 下游主机列表
/// </summary>
public virtual ICollection<RouteDownstreamHostAndPort> DownstreamHostAndPorts { get; protected set; }
/// <summary>
/// 授权处理器列表
/// </summary>
public virtual ICollection<RouteHttpDelegatingHandler> DelegatingHandlers { get; protected set; }
/// <summary>
/// Http选项
/// </summary>
public virtual RouteHttpHandler HttpHandler { get; protected set; }
/// <summary>
/// 授权
/// </summary>
public virtual RouteAuthentication Authentication { get; protected set; }
/// <summary>
/// 速率限制
/// </summary>
public virtual RouteRateLimitRule RouteRateLimitRule { get; protected set; }
/// <summary>
/// 负债均衡
/// </summary>
public virtual RouteLoadBalancer LoadBalancer { get; protected set; }
/// <summary>
/// 服务质量
/// </summary>
public virtual RouteQos QoS { get; protected set; }
/// <summary>
/// 文件缓存
/// </summary>
public virtual RouteCache Cache { get; protected set; }
/// <summary>
/// 安全策略
/// </summary>
public virtual RouteSecurity Security { get; protected set; }
protected Route()
{
UpstreamHttpMethods = new Collection<RouteUpstreamHttpMethod>();
DownstreamHttpMethods = new Collection<RouteDownstreamHttpMethod>();
AddHeadersToRequest = new Collection<RouteAddRequestHttpHeader>();
UpstreamHeaderTransform = new Collection<RouteUpstreamTransformHttpHeader>();
DownstreamHeaderTransform = new Collection<RouteDownstreamTransformHttpHeader>();
AddClaimsToRequest = new Collection<RouteAddToRequestClaim>();
RouteClaimsRequirement = new Collection<RouteRequirementClaim>();
AddQueriesToRequest = new Collection<RouteAddToRequestHttpQuery>();
DownstreamHostAndPorts = new Collection<RouteDownstreamHostAndPort>();
DelegatingHandlers = new Collection<RouteHttpDelegatingHandler>();
}
public void AddDownstreamHttpMethod(IGuidGenerator generator, string method)
{
DownstreamHttpMethods.AddIfNotContains(new RouteDownstreamHttpMethod(Id, generator.Create(), method)); ;
}
public void RemoveDownstreamHttpMethod(string method)
{
DownstreamHttpMethods.RemoveAll(x => x.Method.Equals(method, StringComparison.CurrentCultureIgnoreCase));
}
public void RemoveAllDownstreamHttpMethod()
{
DownstreamHttpMethods.Clear();
}
public void AddUpstreamHttpMethod(IGuidGenerator generator, string method)
{
UpstreamHttpMethods.AddIfNotContains(new RouteUpstreamHttpMethod(Id, generator.Create(), method));
}
public void RemoveUpstreamHttpMethod(string method)
{
UpstreamHttpMethods.RemoveAll(x => x.Method.Equals(method, StringComparison.CurrentCultureIgnoreCase));
}
public void RemoveAllUpstreamHttpMethod()
{
UpstreamHttpMethods.Clear();
}
public void AddRequestHeader(IGuidGenerator generator, string key, string value)
{
AddHeadersToRequest.AddIfNotContains(new RouteAddRequestHttpHeader(Id, generator.Create(), key, value));
}
public void RemoveRequestHeader(string key, string value)
{
AddHeadersToRequest.RemoveAll(x => x.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase)
&& x.Value.Equals(value, StringComparison.CurrentCultureIgnoreCase));
}
public void RemoveAllRequestHeader()
{
AddHeadersToRequest.Clear();
}
public void AddUpstreamHeaderTransform(IGuidGenerator generator, string key, string value)
{
UpstreamHeaderTransform.AddIfNotContains(new RouteUpstreamTransformHttpHeader(Id, generator.Create(), key, value));
}
public void RemoveUpstreamHeaderTransform(string key, string value)
{
UpstreamHeaderTransform.RemoveAll(x => x.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase)
&& x.Value.Equals(value, StringComparison.CurrentCultureIgnoreCase));
}
public void RemoveAllUpstreamHeaderTransform()
{
UpstreamHeaderTransform.Clear();
}
public void AddDownstreamHeaderTransform(IGuidGenerator generator, string key, string value)
{
DownstreamHeaderTransform.AddIfNotContains(new RouteDownstreamTransformHttpHeader(Id, generator.Create(), key, value));
}
public void RemoveDownstreamHeaderTransform(string key, string value)
{
DownstreamHeaderTransform.RemoveAll(x => x.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase)
&& x.Value.Equals(value, StringComparison.CurrentCultureIgnoreCase));
}
public void RemoveAllDownstreamHeaderTransform()
{
DownstreamHeaderTransform.Clear();
}
public void AddRequestClaim(IGuidGenerator generator, string key, string value)
{
AddClaimsToRequest.AddIfNotContains(new RouteAddToRequestClaim(Id, generator.Create(), key, value));
}
public void RemoveRequestClaim(string key, string value)
{
AddClaimsToRequest.RemoveAll(x => x.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase)
&& x.Value.Equals(value, StringComparison.CurrentCultureIgnoreCase));
}
public void RemoveAllRequestClaim()
{
AddClaimsToRequest.Clear();
}
public void AddRequirementClaim(IGuidGenerator generator, string key, string value)
{
RouteClaimsRequirement.AddIfNotContains(new RouteRequirementClaim(Id, generator.Create(), key, value));
}
public void RemoveRequirementClaim(string key, string value)
{
RouteClaimsRequirement.RemoveAll(x => x.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase)
&& x.Value.Equals(value, StringComparison.CurrentCultureIgnoreCase));
}
public void RemoveAllRequirementClaim()
{
RouteClaimsRequirement.Clear();
}
public void AddRequestQuery(IGuidGenerator generator, string key, string value)
{
AddQueriesToRequest.AddIfNotContains(new RouteAddToRequestHttpQuery(Id, generator.Create(), key, value));
}
public void RemoveRequestQuery(string key, string value)
{
AddQueriesToRequest.RemoveAll(x => x.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase)
&& x.Value.Equals(value, StringComparison.CurrentCultureIgnoreCase));
}
public void RemoveAllRequestQuery()
{
AddQueriesToRequest.Clear();
}
public void AddDownstreamHost(IGuidGenerator generator, string host, int? port)
{
DownstreamHostAndPorts.AddIfNotContains(new RouteDownstreamHostAndPort(Id, generator.Create(), host, port));
}
public void RemoveDownstreamHost(string host, int? port)
{
DownstreamHostAndPorts.RemoveAll(x => x.Host.Equals(host, StringComparison.CurrentCultureIgnoreCase)
&& x.Port.Equals(port));
}
public void RemoveAllDownstreamHost()
{
DownstreamHostAndPorts.Clear();
}
public void AddDelegatingHandler(IGuidGenerator generator, string name)
{
DelegatingHandlers.AddIfNotContains(new RouteHttpDelegatingHandler(Id, generator.Create(), name));
}
public void RemoveDelegatingHandler(string name)
{
DelegatingHandlers.RemoveAll(x => x.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));
}
public void RemoveAllDelegatingHandler()
{
DelegatingHandlers.Clear();
}
public void BindService(string serviceName, string @namespace)
{
ServiceName = serviceName;
ServiceNamespace = @namespace;
}
public void UseHttpHandler(IGuidGenerator generator, bool autoRedirect = false, bool useCookie = false,
bool useTracking = false, bool useProxy = false, int? maxConnection = 1000)
{
if (HttpHandler == null)
{
HttpHandler = new RouteHttpHandler(generator.Create(), Id);
}
HttpHandler.UseProxy = useProxy;
HttpHandler.UseTracing = useTracking;
HttpHandler.UseCookieContainer = useCookie;
HttpHandler.AllowAutoRedirect = autoRedirect;
HttpHandler.ChangeMaxConnection(maxConnection);
}
public void UseAuthentication(IGuidGenerator generator, string provider, IEnumerable<string> allowScope)
{
if (Authentication == null)
{
Authentication = new RouteAuthentication(generator.Create(), Id, provider);
}
Authentication.AddScopes(allowScope);
}
}
}

20
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteAddRequestHttpHeader.cs

@ -0,0 +1,20 @@
using LINGYUN.ApiGateWay.Admin.Http;
using System;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteAddRequestHttpHeader : HttpHeader
{
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteAddRequestHttpHeader()
{
}
public RouteAddRequestHttpHeader(Guid routeId, Guid httpHeaderId, string key, string value)
: base(httpHeaderId, key, value)
{
RouteId = routeId;
}
}
}

20
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteAddToRequestClaim.cs

@ -0,0 +1,20 @@
using LINGYUN.ApiGateWay.Admin.Security;
using System;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteAddToRequestClaim : Claim
{
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteAddToRequestClaim()
{
}
public RouteAddToRequestClaim(Guid routeId, Guid claimId, string key, string value)
: base(claimId, key, value)
{
RouteId = routeId;
}
}
}

20
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteAddToRequestHttpQuery.cs

@ -0,0 +1,20 @@
using LINGYUN.ApiGateWay.Admin.Http;
using System;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteAddToRequestHttpQuery : HttpQuery
{
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteAddToRequestHttpQuery()
{
}
public RouteAddToRequestHttpQuery(Guid routeId, Guid httpQueryId, string key, string value)
: base(httpQueryId, key, value)
{
RouteId = routeId;
}
}
}

45
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteAllowedScope.cs

@ -0,0 +1,45 @@
using System;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteAllowedScope : Entity<int>
{
public virtual string Scope { get; protected set; }
public virtual Guid AuthenticationId { get; protected set; }
public virtual RouteAuthentication Authentication { get; protected set; }
protected RouteAllowedScope()
{
}
public RouteAllowedScope(Guid authenticationId, string scope)
{
AuthenticationId = authenticationId;
Scope = scope;
}
public override int GetHashCode()
{
if (!Scope.IsNullOrWhiteSpace())
{
return Scope.GetHashCode();
}
return base.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null ||
Scope.IsNullOrWhiteSpace())
{
return false;
}
if (obj is RouteAllowedScope allowedScope)
{
return allowedScope.Scope.Equals(Scope);
}
return false;
}
}
}

53
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteAuthentication.cs

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteAuthentication : Entity<Guid>
{
public virtual string AuthenticationProviderKey { get; private set; }
public virtual ICollection<RouteAllowedScope> AllowedScopes { get; set; }
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteAuthentication()
{
AllowedScopes = new List<RouteAllowedScope>();
}
public RouteAuthentication(Guid id, Guid routeId, string providerKey)
{
Id = id;
RouteId = routeId;
ChangeProvider(providerKey);
}
public void ChangeProvider(string providerKey)
{
AuthenticationProviderKey = providerKey;
}
public void AddScope(string scope)
{
AllowedScopes.AddIfNotContains(new RouteAllowedScope(Id, scope));
}
public void AddScopes(IEnumerable<string> scope)
{
foreach(var scop in scope)
{
AddScope(scop);
}
}
public void RemoveScope(string scope)
{
AllowedScopes.RemoveAll(x => x.Scope.Equals(scope, StringComparison.CurrentCultureIgnoreCase));
}
public void RemoveAllScope()
{
AllowedScopes.Clear();
}
}
}

22
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteCache.cs

@ -0,0 +1,22 @@
using System;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteCache : Entity<int>
{
public virtual int? TtlSeconds { get; private set; }
public virtual string Region { get; private set; }
public virtual Guid RouteId { get; private set; }
public virtual Route Route { get; private set; }
protected RouteCache()
{
}
public RouteCache(Guid routeId, string region = "", int? ttlSeconds = null)
{
RouteId = routeId;
Region = region;
TtlSeconds = ttlSeconds;
}
}
}

19
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteDownstreamHostAndPort.cs

@ -0,0 +1,19 @@
using System;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteDownstreamHostAndPort : HostAndPort
{
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteDownstreamHostAndPort()
{
}
public RouteDownstreamHostAndPort(Guid routeId, Guid hostId, string key, int? port)
: base(hostId, key, port)
{
RouteId = routeId;
}
}
}

21
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteDownstreamHttpMethod.cs

@ -0,0 +1,21 @@
using LINGYUN.ApiGateWay.Admin.Http;
using System;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteDownstreamHttpMethod : HttpMethod
{
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteDownstreamHttpMethod()
{
}
public RouteDownstreamHttpMethod(Guid routeId, Guid httpMethodId, string method)
: base(httpMethodId, method)
{
RouteId = routeId;
}
}
}

20
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteDownstreamTransformHttpHeader.cs

@ -0,0 +1,20 @@
using LINGYUN.ApiGateWay.Admin.Http;
using System;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteDownstreamTransformHttpHeader : HttpHeader
{
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteDownstreamTransformHttpHeader()
{
}
public RouteDownstreamTransformHttpHeader(Guid routeId, Guid httpHeaderId, string key, string value)
: base(httpHeaderId, key, value)
{
RouteId = routeId;
}
}
}

21
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteHttpDelegatingHandler.cs

@ -0,0 +1,21 @@
using JetBrains.Annotations;
using LINGYUN.ApiGateWay.Admin.Http;
using System;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteHttpDelegatingHandler : HttpDelegatingHandler
{
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteHttpDelegatingHandler()
{
}
public RouteHttpDelegatingHandler(Guid routeId, Guid httpHandlerId, [NotNull] string name)
: base(httpHandlerId, name)
{
RouteId = routeId;
}
}
}

20
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteHttpHandler.cs

@ -0,0 +1,20 @@
using LINGYUN.ApiGateWay.Admin.Http;
using System;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteHttpHandler : HttpHandler
{
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteHttpHandler()
{
}
public RouteHttpHandler(Guid id, Guid routeId)
{
Id = id;
RouteId = routeId;
}
}
}

11
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteHttpMethod.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteHttpMethod
{
}
}

23
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteLoadBalancer.cs

@ -0,0 +1,23 @@
using System;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteLoadBalancer : Entity<int>
{
public virtual Guid LoadBalancerId { get; private set; }
public virtual LoadBalancer LoadBalancer { get; private set; }
public virtual Guid RouteId { get; private set; }
public virtual Route Route { get; private set; }
protected RouteLoadBalancer()
{
}
public RouteLoadBalancer(Guid routeId, Guid loadBalancerId)
{
RouteId = routeId;
LoadBalancerId = loadBalancerId;
}
}
}

22
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteQos.cs

@ -0,0 +1,22 @@
using System;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteQos : Entity<int>
{
public virtual Guid QoSId { get; protected set; }
public virtual QoS QoS { get; protected set; }
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteQos()
{
}
public RouteQos(Guid routeId, Guid qosId)
{
RouteId = routeId;
QoSId = qosId;
}
}
}

23
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteRateLimitRule.cs

@ -0,0 +1,23 @@
using System;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteRateLimitRule : Entity<int>
{
public virtual Guid RateLimitRuleId { get; protected set; }
public virtual RateLimitRule RateLimitRule { get; protected set; }
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteRateLimitRule()
{
}
public RouteRateLimitRule(Guid routeId, Guid rateLimitRuleId)
{
RouteId = routeId;
RateLimitRuleId = rateLimitRuleId;
}
}
}

20
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteRequirementClaim.cs

@ -0,0 +1,20 @@
using LINGYUN.ApiGateWay.Admin.Security;
using System;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteRequirementClaim : Claim
{
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteRequirementClaim()
{
}
public RouteRequirementClaim(Guid routeId, Guid claimId, string key, string value)
: base(claimId, key, value)
{
RouteId = routeId;
}
}
}

21
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteUpstreamHttpMethod.cs

@ -0,0 +1,21 @@
using LINGYUN.ApiGateWay.Admin.Http;
using System;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteUpstreamHttpMethod : HttpMethod
{
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteUpstreamHttpMethod()
{
}
public RouteUpstreamHttpMethod(Guid routeId, Guid httpMethodId, string method)
: base(httpMethodId, method)
{
RouteId = routeId;
}
}
}

20
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Routes/RouteUpstreamTransformHttpHeader.cs

@ -0,0 +1,20 @@
using LINGYUN.ApiGateWay.Admin.Http;
using System;
namespace LINGYUN.ApiGateWay.Admin.Routes
{
public class RouteUpstreamTransformHttpHeader : HttpHeader
{
public virtual Guid RouteId { get; protected set; }
public virtual Route Route { get; protected set; }
protected RouteUpstreamTransformHttpHeader()
{
}
public RouteUpstreamTransformHttpHeader(Guid routeId, Guid httpHeaderId, string key, string value)
: base(httpHeaderId, key, value)
{
RouteId = routeId;
}
}
}

50
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Security/Claim.cs

@ -0,0 +1,50 @@
using JetBrains.Annotations;
using System;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Security
{
public class Claim : Entity<Guid>
{
public virtual string Key { get; protected set; }
public virtual string Value { get; protected set; }
protected Claim()
{
}
protected Claim(Guid id, [NotNull] string key, [NotNull] string value)
{
Id = id;
Key = Check.NotNullOrWhiteSpace(key, nameof(key));
Value = Check.NotNullOrWhiteSpace(value, nameof(value));
}
public override int GetHashCode()
{
if (!Key.IsNullOrWhiteSpace() &&
!Value.IsNullOrWhiteSpace())
{
return Key.GetHashCode() & Value.GetHashCode();
}
return base.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null ||
Key.IsNullOrWhiteSpace() ||
Value.IsNullOrWhiteSpace())
{
return false;
}
if (obj is Claim claim)
{
return claim.Key.Equals(Key, StringComparison.CurrentCultureIgnoreCase) &&
claim.Value.Equals(Value, StringComparison.CurrentCultureIgnoreCase);
}
return false;
}
}
}

34
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Security/RouteClientWhite.cs

@ -0,0 +1,34 @@
using System;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Security
{
public class RouteClientWhite : Entity<int>
{
public virtual string ClientId { get; private set; }
public virtual Guid RateLimitRuleId { get; private set; }
public virtual RateLimitRule RateLimitRule { get; private set; }
public override int GetHashCode()
{
if (!ClientId.IsNullOrWhiteSpace())
{
return ClientId.GetHashCode();
}
return base.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null ||
ClientId.IsNullOrWhiteSpace())
{
return false;
}
if (obj is RouteClientWhite clientWhite)
{
return clientWhite.ClientId.Equals(ClientId);
}
return false;
}
}
}

40
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Security/RouteIPBlock.cs

@ -0,0 +1,40 @@
using System;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Security
{
public class RouteIPBlock : Entity<int>
{
public virtual string Address { get; private set; }
public virtual Guid SecurityId { get; private set; }
public virtual RouteSecurity Security { get; private set; }
protected RouteIPBlock() { }
public RouteIPBlock(Guid securityId, string address)
{
SecurityId = securityId;
Address = address;
}
public override int GetHashCode()
{
if (!Address.IsNullOrWhiteSpace())
{
return Address.GetHashCode();
}
return base.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null ||
Address.IsNullOrWhiteSpace())
{
return false;
}
if (obj is RouteIPBlock iPBlock)
{
return iPBlock.Address.Equals(Address);
}
return false;
}
}
}

41
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Security/RouteIPWhite.cs

@ -0,0 +1,41 @@
using System;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Security
{
public class RouteIPWhite : Entity<int>
{
public virtual string Address { get; private set; }
public virtual Guid SecurityId { get; private set; }
public virtual RouteSecurity Security { get; private set; }
protected RouteIPWhite() { }
public RouteIPWhite(Guid securityId, string address)
{
SecurityId = securityId;
Address = address;
}
public override int GetHashCode()
{
if (!Address.IsNullOrWhiteSpace())
{
return Address.GetHashCode();
}
return base.GetHashCode();
}
public override bool Equals(object obj)
{
if(obj == null ||
Address.IsNullOrWhiteSpace())
{
return false;
}
if (obj is RouteIPWhite iPWhite)
{
return iPWhite.Address.Equals(Address);
}
return false;
}
}
}

56
aspnet-core/modules/apigateway/LINGYUN.ApiGateWay.Admin.Domain/LINGYUN/ApiGateWay/Admin/Security/RouteSecurity.cs

@ -0,0 +1,56 @@
using LINGYUN.ApiGateWay.Admin.Routes;
using System;
using System.Collections.Generic;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.ApiGateWay.Admin.Security
{
public class RouteSecurity : Entity<Guid>
{
public virtual ICollection<RouteIPWhite> IPAllowedList { get; private set; }
public virtual ICollection<RouteIPBlock> IPBlockedList { get; private set; }
public virtual Guid RouteId { get; private set; }
public virtual Route Route { get; private set; }
protected RouteSecurity()
{
IPAllowedList = new List<RouteIPWhite>();
IPBlockedList = new List<RouteIPBlock>();
}
public RouteSecurity(Guid id, Guid routeId) : this()
{
Id = id;
RouteId = routeId;
}
public void AddIpWhite(string address)
{
IPAllowedList.AddIfNotContains(new RouteIPWhite(Id, address));
}
public void RemoveIpWhite(string address)
{
IPAllowedList.RemoveAll(ip => ip.Address.Equals(address));
}
public void RemoveAllIpWhite()
{
IPAllowedList.Clear();
}
public void AddIpBlock(string address)
{
IPBlockedList.AddIfNotContains(new RouteIPBlock(Id, address));
}
public void RemoveIpBlock(string address)
{
IPBlockedList.RemoveAll(ip => ip.Address.Equals(address));
}
public void RemoveAllIpBlock()
{
IPBlockedList.Clear();
}
}
}

2
aspnet-core/modules/common/LINGYUN.Abp.Settings/Volo/Abp/Settings/ISettingProviderExtensions.cs

@ -24,7 +24,5 @@ namespace Volo.Abp.Settings
} }
return value; return value;
} }
} }
} }

30
aspnet-core/modules/permissions-management/LINGYUN.Abp.PermissionManagement.Domain/LINGYUN/Abp/PermissionManagement/FixClientPermissionValueProvider.cs

@ -0,0 +1,30 @@
using System.Threading.Tasks;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.PermissionManagement
{
// fix: https://github.com/abpframework/abp/issues/6022
// TODO: 在4.0正式版中已修复此问题,升级后需要移除
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(ClientPermissionValueProvider))]
public class FixClientPermissionValueProvider : ClientPermissionValueProvider
{
protected ICurrentTenant CurrentTenant { get; }
public FixClientPermissionValueProvider(
IPermissionStore permissionStore,
ICurrentTenant currentTenant) : base(permissionStore)
{
CurrentTenant = currentTenant;
}
public override async Task<PermissionGrantResult> CheckAsync(PermissionValueCheckContext context)
{
using (CurrentTenant.Change(null))
{
return await base.CheckAsync(context);
}
}
}
}

3
aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/SettingAppService.cs

@ -70,7 +70,8 @@ namespace LINGYUN.Abp.SettingManagement
} }
} }
[Authorize] //[Authorize]
[AllowAnonymous]
public virtual async Task<ListResultDto<SettingGroupDto>> GetAllForCurrentTenantAsync() public virtual async Task<ListResultDto<SettingGroupDto>> GetAllForCurrentTenantAsync()
{ {
return await GetAllForProviderAsync(TenantSettingValueProvider.ProviderName, CurrentTenant.GetId().ToString()); return await GetAllForProviderAsync(TenantSettingValueProvider.ProviderName, CurrentTenant.GetId().ToString());

35
aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -101,6 +102,15 @@ namespace AuthServer.Host
var hostingEnvironment = context.Services.GetHostingEnvironment(); var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration(); var configuration = context.Services.GetConfiguration();
// 请求代理配置
Configure<ForwardedHeadersOptions>(options =>
{
configuration.GetSection("App:Forwarded").Bind(options);
// 对于生产环境,为安全考虑需要在配置中指定受信任代理服务器
options.KnownNetworks.Clear();
options.KnownProxies.Clear();
});
Configure<AbpDbContextOptions>(options => Configure<AbpDbContextOptions>(options =>
{ {
options.UseMySQL(); options.UseMySQL();
@ -183,10 +193,7 @@ namespace AuthServer.Host
options.Audience = configuration["AuthServer:ApiName"]; options.Audience = configuration["AuthServer:ApiName"];
}); });
Configure<AbpMultiTenancyOptions>(options =>
{
options.IsEnabled = true;
});
if (!hostingEnvironment.IsDevelopment()) if (!hostingEnvironment.IsDevelopment())
{ {
@ -196,6 +203,24 @@ namespace AuthServer.Host
.PersistKeysToStackExchangeRedis(redis, "AuthServer-Protection-Keys"); .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 => context.Services.AddCors(options =>
{ {
options.AddPolicy(DefaultCorsPolicyName, builder => options.AddPolicy(DefaultCorsPolicyName, builder =>
@ -221,6 +246,8 @@ namespace AuthServer.Host
var app = context.GetApplicationBuilder(); var app = context.GetApplicationBuilder();
var env = context.GetEnvironment(); var env = context.GetEnvironment();
// 从请求头中解析真实的客户机连接信息
app.UseForwardedHeaders();
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();

31
aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs

@ -1,6 +1,5 @@
using DotNetCore.CAP; using DotNetCore.CAP;
using LINGYUN.Abp.Auditing; using LINGYUN.Abp.Auditing;
using LINGYUN.Abp.BackendAdmin.MultiTenancy;
using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.EventBus.CAP;
using LINGYUN.Abp.ExceptionHandling; using LINGYUN.Abp.ExceptionHandling;
using LINGYUN.Abp.ExceptionHandling.Emailing; using LINGYUN.Abp.ExceptionHandling.Emailing;
@ -25,6 +24,8 @@ using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using StackExchange.Redis; using StackExchange.Redis;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.Authentication.JwtBearer;
@ -121,6 +122,16 @@ namespace LINGYUN.Abp.BackendAdmin
{ {
var hostingEnvironment = context.Services.GetHostingEnvironment(); var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = hostingEnvironment.BuildConfiguration(); var configuration = hostingEnvironment.BuildConfiguration();
// 请求代理配置
Configure<ForwardedHeadersOptions>(options =>
{
configuration.GetSection("App:Forwarded").Bind(options);
// 对于生产环境,为安全考虑需要在配置中指定受信任代理服务器
options.KnownNetworks.Clear();
options.KnownProxies.Clear();
});
// 配置Ef // 配置Ef
Configure<AbpDbContextOptions>(options => Configure<AbpDbContextOptions>(options =>
{ {
@ -207,10 +218,18 @@ namespace LINGYUN.Abp.BackendAdmin
options.IsEnabled = true; options.IsEnabled = true;
}); });
Configure<AbpTenantResolveOptions>(options => var tenantResolveCfg = configuration.GetSection("App:Domains");
if (tenantResolveCfg.Exists())
{ {
options.TenantResolvers.Insert(0, new AuthorizationTenantResolveContributor()); Configure<AbpTenantResolveOptions>(options =>
}); {
var domains = tenantResolveCfg.Get<string[]>();
foreach (var domain in domains)
{
options.AddDomainTenantResolver(domain);
}
});
}
Configure<AbpAuditingOptions>(options => Configure<AbpAuditingOptions>(options =>
{ {
@ -299,6 +318,8 @@ namespace LINGYUN.Abp.BackendAdmin
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)
{ {
var app = context.GetApplicationBuilder(); var app = context.GetApplicationBuilder();
// 代理的中间件应放在其他中间件之前
app.UseForwardedHeaders();
// http调用链 // http调用链
app.UseCorrelationId(); app.UseCorrelationId();
// 虚拟文件系统 // 虚拟文件系统
@ -330,6 +351,8 @@ namespace LINGYUN.Abp.BackendAdmin
if (context.GetEnvironment().IsDevelopment()) if (context.GetEnvironment().IsDevelopment())
{ {
// 开发模式下调试代理连接信息用
app.UseProxyConnectTest();
SeedData(context); SeedData(context);
} }
} }

35
aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/MultiTenancy/AuthorizationTenantResolveContributor.cs

@ -1,35 +0,0 @@
using Microsoft.AspNetCore.Http;
using System.Linq;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Security.Claims;
namespace LINGYUN.Abp.BackendAdmin.MultiTenancy
{
public class AuthorizationTenantResolveContributor : HttpTenantResolveContributorBase
{
public override string Name => "Authorization";
protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext)
{
if (httpContext.User?.Identity == null)
{
return null;
}
if (!httpContext.User.Identity.IsAuthenticated)
{
return null;
}
var tenantIdKey = context.GetAbpAspNetCoreMultiTenancyOptions().TenantKey;
var tenantClaim = httpContext.User.Claims.FirstOrDefault(x => x.Type.Equals(AbpClaimTypes.TenantId));
if (tenantClaim == null)
{
return null;
}
return tenantClaim.Value;
}
}
}

2
aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/Properties/launchSettings.json

@ -11,7 +11,7 @@
"LINGYUN.Abp.BackendAdminApp.Host": { "LINGYUN.Abp.BackendAdminApp.Host": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": false, "launchBrowser": false,
"applicationUrl": "http://localhost:30010", "applicationUrl": "http://0.0.0.0:30010",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

44
aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/Tests/ProxyConnectTestMiddleware.cs

@ -0,0 +1,44 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LINGYUN.Abp.BackendAdmin.Tests
{
public class ProxyConnectTestMiddleware
{
private readonly RequestDelegate _next;
public ProxyConnectTestMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
if (context.Request.Path.StartsWithSegments("/api/connect"))
{
var contentBuilder = new StringBuilder();
contentBuilder.AppendLine("Connection:");
contentBuilder.AppendLine($"Id: {context.Connection.Id}");
contentBuilder.AppendLine($"LocalIpAddress: {context.Connection.LocalIpAddress}:{context.Connection.LocalPort}");
contentBuilder.AppendLine($"RemoteIpAddress: {context.Connection.RemoteIpAddress}:{context.Connection.RemotePort}");
contentBuilder.AppendLine();
contentBuilder.AppendLine("Headers:");
contentBuilder.Append(context.Request.Headers.Select(h => $"Key:{h.Key}, Value:{h.Value}").JoinAsString(Environment.NewLine));
contentBuilder.AppendLine();
contentBuilder.AppendLine();
contentBuilder.AppendLine("Host:");
contentBuilder.AppendLine(context.Request.Host.ToUriComponent());
contentBuilder.AppendLine();
contentBuilder.AppendLine("Scheme:");
contentBuilder.AppendLine(context.Request.Scheme);
await context.Response.WriteAsync(contentBuilder.ToString());
return;
}
await _next(context);
}
}
}

12
aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/Tests/ProxyConnectTestMiddlewareExtensions.cs

@ -0,0 +1,12 @@
using LINGYUN.Abp.BackendAdmin.Tests;
namespace Microsoft.AspNetCore.Builder
{
public static class ProxyConnectTestMiddlewareExtensions
{
public static IApplicationBuilder UseProxyConnectTest(this IApplicationBuilder app)
{
return app.UseMiddleware<ProxyConnectTestMiddleware>();
}
}
}

3
aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs

@ -11,6 +11,7 @@ using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Ocelot.Configuration.Creator;
using Ocelot.Configuration.Repository; using Ocelot.Configuration.Repository;
using Ocelot.DependencyInjection; using Ocelot.DependencyInjection;
using Ocelot.Extenssions; using Ocelot.Extenssions;
@ -187,6 +188,8 @@ namespace LINGYUN.ApiGateway
{ {
var app = context.GetApplicationBuilder(); var app = context.GetApplicationBuilder();
// 网关不需要加代理中间件
app.UseAuditing(); app.UseAuditing();
app.UseVirtualFiles(); app.UseVirtualFiles();
app.UseRouting(); app.UseRouting();

12
aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs

@ -72,6 +72,16 @@ namespace LINGYUN.ApiGateway
{ {
var hostingEnvironment = context.Services.GetHostingEnvironment(); var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = hostingEnvironment.BuildConfiguration(); var configuration = hostingEnvironment.BuildConfiguration();
// 请求代理配置
Configure<ForwardedHeadersOptions>(options =>
{
configuration.GetSection("App:Forwarded").Bind(options);
// 对于生产环境,为安全考虑需要在配置中指定受信任代理服务器
options.KnownNetworks.Clear();
options.KnownProxies.Clear();
});
// 配置Ef // 配置Ef
Configure<AbpDbContextOptions>(options => Configure<AbpDbContextOptions>(options =>
{ {
@ -201,6 +211,8 @@ namespace LINGYUN.ApiGateway
{ {
var app = context.GetApplicationBuilder(); var app = context.GetApplicationBuilder();
var configuration = context.GetConfiguration(); var configuration = context.GetConfiguration();
app.UseForwardedHeaders();
// http调用链 // http调用链
app.UseCorrelationId(); app.UseCorrelationId();
// 虚拟文件系统 // 虚拟文件系统

28
aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs

@ -94,6 +94,16 @@ namespace LINGYUN.Abp.IdentityServer4
{ {
var hostingEnvironment = context.Services.GetHostingEnvironment(); var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = hostingEnvironment.BuildConfiguration(); var configuration = hostingEnvironment.BuildConfiguration();
// 请求代理配置
Configure<ForwardedHeadersOptions>(options =>
{
configuration.GetSection("App:Forwarded").Bind(options);
// 对于生产环境,为安全考虑需要在配置中指定受信任代理服务器
options.KnownNetworks.Clear();
options.KnownProxies.Clear();
});
// 配置Ef // 配置Ef
Configure<AbpDbContextOptions>(options => Configure<AbpDbContextOptions>(options =>
{ {
@ -150,8 +160,6 @@ namespace LINGYUN.Abp.IdentityServer4
{ {
// 是否发送堆栈信息 // 是否发送堆栈信息
options.SendStackTrace = true; options.SendStackTrace = true;
// 未指定异常接收者的默认接收邮件
options.DefaultReceiveEmail = "colin.in@foxmail.com";
}); });
Configure<AbpAuditingOptions>(options => Configure<AbpAuditingOptions>(options =>
@ -201,10 +209,18 @@ namespace LINGYUN.Abp.IdentityServer4
options.IsEnabled = true; options.IsEnabled = true;
}); });
Configure<AbpTenantResolveOptions>(options => var tenantResolveCfg = configuration.GetSection("App:Domains");
if (tenantResolveCfg.Exists())
{ {
options.TenantResolvers.Insert(0, new AuthorizationTenantResolveContributor()); Configure<AbpTenantResolveOptions>(options =>
}); {
var domains = tenantResolveCfg.Get<string[]>();
foreach (var domain in domains)
{
options.AddDomainTenantResolver(domain);
}
});
}
// Swagger // Swagger
context.Services.AddSwaggerGen( context.Services.AddSwaggerGen(
@ -270,6 +286,8 @@ namespace LINGYUN.Abp.IdentityServer4
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)
{ {
var app = context.GetApplicationBuilder(); var app = context.GetApplicationBuilder();
app.UseForwardedHeaders();
// http调用链 // http调用链
app.UseCorrelationId(); app.UseCorrelationId();
// 虚拟文件系统 // 虚拟文件系统

35
aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/MultiTenancy/AuthorizationTenantResolveContributor.cs

@ -1,35 +0,0 @@
using Microsoft.AspNetCore.Http;
using System.Linq;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Security.Claims;
namespace LINGYUN.Abp.IdentityServer4
{
public class AuthorizationTenantResolveContributor : HttpTenantResolveContributorBase
{
public override string Name => "Authorization";
protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext)
{
if (httpContext.User?.Identity == null)
{
return null;
}
if (!httpContext.User.Identity.IsAuthenticated)
{
return null;
}
var tenantIdKey = context.GetAbpAspNetCoreMultiTenancyOptions().TenantKey;
var tenantClaim = httpContext.User.Claims.FirstOrDefault(x => x.Type.Equals(AbpClaimTypes.TenantId));
if (tenantClaim == null)
{
return null;
}
return tenantClaim.Value;
}
}
}

27
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs

@ -10,7 +10,6 @@ using LINGYUN.Abp.IM.SignalR;
using LINGYUN.Abp.MessageService.Authorization; using LINGYUN.Abp.MessageService.Authorization;
using LINGYUN.Abp.MessageService.EntityFrameworkCore; using LINGYUN.Abp.MessageService.EntityFrameworkCore;
using LINGYUN.Abp.MessageService.Localization; using LINGYUN.Abp.MessageService.Localization;
using LINGYUN.Abp.MessageService.MultiTenancy;
using LINGYUN.Abp.MultiTenancy.DbFinder; using LINGYUN.Abp.MultiTenancy.DbFinder;
using LINGYUN.Abp.Notifications.SignalR; using LINGYUN.Abp.Notifications.SignalR;
using LINGYUN.Abp.Notifications.Sms; using LINGYUN.Abp.Notifications.Sms;
@ -95,6 +94,16 @@ namespace LINGYUN.Abp.MessageService
{ {
var hostingEnvironment = context.Services.GetHostingEnvironment(); var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = hostingEnvironment.BuildConfiguration(); var configuration = hostingEnvironment.BuildConfiguration();
// 请求代理配置
Configure<ForwardedHeadersOptions>(options =>
{
configuration.GetSection("App:Forwarded").Bind(options);
// 对于生产环境,为安全考虑需要在配置中指定受信任代理服务器
options.KnownNetworks.Clear();
options.KnownProxies.Clear();
});
// 配置Ef // 配置Ef
Configure<AbpDbContextOptions>(options => Configure<AbpDbContextOptions>(options =>
{ {
@ -141,10 +150,18 @@ namespace LINGYUN.Abp.MessageService
options.IsEnabled = true; options.IsEnabled = true;
}); });
Configure<AbpTenantResolveOptions>(options => var tenantResolveCfg = configuration.GetSection("App:Domains");
if (tenantResolveCfg.Exists())
{ {
options.TenantResolvers.Insert(0, new AuthorizationTenantResolveContributor()); Configure<AbpTenantResolveOptions>(options =>
}); {
var domains = tenantResolveCfg.Get<string[]>();
foreach (var domain in domains)
{
options.AddDomainTenantResolver(domain);
}
});
}
Configure<AbpDistributedCacheOptions>(options => Configure<AbpDistributedCacheOptions>(options =>
{ {
@ -273,6 +290,8 @@ namespace LINGYUN.Abp.MessageService
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)
{ {
var app = context.GetApplicationBuilder(); var app = context.GetApplicationBuilder();
app.UseForwardedHeaders();
// http调用链 // http调用链
app.UseCorrelationId(); app.UseCorrelationId();
// 虚拟文件系统 // 虚拟文件系统

35
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/MultiTenancy/AuthorizationTenantResolveContributor.cs

@ -1,35 +0,0 @@
using Microsoft.AspNetCore.Http;
using System.Linq;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Security.Claims;
namespace LINGYUN.Abp.MessageService.MultiTenancy
{
public class AuthorizationTenantResolveContributor : HttpTenantResolveContributorBase
{
public override string Name => "Authorization";
protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext)
{
if (httpContext.User?.Identity == null)
{
return null;
}
if (!httpContext.User.Identity.IsAuthenticated)
{
return null;
}
var tenantIdKey = context.GetAbpAspNetCoreMultiTenancyOptions().TenantKey;
var tenantClaim = httpContext.User.Claims.FirstOrDefault(x => x.Type.Equals(AbpClaimTypes.TenantId));
if (tenantClaim == null)
{
return null;
}
return tenantClaim.Value;
}
}
}

31
aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs

@ -7,7 +7,6 @@ using LINGYUN.Abp.MultiTenancy.DbFinder;
using LINGYUN.Abp.Notifications; using LINGYUN.Abp.Notifications;
using LINGYUN.Platform.EntityFrameworkCore; using LINGYUN.Platform.EntityFrameworkCore;
using LINGYUN.Platform.HttpApi; using LINGYUN.Platform.HttpApi;
using LINGYUN.Platform.MultiTenancy;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
@ -90,6 +89,16 @@ namespace LINGYUN.Platform
{ {
var hostingEnvironment = context.Services.GetHostingEnvironment(); var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = hostingEnvironment.BuildConfiguration(); var configuration = hostingEnvironment.BuildConfiguration();
// 请求代理配置
Configure<ForwardedHeadersOptions>(options =>
{
configuration.GetSection("App:Forwarded").Bind(options);
// 对于生产环境,为安全考虑需要在配置中指定受信任代理服务器
options.KnownNetworks.Clear();
options.KnownProxies.Clear();
});
// 配置Ef // 配置Ef
Configure<AbpDbContextOptions>(options => Configure<AbpDbContextOptions>(options =>
{ {
@ -179,6 +188,19 @@ namespace LINGYUN.Platform
options.IsEnabled = true; 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);
}
});
}
Configure<AbpAuditingOptions>(options => Configure<AbpAuditingOptions>(options =>
{ {
options.ApplicationName = "Platform"; options.ApplicationName = "Platform";
@ -192,11 +214,6 @@ namespace LINGYUN.Platform
} }
}); });
Configure<AbpTenantResolveOptions>(options =>
{
options.TenantResolvers.Insert(0, new AuthorizationTenantResolveContributor());
});
// Swagger // Swagger
context.Services.AddSwaggerGen( context.Services.AddSwaggerGen(
options => options =>
@ -265,6 +282,8 @@ namespace LINGYUN.Platform
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)
{ {
var app = context.GetApplicationBuilder(); var app = context.GetApplicationBuilder();
app.UseForwardedHeaders();
// http调用链 // http调用链
app.UseCorrelationId(); app.UseCorrelationId();
// 虚拟文件系统 // 虚拟文件系统

35
aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/MultiTenancy/AuthorizationTenantResolveContributor.cs

@ -1,35 +0,0 @@
using Microsoft.AspNetCore.Http;
using System.Linq;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Security.Claims;
namespace LINGYUN.Platform.MultiTenancy
{
public class AuthorizationTenantResolveContributor : HttpTenantResolveContributorBase
{
public override string Name => "Authorization";
protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext)
{
if (httpContext.User?.Identity == null)
{
return null;
}
if (!httpContext.User.Identity.IsAuthenticated)
{
return null;
}
var tenantIdKey = context.GetAbpAspNetCoreMultiTenancyOptions().TenantKey;
var tenantClaim = httpContext.User.Claims.FirstOrDefault(x => x.Type.Equals(AbpClaimTypes.TenantId));
if (tenantClaim == null)
{
return null;
}
return tenantClaim.Value;
}
}
}
Loading…
Cancel
Save