Browse Source

feat(open-api): 注释白名单校验

pull/415/head
cKey 4 years ago
parent
commit
83e997aeec
  1. 23
      aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi.Authorization/LINGYUN/Abp/OpenApi/Authorization/OpenApiAuthorizationService.cs
  2. 4
      aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/AbpOpenApiModule.cs
  3. 25
      aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/AbpOpenApiOptions.cs
  4. 4
      aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/ConfigurationStore/AbpDefaultAppKeyStoreOptions.cs
  5. 2
      aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/ConfigurationStore/DefaultAppKeyStore.cs

23
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; return true;
} }
if (_currentClient.IsAuthenticated && // TODO: 不够优雅,应该用接口来实现
_openApiOptions.HasWhiteClient(_currentClient.Id)) //if (_currentClient.IsAuthenticated &&
{ // _openApiOptions.HasWhiteClient(_currentClient.Id))
return true; //{
} // return true;
//}
if (!string.IsNullOrWhiteSpace(_clientInfoProvider.ClientIpAddress) &&
_openApiOptions.HasWhiteIpAddress(_clientInfoProvider.ClientIpAddress)) //if (!string.IsNullOrWhiteSpace(_clientInfoProvider.ClientIpAddress) &&
{ // _openApiOptions.HasWhiteIpAddress(_clientInfoProvider.ClientIpAddress))
return true; //{
} // return true;
//}
BusinessException exception; BusinessException exception;
if (!httpContext.Request.QueryString.HasValue) if (!httpContext.Request.QueryString.HasValue)

4
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 Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Localization; using Volo.Abp.Localization;
using Volo.Abp.Localization.ExceptionHandling; using Volo.Abp.Localization.ExceptionHandling;
@ -18,6 +19,7 @@ namespace LINGYUN.Abp.OpenApi
var configuration = context.Services.GetConfiguration(); var configuration = context.Services.GetConfiguration();
Configure<AbpOpenApiOptions>(configuration.GetSection("OpenApi")); Configure<AbpOpenApiOptions>(configuration.GetSection("OpenApi"));
Configure<AbpDefaultAppKeyStoreOptions>(configuration);
Configure<AbpVirtualFileSystemOptions>(options => Configure<AbpVirtualFileSystemOptions>(options =>
{ {

25
aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/AbpOpenApiOptions.cs

@ -1,34 +1,11 @@
using System; namespace LINGYUN.Abp.OpenApi
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LINGYUN.Abp.OpenApi
{ {
public class AbpOpenApiOptions public class AbpOpenApiOptions
{ {
public bool IsEnabled { get; set; } public bool IsEnabled { get; set; }
public string[] WhiteIpAddress { get; set; }
public string[] WhiteClient { get; set; }
public AbpOpenApiOptions() public AbpOpenApiOptions()
{ {
IsEnabled = true; 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;
} }
} }
} }

4
aspnet-core/modules/open-api/LINGYUN.Abp.OpenApi/LINGYUN/Abp/OpenApi/ConfigurationStore/AbpDefaultAppKeyStoreOptions.cs

@ -2,11 +2,11 @@
{ {
public class AbpDefaultAppKeyStoreOptions public class AbpDefaultAppKeyStoreOptions
{ {
public AppDescriptor[] Apps { get; set; } public AppDescriptor[] AppDescriptors { get; set; }
public AbpDefaultAppKeyStoreOptions() public AbpDefaultAppKeyStoreOptions()
{ {
Apps = new AppDescriptor[0]; AppDescriptors = new AppDescriptor[0];
} }
} }
} }

2
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) public AppDescriptor Find(string appKey)
{ {
return _options.Apps?.FirstOrDefault(t => t.AppKey == appKey); return _options.AppDescriptors?.FirstOrDefault(t => t.AppKey == appKey);
} }
} }
} }

Loading…
Cancel
Save