mirror of https://github.com/abpframework/abp.git
committed by
GitHub
52 changed files with 1773 additions and 83 deletions
@ -0,0 +1,43 @@ |
|||||
|
using System; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Auditing |
||||
|
{ |
||||
|
[Dependency(ReplaceServices = true)] |
||||
|
public class AspNetCoreCorrelationIdProvider : ICorrelationIdProvider, ITransientDependency |
||||
|
{ |
||||
|
public const string CorrelationIdKey = "_CorrelationId"; |
||||
|
|
||||
|
protected IHttpContextAccessor HttpContextAccessor { get; } |
||||
|
|
||||
|
public AspNetCoreCorrelationIdProvider(IHttpContextAccessor httpContextAccessor) |
||||
|
{ |
||||
|
HttpContextAccessor = httpContextAccessor; |
||||
|
} |
||||
|
|
||||
|
public virtual string Get() |
||||
|
{ |
||||
|
if (HttpContextAccessor.HttpContext?.Request?.Headers == null) |
||||
|
{ |
||||
|
return CreateNewCorrelationId(); |
||||
|
} |
||||
|
|
||||
|
string correlationId = HttpContextAccessor.HttpContext.Request.Headers[CorrelationIdKey]; |
||||
|
|
||||
|
if (correlationId.IsNullOrEmpty()) |
||||
|
{ |
||||
|
correlationId = CreateNewCorrelationId(); |
||||
|
HttpContextAccessor.HttpContext.Request.Headers[CorrelationIdKey] = correlationId; |
||||
|
} |
||||
|
|
||||
|
return correlationId; |
||||
|
} |
||||
|
|
||||
|
protected virtual string CreateNewCorrelationId() |
||||
|
{ |
||||
|
return Guid.NewGuid().ToString("N"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
namespace Volo.Abp.Auditing |
||||
|
{ |
||||
|
public interface ICorrelationIdProvider |
||||
|
{ |
||||
|
string Get(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.Auditing |
||||
|
{ |
||||
|
public class NullCorrelationIdProvider : ICorrelationIdProvider, ISingletonDependency |
||||
|
{ |
||||
|
public string Get() |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Security.Claims; |
||||
|
|
||||
|
namespace Volo.Abp.Authorization.Permissions |
||||
|
{ |
||||
|
public class ClientPermissionValueProvider : PermissionValueProvider |
||||
|
{ |
||||
|
public const string ProviderName = "Client"; |
||||
|
|
||||
|
public override string Name => ProviderName; |
||||
|
|
||||
|
public ClientPermissionValueProvider(IPermissionStore permissionStore) |
||||
|
: base(permissionStore) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public override async Task<PermissionValueProviderGrantInfo> CheckAsync(PermissionValueCheckContext context) |
||||
|
{ |
||||
|
var clientId = context.Principal?.FindFirst(AbpClaimTypes.ClientId)?.Value; |
||||
|
|
||||
|
if (clientId == null) |
||||
|
{ |
||||
|
return PermissionValueProviderGrantInfo.NonGranted; |
||||
|
} |
||||
|
|
||||
|
if (await PermissionStore.IsGrantedAsync(context.Permission.Name, Name, clientId)) |
||||
|
{ |
||||
|
return new PermissionValueProviderGrantInfo(true, clientId); |
||||
|
} |
||||
|
|
||||
|
return PermissionValueProviderGrantInfo.NonGranted; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using System.Security.Principal; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Security.Claims; |
||||
|
|
||||
|
namespace Volo.Abp.Clients |
||||
|
{ |
||||
|
public class CurrentClient : ICurrentClient, ITransientDependency |
||||
|
{ |
||||
|
public virtual string Id => _principalAccessor.Principal?.FindClientId(); |
||||
|
|
||||
|
public virtual bool IsAuthenticated => Id != null; |
||||
|
|
||||
|
private readonly ICurrentPrincipalAccessor _principalAccessor; |
||||
|
|
||||
|
public CurrentClient(ICurrentPrincipalAccessor principalAccessor) |
||||
|
{ |
||||
|
_principalAccessor = principalAccessor; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
namespace Volo.Abp.Clients |
||||
|
{ |
||||
|
public interface ICurrentClient |
||||
|
{ |
||||
|
string Id { get; } |
||||
|
|
||||
|
bool IsAuthenticated { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Volo.Abp.Identity |
||||
|
{ |
||||
|
public interface IIdentityUserLookupAppService : IApplicationService |
||||
|
{ |
||||
|
Task<UserData> FindByIdAsync(Guid id); |
||||
|
|
||||
|
Task<UserData> FindByUserNameAsync(string userName); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Volo.Abp.Identity |
||||
|
{ |
||||
|
[Authorize(IdentityPermissions.UserLookup.Default)] |
||||
|
public class IdentityUserLookupAppService : IdentityAppServiceBase, IIdentityUserLookupAppService |
||||
|
{ |
||||
|
protected IdentityUserRepositoryExternalUserLookupServiceProvider UserLookupServiceProvider { get; } |
||||
|
|
||||
|
public IdentityUserLookupAppService( |
||||
|
IdentityUserRepositoryExternalUserLookupServiceProvider userLookupServiceProvider) |
||||
|
{ |
||||
|
UserLookupServiceProvider = userLookupServiceProvider; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<UserData> FindByIdAsync(Guid id) |
||||
|
{ |
||||
|
var userData = await UserLookupServiceProvider.FindByIdAsync(id); |
||||
|
if (userData == null) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
return new UserData(userData); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<UserData> FindByUserNameAsync(string userName) |
||||
|
{ |
||||
|
var userData = await UserLookupServiceProvider.FindByUserNameAsync(userName); |
||||
|
if (userData == null) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
return new UserData(userData); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Volo.Abp.Identity |
||||
|
{ |
||||
|
[RemoteService] |
||||
|
[Area("identity")] |
||||
|
[ControllerName("UserLookup")] |
||||
|
[Route("api/identity/user-lookup")] |
||||
|
public class IdentityUserLookupController : AbpController, IIdentityUserLookupAppService |
||||
|
{ |
||||
|
protected IIdentityUserLookupAppService LookupAppService { get; } |
||||
|
|
||||
|
public IdentityUserLookupController(IIdentityUserLookupAppService lookupAppService) |
||||
|
{ |
||||
|
LookupAppService = lookupAppService; |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
[Route("{id}")] |
||||
|
public Task<UserData> FindByIdAsync(Guid id) |
||||
|
{ |
||||
|
return LookupAppService.FindByIdAsync(id); |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
[Route("by-username/{userName}")] |
||||
|
public Task<UserData> FindByUserNameAsync(string userName) |
||||
|
{ |
||||
|
return LookupAppService.FindByUserNameAsync(userName); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.PermissionManagement.Domain.IdentityServer</AssemblyName> |
||||
|
<PackageId>Volo.Abp.PermissionManagement.Domain.IdentityServer</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.IdentityServer.Domain.Shared\Volo.Abp.IdentityServer.Domain.Shared.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\permission-management\src\Volo.Abp.PermissionManagement.Domain\Volo.Abp.PermissionManagement.Domain.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,18 @@ |
|||||
|
using Volo.Abp.Authorization.Permissions; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp.PermissionManagement.IdentityServer |
||||
|
{ |
||||
|
public class AbpPermissionManagementDomainIdentityServerModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
Configure<PermissionManagementOptions>(options => |
||||
|
{ |
||||
|
options.ManagementProviders.Add<ClientPermissionManagementProvider>(); |
||||
|
|
||||
|
options.ProviderPolicies[ClientPermissionValueProvider.ProviderName] = "IdentityServer.Client.ManagePermissions"; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
using Volo.Abp.Authorization.Permissions; |
||||
|
using Volo.Abp.Guids; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
|
namespace Volo.Abp.PermissionManagement.IdentityServer |
||||
|
{ |
||||
|
public class ClientPermissionManagementProvider : PermissionManagementProvider |
||||
|
{ |
||||
|
public override string Name => ClientPermissionValueProvider.ProviderName; |
||||
|
|
||||
|
public ClientPermissionManagementProvider( |
||||
|
IPermissionGrantRepository permissionGrantRepository, |
||||
|
IGuidGenerator guidGenerator, |
||||
|
ICurrentTenant currentTenant) |
||||
|
: base( |
||||
|
permissionGrantRepository, |
||||
|
guidGenerator, |
||||
|
currentTenant) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
File diff suppressed because it is too large
@ -0,0 +1,72 @@ |
|||||
|
using System.Reflection.Metadata; |
||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
|
||||
|
namespace AuthServer.Host.Migrations |
||||
|
{ |
||||
|
public partial class Added_ClientId_And_CorrelationId_To_AuditLogs : Migration |
||||
|
{ |
||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.DropPrimaryKey( |
||||
|
"PK_IdentityServerClientPostLogoutRedirectUris", |
||||
|
"IdentityServerClientPostLogoutRedirectUris" |
||||
|
); |
||||
|
|
||||
|
migrationBuilder.AlterColumn<string>( |
||||
|
name: "PostLogoutRedirectUri", |
||||
|
table: "IdentityServerClientPostLogoutRedirectUris", |
||||
|
maxLength: 200, |
||||
|
nullable: false, |
||||
|
oldClrType: typeof(string), |
||||
|
oldMaxLength: 2000); |
||||
|
|
||||
|
migrationBuilder.AddPrimaryKey( |
||||
|
"PK_IdentityServerClientPostLogoutRedirectUris", |
||||
|
"IdentityServerClientPostLogoutRedirectUris", |
||||
|
new[] {"ClientId", "PostLogoutRedirectUri"} |
||||
|
); |
||||
|
|
||||
|
migrationBuilder.AddColumn<string>( |
||||
|
name: "ClientId", |
||||
|
table: "AbpAuditLogs", |
||||
|
maxLength: 64, |
||||
|
nullable: true); |
||||
|
|
||||
|
migrationBuilder.AddColumn<string>( |
||||
|
name: "CorrelationId", |
||||
|
table: "AbpAuditLogs", |
||||
|
maxLength: 64, |
||||
|
nullable: true); |
||||
|
} |
||||
|
|
||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "ClientId", |
||||
|
table: "AbpAuditLogs"); |
||||
|
|
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "CorrelationId", |
||||
|
table: "AbpAuditLogs"); |
||||
|
|
||||
|
migrationBuilder.DropPrimaryKey( |
||||
|
"PK_IdentityServerClientPostLogoutRedirectUris", |
||||
|
"IdentityServerClientPostLogoutRedirectUris" |
||||
|
); |
||||
|
|
||||
|
migrationBuilder.AlterColumn<string>( |
||||
|
name: "PostLogoutRedirectUri", |
||||
|
table: "IdentityServerClientPostLogoutRedirectUris", |
||||
|
maxLength: 2000, |
||||
|
nullable: false, |
||||
|
oldClrType: typeof(string), |
||||
|
oldMaxLength: 200); |
||||
|
|
||||
|
migrationBuilder.AddPrimaryKey( |
||||
|
"PK_IdentityServerClientPostLogoutRedirectUris", |
||||
|
"IdentityServerClientPostLogoutRedirectUris", |
||||
|
new[] { "ClientId", "PostLogoutRedirectUri" } |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Binary file not shown.
Loading…
Reference in new issue