From f9594e10164a8f0dcc5ca14e7da07a8296e2d1be Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Fri, 14 May 2021 18:06:29 +0800 Subject: [PATCH] upgrade cap to 5.0.2 --- aspnet-core/LINGYUN.MicroService.All.sln | 7 ++ .../LINGYUN.MicroService.ApiGateway.sln | 7 ++ aspnet-core/LINGYUN.MicroService.Common.sln | 7 ++ .../appsettings.Development.json | 2 +- .../appsettings.Development.json | 2 +- .../appsettings.Development.json | 2 +- .../appsettings.Development.json | 2 +- .../appsettings.Development.json | 2 +- .../appsettings.Development.json | 2 +- .../appsettings.Development.json | 2 +- .../appsettings.Development.json | 2 +- ...INGYUN.Abp.AspNetCore.HttpOverrides.csproj | 14 ++++ .../AbpAspNetCoreHttpOverridesModule.cs | 25 +++++++ .../Forwarded/AbpForwardedHeadersOptions.cs | 36 ++++++++++ ...estForwardedHeaderWebClientInfoProvider.cs | 43 ++++++++++++ .../ForwardedHeadersOptionsExtensions.cs | 67 +++++++++++++++++++ .../README.md | 32 +++++++++ .../LINGYUN.Abp.EventBus.CAP.xml | 2 +- .../CAP/CustomDistributedEventSubscriber.cs | 2 +- .../AuthServer.Host/AuthServer.Host.csproj | 10 +-- ...NGYUN.Abp.BackendAdmin.HttpApi.Host.csproj | 10 +-- .../ApiGatewayHostModule.cs | 11 ++- .../LINGYUN.ApiGateway.Host.csproj | 11 +-- .../Properties/launchSettings.json | 9 +-- .../LINGYUN.ApiGateway.HttpApi.Host.csproj | 6 +- ...UN.Abp.IdentityServer4.HttpApi.Host.csproj | 10 +-- ...LocalizationManagement.HttpApi.Host.csproj | 10 +-- ...YUN.Abp.MessageService.HttpApi.Host.csproj | 10 +-- .../LINGYUN.Platform.HttpApi.Host.csproj | 10 +-- 29 files changed, 293 insertions(+), 62 deletions(-) create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN.Abp.AspNetCore.HttpOverrides.csproj create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/HttpOverrides/AbpAspNetCoreHttpOverridesModule.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/HttpOverrides/Forwarded/AbpForwardedHeadersOptions.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/WebClientInfo/RequestForwardedHeaderWebClientInfoProvider.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/Microsoft/AspNetCore/Builder/ForwardedHeadersOptionsExtensions.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/README.md diff --git a/aspnet-core/LINGYUN.MicroService.All.sln b/aspnet-core/LINGYUN.MicroService.All.sln index d690d53c1..663fd24cf 100644 --- a/aspnet-core/LINGYUN.MicroService.All.sln +++ b/aspnet-core/LINGYUN.MicroService.All.sln @@ -329,6 +329,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Rules.RulesEngi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Rules.RulesEngine.Tests", "tests\LINGYUN.Abp.Rules.RulesEngine.Tests\LINGYUN.Abp.Rules.RulesEngine.Tests.csproj", "{8EF31071-3521-409D-9740-BBFBFC04C50E}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.AspNetCore.HttpOverrides", "modules\common\LINGYUN.Abp.AspNetCore.HttpOverrides\LINGYUN.Abp.AspNetCore.HttpOverrides.csproj", "{13219C1C-23E1-4EBA-93FB-86830C93A800}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -859,6 +861,10 @@ Global {8EF31071-3521-409D-9740-BBFBFC04C50E}.Debug|Any CPU.Build.0 = Debug|Any CPU {8EF31071-3521-409D-9740-BBFBFC04C50E}.Release|Any CPU.ActiveCfg = Release|Any CPU {8EF31071-3521-409D-9740-BBFBFC04C50E}.Release|Any CPU.Build.0 = Release|Any CPU + {13219C1C-23E1-4EBA-93FB-86830C93A800}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {13219C1C-23E1-4EBA-93FB-86830C93A800}.Debug|Any CPU.Build.0 = Debug|Any CPU + {13219C1C-23E1-4EBA-93FB-86830C93A800}.Release|Any CPU.ActiveCfg = Release|Any CPU + {13219C1C-23E1-4EBA-93FB-86830C93A800}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1021,6 +1027,7 @@ Global {34BB9810-2983-4E55-A96A-132D32310145} = {6084D52D-775B-4A39-8CD5-AA2F362B5A61} {4D83BDA7-2059-41C7-85AE-FEFAD5CD9498} = {6084D52D-775B-4A39-8CD5-AA2F362B5A61} {8EF31071-3521-409D-9740-BBFBFC04C50E} = {370D7CD5-1E17-4F3D-BBFA-03429F6D4F2F} + {13219C1C-23E1-4EBA-93FB-86830C93A800} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718} diff --git a/aspnet-core/LINGYUN.MicroService.ApiGateway.sln b/aspnet-core/LINGYUN.MicroService.ApiGateway.sln index 68b066655..58554c708 100644 --- a/aspnet-core/LINGYUN.MicroService.ApiGateway.sln +++ b/aspnet-core/LINGYUN.MicroService.ApiGateway.sln @@ -31,6 +31,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{D6629D 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}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.AspNetCore.HttpOverrides", "modules\common\LINGYUN.Abp.AspNetCore.HttpOverrides\LINGYUN.Abp.AspNetCore.HttpOverrides.csproj", "{7588F35B-7C0E-4D80-B43A-8A5C9AC6FE03}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -77,6 +79,10 @@ Global {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.Build.0 = Release|Any CPU + {7588F35B-7C0E-4D80-B43A-8A5C9AC6FE03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7588F35B-7C0E-4D80-B43A-8A5C9AC6FE03}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7588F35B-7C0E-4D80-B43A-8A5C9AC6FE03}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7588F35B-7C0E-4D80-B43A-8A5C9AC6FE03}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -94,6 +100,7 @@ Global {4757C7D9-6AE9-477D-9829-55D9906AC3E6} = {AD93DD04-989C-40BE-A3F4-25DABF290423} {D6629DD3-BA0F-44B5-A97F-3B992ECAB85D} = {630FB448-8C5C-438F-930D-B0209407DE6A} {1DA1835B-9EA4-4095-A8CF-10E2778206D3} = {D6629DD3-BA0F-44B5-A97F-3B992ECAB85D} + {7588F35B-7C0E-4D80-B43A-8A5C9AC6FE03} = {D6629DD3-BA0F-44B5-A97F-3B992ECAB85D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B327C65A-BD15-480D-825E-9D5A870C521A} diff --git a/aspnet-core/LINGYUN.MicroService.Common.sln b/aspnet-core/LINGYUN.MicroService.Common.sln index e48c2a542..9d0c8bc23 100644 --- a/aspnet-core/LINGYUN.MicroService.Common.sln +++ b/aspnet-core/LINGYUN.MicroService.Common.sln @@ -156,6 +156,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr.AspNetCore EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr.Actors.Tests", "tests\LINGYUN.Abp.Dapr.Actors.Tests\LINGYUN.Abp.Dapr.Actors.Tests.csproj", "{CF30221B-CA7A-42CD-B91A-B7224AB2F38B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.AspNetCore.HttpOverrides", "modules\common\LINGYUN.Abp.AspNetCore.HttpOverrides\LINGYUN.Abp.AspNetCore.HttpOverrides.csproj", "{191BB108-546E-4E70-978E-D6A8149C319C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -406,6 +408,10 @@ Global {CF30221B-CA7A-42CD-B91A-B7224AB2F38B}.Debug|Any CPU.Build.0 = Debug|Any CPU {CF30221B-CA7A-42CD-B91A-B7224AB2F38B}.Release|Any CPU.ActiveCfg = Release|Any CPU {CF30221B-CA7A-42CD-B91A-B7224AB2F38B}.Release|Any CPU.Build.0 = Release|Any CPU + {191BB108-546E-4E70-978E-D6A8149C319C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {191BB108-546E-4E70-978E-D6A8149C319C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {191BB108-546E-4E70-978E-D6A8149C319C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {191BB108-546E-4E70-978E-D6A8149C319C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -484,6 +490,7 @@ Global {26E87199-F0AD-4B30-B0E4-080B12E6F8FC} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} {8968EDAF-9F5C-4786-AF2A-D3928B70C3EC} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} {CF30221B-CA7A-42CD-B91A-B7224AB2F38B} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} + {191BB108-546E-4E70-978E-D6A8149C319C} = {086BE5BE-8594-4DA7-8819-935FEF76DABD} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {06C707C6-02C0-411A-AD3B-2D0E13787CB8} diff --git a/aspnet-core/configuration/account/AuthServer.Host/appsettings.Development.json b/aspnet-core/configuration/account/AuthServer.Host/appsettings.Development.json index 22d298107..588a27b2f 100644 --- a/aspnet-core/configuration/account/AuthServer.Host/appsettings.Development.json +++ b/aspnet-core/configuration/account/AuthServer.Host/appsettings.Development.json @@ -41,7 +41,7 @@ }, "CAP": { "EventBus": { - "DefaultGroup": "AuthServer", + "DefaultGroupName": "AuthServer", "Version": "v1", "FailedRetryInterval": 300, "FailedRetryCount": 10 diff --git a/aspnet-core/configuration/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/appsettings.Development.json b/aspnet-core/configuration/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/appsettings.Development.json index db45a7628..01bde2715 100644 --- a/aspnet-core/configuration/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/appsettings.Development.json +++ b/aspnet-core/configuration/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/appsettings.Development.json @@ -34,7 +34,7 @@ }, "CAP": { "EventBus": { - "DefaultGroup": "BackendAdmin", + "DefaultGroupName": "BackendAdmin", "Version": "v1", "FailedRetryInterval": 300, "FailedRetryCount": 10 diff --git a/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.Host/appsettings.Development.json b/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.Host/appsettings.Development.json index 2c0b4a5a2..d18530077 100644 --- a/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.Host/appsettings.Development.json +++ b/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.Host/appsettings.Development.json @@ -26,7 +26,7 @@ "EnabledDynamicOcelot": true, "CAP": { "EventBus": { - "DefaultGroup": "ApiGateway-Host", + "DefaultGroupName": "ApiGateway-Host", "Version": "v1", "FailedRetryInterval": 300, "FailedRetryCount": 10 diff --git a/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json b/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json index c7cadad11..191043b53 100644 --- a/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json +++ b/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json @@ -23,7 +23,7 @@ }, "CAP": { "EventBus": { - "DefaultGroup": "ApiGateway-Admin", + "DefaultGroupName": "ApiGateway-Admin", "Version": "v1", "FailedRetryInterval": 300, "FailedRetryCount": 10 diff --git a/aspnet-core/configuration/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/appsettings.Development.json b/aspnet-core/configuration/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/appsettings.Development.json index e75d71789..fe4c331bc 100644 --- a/aspnet-core/configuration/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/appsettings.Development.json +++ b/aspnet-core/configuration/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/appsettings.Development.json @@ -20,7 +20,7 @@ }, "CAP": { "EventBus": { - "DefaultGroup": "IdentityServer4Admin", + "DefaultGroupName": "IdentityServer4Admin", "Version": "v1", "FailedRetryInterval": 300, "FailedRetryCount": 10 diff --git a/aspnet-core/configuration/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/appsettings.Development.json b/aspnet-core/configuration/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/appsettings.Development.json index 710cb4dad..c24ab87b6 100644 --- a/aspnet-core/configuration/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/appsettings.Development.json +++ b/aspnet-core/configuration/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/appsettings.Development.json @@ -8,7 +8,7 @@ }, "CAP": { "EventBus": { - "DefaultGroup": "Platform", + "DefaultGroupName": "Platform", "Version": "v1", "FailedRetryInterval": 300, "FailedRetryCount": 10 diff --git a/aspnet-core/configuration/messages/LINGYUN.Abp.MessageService.HttpApi.Host/appsettings.Development.json b/aspnet-core/configuration/messages/LINGYUN.Abp.MessageService.HttpApi.Host/appsettings.Development.json index a1902937e..cff16ce44 100644 --- a/aspnet-core/configuration/messages/LINGYUN.Abp.MessageService.HttpApi.Host/appsettings.Development.json +++ b/aspnet-core/configuration/messages/LINGYUN.Abp.MessageService.HttpApi.Host/appsettings.Development.json @@ -45,7 +45,7 @@ }, "CAP": { "EventBus": { - "DefaultGroup": "MessageService", + "DefaultGroupName": "MessageService", "Version": "v1", "FailedRetryInterval": 300, "FailedRetryCount": 10 diff --git a/aspnet-core/configuration/platform/LINGYUN.Platform.HttpApi.Host/appsettings.Development.json b/aspnet-core/configuration/platform/LINGYUN.Platform.HttpApi.Host/appsettings.Development.json index ec97b1f09..5a75e60f6 100644 --- a/aspnet-core/configuration/platform/LINGYUN.Platform.HttpApi.Host/appsettings.Development.json +++ b/aspnet-core/configuration/platform/LINGYUN.Platform.HttpApi.Host/appsettings.Development.json @@ -26,7 +26,7 @@ }, "CAP": { "EventBus": { - "DefaultGroup": "Platform", + "DefaultGroupName": "Platform", "Version": "v1", "FailedRetryInterval": 300, "FailedRetryCount": 10 diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN.Abp.AspNetCore.HttpOverrides.csproj b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN.Abp.AspNetCore.HttpOverrides.csproj new file mode 100644 index 000000000..476c43c66 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN.Abp.AspNetCore.HttpOverrides.csproj @@ -0,0 +1,14 @@ + + + + + + net5.0 + + + + + + + + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/HttpOverrides/AbpAspNetCoreHttpOverridesModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/HttpOverrides/AbpAspNetCoreHttpOverridesModule.cs new file mode 100644 index 000000000..7abc97eb2 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/HttpOverrides/AbpAspNetCoreHttpOverridesModule.cs @@ -0,0 +1,25 @@ +using LINGYUN.Abp.AspNetCore.HttpOverrides.Forwarded; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.AspNetCore.HttpOverrides +{ + public class AbpAspNetCoreHttpOverridesModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + + var forwardOptions = new AbpForwardedHeadersOptions(); + configuration.GetSection("Forwarded:Headers").Bind(forwardOptions); + context.Services.ExecutePreConfiguredActions(forwardOptions); + + Configure(options => + { + options.Configure(forwardOptions); + }); + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/HttpOverrides/Forwarded/AbpForwardedHeadersOptions.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/HttpOverrides/Forwarded/AbpForwardedHeadersOptions.cs new file mode 100644 index 000000000..f56e1c62c --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/HttpOverrides/Forwarded/AbpForwardedHeadersOptions.cs @@ -0,0 +1,36 @@ +using Microsoft.AspNetCore.HttpOverrides; +using System.Collections.Generic; + +namespace LINGYUN.Abp.AspNetCore.HttpOverrides.Forwarded +{ + public class AbpForwardedHeadersOptions + { + public string ForwardedForHeaderName { get; set; } + public string ForwardedHostHeaderName { get; set; } + public string ForwardedProtoHeaderName { get; set; } + public string OriginalForHeaderName { get; set; } + public string OriginalHostHeaderName { get; set; } + public string OriginalProtoHeaderName { get; set; } + public ForwardedHeaders ForwardedHeaders { get; set; } + public int? ForwardLimit { get; set; } + public bool RequireHeaderSymmetry { get; set; } + public List AllowedHosts { get; set; } + public List KnownNetworks { get; set; } + public List KnownProxies { get; set; } + public AbpForwardedHeadersOptions() + { + ForwardedForHeaderName = ForwardedHeadersDefaults.XForwardedForHeaderName; + ForwardedHostHeaderName = ForwardedHeadersDefaults.XForwardedHostHeaderName; + ForwardedProtoHeaderName = ForwardedHeadersDefaults.XForwardedProtoHeaderName; + OriginalForHeaderName = ForwardedHeadersDefaults.XOriginalForHeaderName; + OriginalHostHeaderName = ForwardedHeadersDefaults.XOriginalHostHeaderName; + OriginalProtoHeaderName = ForwardedHeadersDefaults.XOriginalProtoHeaderName; + ForwardedHeaders = ForwardedHeaders.None; + ForwardLimit = 1; + RequireHeaderSymmetry = false; + AllowedHosts = new List(); + KnownProxies = new List(); + KnownNetworks = new List(); + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/WebClientInfo/RequestForwardedHeaderWebClientInfoProvider.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/WebClientInfo/RequestForwardedHeaderWebClientInfoProvider.cs new file mode 100644 index 000000000..9c2ae872b --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/LINGYUN/Abp/AspNetCore/WebClientInfo/RequestForwardedHeaderWebClientInfoProvider.cs @@ -0,0 +1,43 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Microsoft.Extensions.Primitives; +using System.Linq; +using Volo.Abp.AspNetCore.WebClientInfo; +using Volo.Abp.DependencyInjection; + +namespace LINGYUN.Abp.AspNetCore.WebClientInfo +{ + [Dependency(ServiceLifetime.Transient, ReplaceServices = true)] + [ExposeServices( + typeof(IWebClientInfoProvider), + typeof(HttpContextWebClientInfoProvider))] + public class RequestForwardedHeaderWebClientInfoProvider : HttpContextWebClientInfoProvider + { + protected ForwardedHeadersOptions Options { get; } + public RequestForwardedHeaderWebClientInfoProvider( + ILogger logger, + IOptions options, + IHttpContextAccessor httpContextAccessor) + : base(logger, httpContextAccessor) + { + Options = options.Value; + } + + protected override string GetClientIpAddress() + { + IHeaderDictionary requestHeaders = HttpContextAccessor.HttpContext?.Request?.Headers; + if (requestHeaders != null && + requestHeaders.TryGetValue(Options.ForwardedForHeaderName, out StringValues headers) == true) + { + if (StringValues.IsNullOrEmpty(headers)) + { + return headers.Last(); + } + } + return base.GetClientIpAddress(); + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/Microsoft/AspNetCore/Builder/ForwardedHeadersOptionsExtensions.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/Microsoft/AspNetCore/Builder/ForwardedHeadersOptionsExtensions.cs new file mode 100644 index 000000000..5054ed433 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/Microsoft/AspNetCore/Builder/ForwardedHeadersOptionsExtensions.cs @@ -0,0 +1,67 @@ +using LINGYUN.Abp.AspNetCore.HttpOverrides.Forwarded; +using Microsoft.AspNetCore.HttpOverrides; +using System.Collections.Generic; +using System.Linq; +using System.Net; + +namespace Microsoft.AspNetCore.Builder +{ + public static class ForwardedHeadersOptionsExtensions + { + public static void Configure( + this ForwardedHeadersOptions options, + AbpForwardedHeadersOptions abpOptions) + { + options.ForwardedForHeaderName = abpOptions.ForwardedForHeaderName; + options.ForwardedHeaders = abpOptions.ForwardedHeaders; + options.ForwardedHostHeaderName = abpOptions.ForwardedHostHeaderName; + options.ForwardedProtoHeaderName = abpOptions.ForwardedProtoHeaderName; + options.ForwardLimit = abpOptions.ForwardLimit; + options.OriginalForHeaderName = abpOptions.OriginalForHeaderName; + options.OriginalHostHeaderName = abpOptions.OriginalHostHeaderName; + options.OriginalProtoHeaderName = abpOptions.OriginalProtoHeaderName; + options.RequireHeaderSymmetry = abpOptions.RequireHeaderSymmetry; + + if (abpOptions.AllowedHosts.Any()) + { + options.AllowedHosts = abpOptions.AllowedHosts; + } + + AddProxies(options.KnownProxies, abpOptions.KnownProxies); + + if (abpOptions.KnownNetworks.Any()) + { + options.KnownNetworks.Clear(); + foreach (var proxy in abpOptions.KnownNetworks) + { + // 192.168.1.0/24 + var spiltProxies = proxy.Split("/"); + if (spiltProxies.Length != 2) + { + continue; + } + if (int.TryParse(spiltProxies[1], out int prefixLength) && + IPAddress.TryParse(spiltProxies[0], out IPAddress prefixIpAddress)) + { + options.KnownNetworks.Add(new IPNetwork(prefixIpAddress, prefixLength)); + } + } + } + } + + private static void AddProxies(IList addresses, IList proxiesAddress) + { + if (proxiesAddress.Any()) + { + addresses.Clear(); + foreach (var proxy in proxiesAddress) + { + if (IPAddress.TryParse(proxy, out IPAddress iPAddress)) + { + addresses.Add(iPAddress); + } + } + } + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/README.md b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/README.md new file mode 100644 index 000000000..2a75f966f --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.HttpOverrides/README.md @@ -0,0 +1,32 @@ +# LINGYUN.Abp.AspNetCore.HttpOverrides + +## 模块说明 + +对于Http传输标头的一些重写类模块 + +目前实现通过解析 **X-Forwarded-For** 标头获取反向代理中的真实客户地址,通常获取标头中的最后一个设置值 + +### 基础模块 + +### 高阶模块 + +### 权限定义 + +### 功能定义 + +### 配置定义 + +### 如何使用 + + +```csharp + + [DependsOn( + typeof(AbpAspNetCoreHttpOverridesModule))] + public class YouProjectModule : AbpModule + { + } + +``` + +### 更新日志 diff --git a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml index 7b5589b2f..307792fbf 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml +++ b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml @@ -188,7 +188,7 @@ CAP消息扩展 - + 尝试获取消息标头中的租户标识 diff --git a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/CustomDistributedEventSubscriber.cs b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/CustomDistributedEventSubscriber.cs index b3f91337e..0831026d4 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/CustomDistributedEventSubscriber.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/CustomDistributedEventSubscriber.cs @@ -107,7 +107,7 @@ namespace LINGYUN.Abp.EventBus.CAP { if (attribute.Group == null) { - attribute.Group = CapOptions.DefaultGroup + "." + CapOptions.Version; + attribute.Group = CapOptions.DefaultGroupName + "." + CapOptions.Version; } else { diff --git a/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj b/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj index 4e1e0f18c..b724a7646 100644 --- a/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj +++ b/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj @@ -22,17 +22,17 @@ - - - + + + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/LINGYUN.Abp.BackendAdmin.HttpApi.Host.csproj b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/LINGYUN.Abp.BackendAdmin.HttpApi.Host.csproj index 73b8c522d..21d525180 100644 --- a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/LINGYUN.Abp.BackendAdmin.HttpApi.Host.csproj +++ b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/LINGYUN.Abp.BackendAdmin.HttpApi.Host.csproj @@ -23,14 +23,14 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs index dd0a6cdf5..78e2fda64 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs @@ -1,4 +1,5 @@ using DotNetCore.CAP; +using LINGYUN.Abp.AspNetCore.HttpOverrides; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.ApiGateway.Localization; using Microsoft.AspNetCore.Authentication.JwtBearer; @@ -19,8 +20,6 @@ using Ocelot.Provider.Polly; using StackExchange.Redis; using System; using System.Text; -using System.Text.Encodings.Web; -using System.Text.Unicode; using Volo.Abp; using Volo.Abp.AspNetCore; using Volo.Abp.Autofac; @@ -29,7 +28,6 @@ using Volo.Abp.Caching; using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.Http.Client.IdentityModel; using Volo.Abp.Json; -using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.Security.Encryption; @@ -44,7 +42,8 @@ namespace LINGYUN.ApiGateway typeof(AbpAutoMapperModule), typeof(ApiGatewayHttpApiClientModule), typeof(AbpCAPEventBusModule), - typeof(AbpAspNetCoreModule) + typeof(AbpAspNetCoreModule), + typeof(AbpAspNetCoreHttpOverridesModule) )] public class ApiGatewayHostModule : AbpModule { @@ -195,8 +194,7 @@ namespace LINGYUN.ApiGateway { var app = context.GetApplicationBuilder(); - // 网关不需要加代理中间件 - + app.UseForwardedHeaders(); app.UseAuditing(); app.UseStaticFiles(); app.UseRouting(); @@ -210,6 +208,7 @@ namespace LINGYUN.ApiGateway appNext.UseRouting(); appNext.UseConfiguredEndpoints(); }); + // 启用ws协议 app.UseWebSockets(); app.UseOcelot().Wait(); diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/LINGYUN.ApiGateway.Host.csproj b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/LINGYUN.ApiGateway.Host.csproj index 06cdd77f3..7bbc4a72a 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/LINGYUN.ApiGateway.Host.csproj +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/LINGYUN.ApiGateway.Host.csproj @@ -1,4 +1,4 @@ - + net5.0 @@ -11,10 +11,10 @@ - - - - + + + + @@ -33,6 +33,7 @@ + diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/Properties/launchSettings.json b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/Properties/launchSettings.json index c84540f20..06d77d8df 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/Properties/launchSettings.json +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/Properties/launchSettings.json @@ -13,14 +13,7 @@ "launchBrowser": false, "applicationUrl": "http://localhost:30000;https://localhost:30443", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Production" } } } diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj index 616b90739..5573e12c1 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj @@ -11,9 +11,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj b/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj index 1dae1a1b3..2cc3770cb 100644 --- a/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj +++ b/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj @@ -21,14 +21,14 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/LINGYUN.Abp.LocalizationManagement.HttpApi.Host.csproj b/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/LINGYUN.Abp.LocalizationManagement.HttpApi.Host.csproj index 265610cce..1009ba6f1 100644 --- a/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/LINGYUN.Abp.LocalizationManagement.HttpApi.Host.csproj +++ b/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/LINGYUN.Abp.LocalizationManagement.HttpApi.Host.csproj @@ -6,14 +6,14 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj index b7725a091..121beff37 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj @@ -16,14 +16,14 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj index af816bbff..a7944df88 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj @@ -20,14 +20,14 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - +