Docking with third-party OAuth services for ease of rewriting CurrentUser

pull/952/head
ddrsql 6 years ago
parent 5e8efee1e9
commit ca1f2e9e8e

@ -1,23 +1,25 @@
using System.Threading.Tasks;
using Volo.Abp.Security.Claims;
using Volo.Abp.Clients;
namespace Volo.Abp.Authorization.Permissions
{
public class ClientPermissionValueProvider : PermissionValueProvider
{
protected ICurrentClient CurrentClient { get; }
public const string ProviderName = "Client";
public override string Name => ProviderName;
public ClientPermissionValueProvider(IPermissionStore permissionStore)
public ClientPermissionValueProvider(ICurrentClient currentClient, IPermissionStore permissionStore)
: base(permissionStore)
{
CurrentClient = currentClient;
}
public override async Task<PermissionGrantResult> CheckAsync(PermissionValueCheckContext context)
{
var clientId = context.Principal?.FindFirst(AbpClaimTypes.ClientId)?.Value;
var clientId = CurrentClient.Id;
if (clientId == null)
{

@ -1,24 +1,28 @@
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Security.Claims;
using Volo.Abp.Users;
namespace Volo.Abp.Authorization.Permissions
{
public class RolePermissionValueProvider : PermissionValueProvider
{
protected ICurrentUser CurrentUser { get; }
public const string ProviderName = "Role";
public override string Name => ProviderName;
public RolePermissionValueProvider(IPermissionStore permissionStore)
public RolePermissionValueProvider(ICurrentUser currentUser, IPermissionStore permissionStore)
: base(permissionStore)
{
CurrentUser = currentUser;
}
public override async Task<PermissionGrantResult> CheckAsync(PermissionValueCheckContext context)
{
var roles = context.Principal?.FindAll(AbpClaimTypes.Role).Select(c => c.Value).ToArray();
var roles = CurrentUser.Roles;
if (roles == null || !roles.Any())
{
return PermissionGrantResult.Undefined;

@ -1,23 +1,26 @@
using System.Threading.Tasks;
using Volo.Abp.Security.Claims;
using Volo.Abp.Users;
namespace Volo.Abp.Authorization.Permissions
{
public class UserPermissionValueProvider : PermissionValueProvider
{
protected ICurrentUser CurrentUser { get; }
public const string ProviderName = "User";
public override string Name => ProviderName;
public UserPermissionValueProvider(IPermissionStore permissionStore)
public UserPermissionValueProvider(ICurrentUser currentUser, IPermissionStore permissionStore)
: base(permissionStore)
{
CurrentUser = currentUser;
}
public override async Task<PermissionGrantResult> CheckAsync(PermissionValueCheckContext context)
{
var userId = context.Principal?.FindFirst(AbpClaimTypes.UserId)?.Value;
var userId = CurrentUser.Id.ToString();
if (userId == null)
{

@ -1,6 +1,5 @@
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Security.Claims;
using Volo.Abp.Users;
namespace Volo.Abp.MultiTenancy
{
@ -12,17 +11,14 @@ namespace Volo.Abp.MultiTenancy
public override void Resolve(ITenantResolveContext context)
{
var principal = context.ServiceProvider.GetRequiredService<ICurrentPrincipalAccessor>().Principal;
if (principal?.Identity?.IsAuthenticated != true)
var currentUser = context.ServiceProvider.GetRequiredService<ICurrentUser>();
if (currentUser.IsAuthenticated != true)
{
return;
}
context.Handled = true;
context.TenantIdOrName = principal
.Claims
.FirstOrDefault(c => c.Type == AbpClaimTypes.TenantId)
?.Value;
context.TenantIdOrName = currentUser.TenantId.ToString();
}
}
}
Loading…
Cancel
Save