mirror of https://github.com/abpframework/abp.git
21 changed files with 264 additions and 21 deletions
@ -0,0 +1,22 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.AspNetCore.Mvc.Client</AssemblyName> |
|||
<PackageId>Volo.Abp.AspNetCore.Mvc.Client</PackageId> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.AspNetCore.Mvc.Contracts\Volo.Abp.AspNetCore.Mvc.Contracts.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.Caching\Volo.Abp.Caching.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.Http.Client\Volo.Abp.Http.Client.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,26 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.Http.Client; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Client |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpHttpClientModule), |
|||
typeof(AbpAspNetCoreMvcContractsModule), |
|||
typeof(AbpCachingModule) |
|||
)] |
|||
public class AbpAspNetCoreMvcClientModule : AbpModule |
|||
{ |
|||
public const string RemoteServiceName = "AbpMvcClient"; |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddHttpClientProxies( |
|||
typeof(AbpAspNetCoreMvcContractsModule).Assembly, |
|||
RemoteServiceName, |
|||
asDefaultServices: false |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
using System; |
|||
using Microsoft.AspNetCore.Http; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.Caching.Distributed; |
|||
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Http.Client.DynamicProxying; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Client |
|||
{ |
|||
public class CachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency |
|||
{ |
|||
public IHttpContextAccessor HttpContextAccessor { get; set; } |
|||
|
|||
protected IHttpClientProxy<IAbpApplicationConfigurationAppService> Proxy { get; } |
|||
protected ICurrentUser CurrentUser { get; } |
|||
protected IDistributedCache<ApplicationConfigurationDto> Cache { get; } |
|||
|
|||
public CachedApplicationConfigurationClient( |
|||
IDistributedCache<ApplicationConfigurationDto> cache, |
|||
IHttpClientProxy<IAbpApplicationConfigurationAppService> proxy, |
|||
ICurrentUser currentUser, |
|||
IHttpContextAccessor httpContextAccessor) |
|||
{ |
|||
Proxy = proxy; |
|||
CurrentUser = currentUser; |
|||
HttpContextAccessor = httpContextAccessor; |
|||
Cache = cache; |
|||
} |
|||
|
|||
public async Task<ApplicationConfigurationDto> GetAsync() |
|||
{ |
|||
var cacheKey = CreateCacheKey(); |
|||
var httpContext = HttpContextAccessor?.HttpContext; |
|||
|
|||
if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration) |
|||
{ |
|||
return configuration; |
|||
} |
|||
|
|||
configuration = await Cache.GetOrAddAsync( |
|||
CreateCacheKey(), |
|||
async () => await Proxy.Service.GetAsync(), |
|||
() => new DistributedCacheEntryOptions |
|||
{ |
|||
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5) |
|||
} |
|||
); |
|||
|
|||
if (httpContext != null) |
|||
{ |
|||
httpContext.Items[cacheKey] = configuration; |
|||
} |
|||
|
|||
return configuration; |
|||
} |
|||
|
|||
protected virtual string CreateCacheKey() |
|||
{ |
|||
return $"ApplicationConfiguration_{CurrentUser.Id?.ToString("N") ?? "Anonymous"}"; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Client |
|||
{ |
|||
public interface ICachedApplicationConfigurationClient |
|||
{ |
|||
Task<ApplicationConfigurationDto> GetAsync(); |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using System.Security.Claims; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Client |
|||
{ |
|||
public class RemotePermissionChecker : IPermissionChecker, ITransientDependency |
|||
{ |
|||
protected ICachedApplicationConfigurationClient ConfigurationClient { get; } |
|||
|
|||
public RemotePermissionChecker(ICachedApplicationConfigurationClient configurationClient) |
|||
{ |
|||
ConfigurationClient = configurationClient; |
|||
} |
|||
|
|||
public async Task<PermissionGrantInfo> CheckAsync(string name) |
|||
{ |
|||
var configuration = await ConfigurationClient.GetAsync(); |
|||
|
|||
return new PermissionGrantInfo( |
|||
name, |
|||
configuration.Auth.GrantedPolicies.ContainsKey(name) |
|||
); |
|||
} |
|||
|
|||
public Task<PermissionGrantInfo> CheckAsync(ClaimsPrincipal claimsPrincipal, string name) |
|||
{ |
|||
return CheckAsync(name); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.AspNetCore.Mvc.Contracts</AssemblyName> |
|||
<PackageId>Volo.Abp.AspNetCore.Mvc.Contracts</PackageId> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.Ddd.Application\Volo.Abp.Ddd.Application.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.Application; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpDddApplicationModule) |
|||
)] |
|||
public class AbpAspNetCoreMvcContractsModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,7 +1,9 @@ |
|||
using System.Collections.Generic; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations |
|||
{ |
|||
[Serializable] |
|||
public class ApplicationAuthConfigurationDto |
|||
{ |
|||
public Dictionary<string, bool> Policies { get; set; } |
|||
@ -1,9 +1,14 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations |
|||
using System; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations |
|||
{ |
|||
[Serializable] |
|||
public class ApplicationConfigurationDto |
|||
{ |
|||
public ApplicationLocalizationConfigurationDto Localization { get; set; } |
|||
|
|||
public ApplicationAuthConfigurationDto Auth { get; set; } |
|||
|
|||
public CurrentUserDto CurrentUser { get; set; } |
|||
} |
|||
} |
|||
@ -1,7 +1,9 @@ |
|||
using System.Collections.Generic; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations |
|||
{ |
|||
[Serializable] |
|||
public class ApplicationLocalizationConfigurationDto |
|||
{ |
|||
public Dictionary<string, Dictionary<string, string>> Values { get; set; } |
|||
@ -0,0 +1,16 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations |
|||
{ |
|||
[Serializable] |
|||
public class CurrentUserDto |
|||
{ |
|||
public bool IsAuthenticated { get; set; } |
|||
|
|||
public Guid? Id { get; set; } |
|||
|
|||
public Guid? TenantId { get; set; } |
|||
|
|||
public string UserName { get; set; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue