From 83e997aeecd541abebd3c6c51afa526a2d2d0a4e Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Mon, 29 Nov 2021 21:21:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(open-api):=20=E6=B3=A8=E9=87=8A=E7=99=BD?= =?UTF-8?q?=E5=90=8D=E5=8D=95=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OpenApiAuthorizationService.cs | 23 +++++++++-------- .../LINGYUN/Abp/OpenApi/AbpOpenApiModule.cs | 4 ++- .../LINGYUN/Abp/OpenApi/AbpOpenApiOptions.cs | 25 +------------------ .../AbpDefaultAppKeyStoreOptions.cs | 4 +-- .../ConfigurationStore/DefaultAppKeyStore.cs | 2 +- 5 files changed, 19 insertions(+), 39 deletions(-) diff --git a/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi.Authorization/LINGYUN/Abp/OpenApi/Authorization/OpenApiAuthorizationService.cs b/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi.Authorization/LINGYUN/Abp/OpenApi/Authorization/OpenApiAuthorizationService.cs index 7ecfd1930..7ed53477d 100644 --- a/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi.Authorization/LINGYUN/Abp/OpenApi/Authorization/OpenApiAuthorizationService.cs +++ b/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi.Authorization/LINGYUN/Abp/OpenApi/Authorization/OpenApiAuthorizationService.cs @@ -46,17 +46,18 @@ namespace LINGYUN.Abp.OpenApi.Authorization return true; } - if (_currentClient.IsAuthenticated && - _openApiOptions.HasWhiteClient(_currentClient.Id)) - { - return true; - } - - if (!string.IsNullOrWhiteSpace(_clientInfoProvider.ClientIpAddress) && - _openApiOptions.HasWhiteIpAddress(_clientInfoProvider.ClientIpAddress)) - { - return true; - } + // TODO: 不够优雅,应该用接口来实现 + //if (_currentClient.IsAuthenticated && + // _openApiOptions.HasWhiteClient(_currentClient.Id)) + //{ + // return true; + //} + + //if (!string.IsNullOrWhiteSpace(_clientInfoProvider.ClientIpAddress) && + // _openApiOptions.HasWhiteIpAddress(_clientInfoProvider.ClientIpAddress)) + //{ + // return true; + //} BusinessException exception; if (!httpContext.Request.QueryString.HasValue) diff --git a/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/AbpOpenApiModule.cs b/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/AbpOpenApiModule.cs index e3eae6d14..c2d7cadc2 100644 --- a/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/AbpOpenApiModule.cs +++ b/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/AbpOpenApiModule.cs @@ -1,4 +1,5 @@ -using LINGYUN.Abp.OpenApi.Localization; +using LINGYUN.Abp.OpenApi.ConfigurationStore; +using LINGYUN.Abp.OpenApi.Localization; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Localization; using Volo.Abp.Localization.ExceptionHandling; @@ -18,6 +19,7 @@ namespace LINGYUN.Abp.OpenApi var configuration = context.Services.GetConfiguration(); Configure(configuration.GetSection("OpenApi")); + Configure(configuration); Configure(options => { diff --git a/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/AbpOpenApiOptions.cs b/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/AbpOpenApiOptions.cs index bb6c4808b..c1eabfa94 100644 --- a/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/AbpOpenApiOptions.cs +++ b/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/AbpOpenApiOptions.cs @@ -1,34 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace LINGYUN.Abp.OpenApi +namespace LINGYUN.Abp.OpenApi { public class AbpOpenApiOptions { public bool IsEnabled { get; set; } - public string[] WhiteIpAddress { get; set; } - public string[] WhiteClient { get; set; } public AbpOpenApiOptions() { IsEnabled = true; - WhiteIpAddress = new string[0]; - WhiteClient = new string[0]; - } - - public bool HasWhiteIpAddress(string ipAddress) - { - return WhiteIpAddress?.Contains(ipAddress) == true; - } - - public bool HasWhiteClient(string clientId) - { - if (clientId.IsNullOrWhiteSpace()) - { - return false; - } - return WhiteClient?.Contains(clientId) == true; } } } diff --git a/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/ConfigurationStore/AbpDefaultAppKeyStoreOptions.cs b/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/ConfigurationStore/AbpDefaultAppKeyStoreOptions.cs index ac89b6d69..08f3d445f 100644 --- a/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/ConfigurationStore/AbpDefaultAppKeyStoreOptions.cs +++ b/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/ConfigurationStore/AbpDefaultAppKeyStoreOptions.cs @@ -2,11 +2,11 @@ { public class AbpDefaultAppKeyStoreOptions { - public AppDescriptor[] Apps { get; set; } + public AppDescriptor[] AppDescriptors { get; set; } public AbpDefaultAppKeyStoreOptions() { - Apps = new AppDescriptor[0]; + AppDescriptors = new AppDescriptor[0]; } } } diff --git a/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/ConfigurationStore/DefaultAppKeyStore.cs b/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/ConfigurationStore/DefaultAppKeyStore.cs index c3d1d9561..78b7e97c9 100644 --- a/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/ConfigurationStore/DefaultAppKeyStore.cs +++ b/aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/ConfigurationStore/DefaultAppKeyStore.cs @@ -22,7 +22,7 @@ namespace LINGYUN.Abp.OpenApi.ConfigurationStore public AppDescriptor Find(string appKey) { - return _options.Apps?.FirstOrDefault(t => t.AppKey == appKey); + return _options.AppDescriptors?.FirstOrDefault(t => t.AppKey == appKey); } } }