Browse Source

Merge remote-tracking branch 'upstream/master'

pull/818/head
Atakan Özceviz 8 years ago
parent
commit
7920b62224
  1. 49
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AspNetCoreCorrelationIdProvider.cs
  2. 6
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs
  3. 6
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs
  4. 13
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingHelper.cs
  5. 1
      framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationModule.cs
  6. 11
      framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/MethodInvocationAuthorizationService.cs
  7. 35
      framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/ClientPermissionValueProvider.cs
  8. 14
      framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionChecker.cs
  9. 27
      framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionDefinition.cs
  10. 7
      framework/src/Volo.Abp.Core/Volo/Abp/Tracing/CorrelationIdOptions.cs
  11. 18
      framework/src/Volo.Abp.Core/Volo/Abp/Tracing/DefaultCorrelationIdProvider.cs
  12. 10
      framework/src/Volo.Abp.Core/Volo/Abp/Tracing/ICorrelationIdProvider.cs
  13. 101
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Values/ValueObject.cs
  14. 26
      framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs
  15. 35
      framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/RemoteServiceConfigurationExtensions.cs
  16. 1
      framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj
  17. 9
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientModule.cs
  18. 6
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/RemoteServiceHttpClientAuthenticateContext.cs
  19. 95
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs
  20. 3
      framework/src/Volo.Abp.Http/Volo/Abp/Http/AbpHttpModule.cs
  21. 3
      framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs
  22. 44
      framework/src/Volo.Abp.Security/System/Security/Principal/AbpClaimsIdentityExtensions.cs
  23. 20
      framework/src/Volo.Abp.Security/Volo/Abp/Clients/CurrentClient.cs
  24. 9
      framework/src/Volo.Abp.Security/Volo/Abp/Clients/ICurrentClient.cs
  25. 5
      framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/AbpClaimTypes.cs
  26. 6
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs
  27. 10
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs
  28. 3
      modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs
  29. 21
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  30. 20
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/BloggingEntityFrameworkCoreQueryableExtensions.cs
  31. 6
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs
  32. 2
      modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs
  33. 3
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo.Abp.Identity.Application.Contracts.csproj
  34. 15
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/AbpIdentityApplicationContractsModule.cs
  35. 14
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs
  36. 2
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityPermissionDefinitionProvider.cs
  37. 8
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityPermissions.cs
  38. 3
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/en.json
  39. 6
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/pt-BR.json
  40. 3
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/tr.json
  41. 41
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs
  42. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs
  43. 3
      modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj
  44. 2
      modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/AbpIdentityHttpApiClientModule.cs
  45. 14
      modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs
  46. 36
      modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs
  47. 2
      modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/pt-BR.json
  48. 2
      modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RolePermissionManagementProvider.cs
  49. 4
      modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/UserPermissionManagementProvider.cs
  50. 9
      modules/identityserver/Volo.Abp.IdentityServer.sln
  51. 21
      modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo.Abp.PermissionManagement.Domain.IdentityServer.csproj
  52. 18
      modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs
  53. 23
      modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/ClientPermissionManagementProvider.cs
  54. 22
      modules/permission-management/src/Volo.Abp.PermissionManagement.Application/Volo/Abp/PermissionManagement/PermissionAppService.cs
  55. 2
      modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/Localization/ApplicationContracts/pt-BR.json
  56. 13
      modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserData.cs
  57. 1
      nupkg/common.ps1
  58. 7
      samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerHostModule.cs
  59. 1150
      samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190208210234_Added_ClientId_And_CorrelationId_To_AuditLogs.Designer.cs
  60. 72
      samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190208210234_Added_ClientId_And_CorrelationId_To_AuditLogs.cs
  61. 1154
      samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190209193341_Added_ApplicationName_To_AuditLogs.Designer.cs
  62. 23
      samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190209193341_Added_ApplicationName_To_AuditLogs.cs
  63. 14
      samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/AuthServerDbContextModelSnapshot.cs
  64. BIN
      samples/MicroserviceDemo/databases/MsDemo_Identity.zip
  65. 1
      samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGateway.Host.csproj
  66. 4
      samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGatewayHostModule.cs
  67. 7
      samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingServiceHostModule.cs
  68. 12
      samples/MicroserviceDemo/microservices/BloggingService.Host/appsettings.json
  69. 7
      samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityServiceHostModule.cs
  70. 1
      samples/MicroserviceDemo/microservices/ProductService.Host/ProductService.Host.csproj
  71. 7
      samples/MicroserviceDemo/microservices/ProductService.Host/ProductServiceHostModule.cs

49
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AspNetCoreCorrelationIdProvider.cs

@ -0,0 +1,49 @@
using System;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Tracing;
namespace Volo.Abp.AspNetCore.Tracing
{
[Dependency(ReplaceServices = true)]
public class AspNetCoreCorrelationIdProvider : ICorrelationIdProvider, ITransientDependency
{
protected IHttpContextAccessor HttpContextAccessor { get; }
protected CorrelationIdOptions Options { get; }
public AspNetCoreCorrelationIdProvider(
IHttpContextAccessor httpContextAccessor,
IOptions<CorrelationIdOptions> options)
{
HttpContextAccessor = httpContextAccessor;
Options = options.Value;
}
public virtual string Get()
{
if (HttpContextAccessor.HttpContext?.Request?.Headers == null)
{
return CreateNewCorrelationId();
}
lock (HttpContextAccessor.HttpContext.Request.Headers)
{
string correlationId = HttpContextAccessor.HttpContext.Request.Headers[Options.HttpHeaderName];
if (correlationId.IsNullOrEmpty())
{
correlationId = CreateNewCorrelationId();
HttpContextAccessor.HttpContext.Request.Headers[Options.HttpHeaderName] = correlationId;
}
return correlationId;
}
}
protected virtual string CreateNewCorrelationId()
{
return Guid.NewGuid().ToString("N");
}
}
}

6
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs

@ -14,6 +14,12 @@ namespace Volo.Abp.Auditing
/// </summary> /// </summary>
public bool IsEnabled { get; set; } public bool IsEnabled { get; set; }
/// <summary>
/// The name of the application or service writing audit logs.
/// Default: null.
/// </summary>
public string ApplicationName { get; set; }
/// <summary> /// <summary>
/// Default: true. /// Default: true.
/// </summary> /// </summary>

6
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs

@ -10,6 +10,8 @@ namespace Volo.Abp.Auditing
//TODO: Make serializable! //TODO: Make serializable!
public class AuditLogInfo : IMultiTenant, IHasExtraProperties public class AuditLogInfo : IMultiTenant, IHasExtraProperties
{ {
public string ApplicationName { get; set; }
public Guid? UserId { get; set; } public Guid? UserId { get; set; }
public string UserName { get; set; } public string UserName { get; set; }
@ -24,6 +26,10 @@ namespace Volo.Abp.Auditing
public int ExecutionDuration { get; set; } public int ExecutionDuration { get; set; }
public string ClientId { get; set; }
public string CorrelationId { get; set; }
public string ClientIpAddress { get; set; } public string ClientIpAddress { get; set; }
public string ClientName { get; set; } public string ClientName { get; set; }

13
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingHelper.cs

@ -5,9 +5,11 @@ using System.Reflection;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.Clients;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.Abp.Timing; using Volo.Abp.Timing;
using Volo.Abp.Tracing;
using Volo.Abp.Users; using Volo.Abp.Users;
namespace Volo.Abp.Auditing namespace Volo.Abp.Auditing
@ -18,30 +20,36 @@ namespace Volo.Abp.Auditing
protected IAuditingStore AuditingStore { get; } protected IAuditingStore AuditingStore { get; }
protected ICurrentUser CurrentUser { get; } protected ICurrentUser CurrentUser { get; }
protected ICurrentTenant CurrentTenant { get; } protected ICurrentTenant CurrentTenant { get; }
protected ICurrentClient CurrentClient { get; }
protected IClock Clock { get; } protected IClock Clock { get; }
protected AbpAuditingOptions Options; protected AbpAuditingOptions Options;
protected IAuditSerializer AuditSerializer; protected IAuditSerializer AuditSerializer;
protected IServiceProvider ServiceProvider; protected IServiceProvider ServiceProvider;
protected ICorrelationIdProvider CorrelationIdProvider { get; }
public AuditingHelper( public AuditingHelper(
IAuditSerializer auditSerializer, IAuditSerializer auditSerializer,
IOptions<AbpAuditingOptions> options, IOptions<AbpAuditingOptions> options,
ICurrentUser currentUser, ICurrentUser currentUser,
ICurrentTenant currentTenant, ICurrentTenant currentTenant,
ICurrentClient currentClient,
IClock clock, IClock clock,
IAuditingStore auditingStore, IAuditingStore auditingStore,
ILogger<AuditingHelper> logger, ILogger<AuditingHelper> logger,
IServiceProvider serviceProvider) IServiceProvider serviceProvider,
ICorrelationIdProvider correlationIdProvider)
{ {
Options = options.Value; Options = options.Value;
AuditSerializer = auditSerializer; AuditSerializer = auditSerializer;
CurrentUser = currentUser; CurrentUser = currentUser;
CurrentTenant = currentTenant; CurrentTenant = currentTenant;
CurrentClient = currentClient;
Clock = clock; Clock = clock;
AuditingStore = auditingStore; AuditingStore = auditingStore;
Logger = logger; Logger = logger;
ServiceProvider = serviceProvider; ServiceProvider = serviceProvider;
CorrelationIdProvider = correlationIdProvider;
} }
public virtual bool ShouldSaveAudit(MethodInfo methodInfo, bool defaultValue = false) public virtual bool ShouldSaveAudit(MethodInfo methodInfo, bool defaultValue = false)
@ -82,9 +90,12 @@ namespace Volo.Abp.Auditing
{ {
var auditInfo = new AuditLogInfo var auditInfo = new AuditLogInfo
{ {
ApplicationName = Options.ApplicationName,
TenantId = CurrentTenant.Id, TenantId = CurrentTenant.Id,
UserId = CurrentUser.Id, UserId = CurrentUser.Id,
UserName = CurrentUser.UserName, UserName = CurrentUser.UserName,
ClientId = CurrentClient.Id,
CorrelationId = CorrelationIdProvider.Get(),
//ImpersonatorUserId = AbpSession.ImpersonatorUserId, //TODO: Impersonation system is not available yet! //ImpersonatorUserId = AbpSession.ImpersonatorUserId, //TODO: Impersonation system is not available yet!
//ImpersonatorTenantId = AbpSession.ImpersonatorTenantId, //ImpersonatorTenantId = AbpSession.ImpersonatorTenantId,
ExecutionTime = Clock.Now ExecutionTime = Clock.Now

1
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationModule.cs

@ -28,6 +28,7 @@ namespace Volo.Abp.Authorization
{ {
options.ValueProviders.Add<UserPermissionValueProvider>(); options.ValueProviders.Add<UserPermissionValueProvider>();
options.ValueProviders.Add<RolePermissionValueProvider>(); options.ValueProviders.Add<RolePermissionValueProvider>();
options.ValueProviders.Add<ClientPermissionValueProvider>();
}); });
} }
} }

11
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/MethodInvocationAuthorizationService.cs

@ -1,6 +1,7 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Clients;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Users; using Volo.Abp.Users;
@ -10,11 +11,16 @@ namespace Volo.Abp.Authorization
{ {
private readonly IAuthorizationService _authorizationService; private readonly IAuthorizationService _authorizationService;
private readonly ICurrentUser _currentUser; private readonly ICurrentUser _currentUser;
private readonly ICurrentClient _currentClient;
public MethodInvocationAuthorizationService(IAuthorizationService authorizationService, ICurrentUser currentUser) public MethodInvocationAuthorizationService(
IAuthorizationService authorizationService,
ICurrentUser currentUser,
ICurrentClient currentClient)
{ {
_authorizationService = authorizationService; _authorizationService = authorizationService;
_currentUser = currentUser; _currentUser = currentUser;
_currentClient = currentClient;
} }
public async Task CheckAsync(MethodInvocationAuthorizationContext context) public async Task CheckAsync(MethodInvocationAuthorizationContext context)
@ -53,7 +59,8 @@ namespace Volo.Abp.Authorization
{ {
if (authorizationAttribute.Policy == null) if (authorizationAttribute.Policy == null)
{ {
if (!_currentUser.IsAuthenticated) //TODO: What about API calls without user id? //TODO: Can we find a better, unified, way of checking if current request has been authenticated
if (!_currentUser.IsAuthenticated && !_currentClient.IsAuthenticated)
{ {
throw new AbpAuthorizationException("Authorization failed! User has not logged in."); throw new AbpAuthorizationException("Authorization failed! User has not logged in.");
} }

35
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/ClientPermissionValueProvider.cs

@ -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;
}
}
}

14
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionChecker.cs

@ -1,10 +1,10 @@
using System; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Security.Claims; using Volo.Abp.Security.Claims;
@ -40,7 +40,7 @@ namespace Volo.Abp.Authorization.Permissions
true true
); );
} }
public virtual Task<PermissionGrantInfo> CheckAsync(string name) public virtual Task<PermissionGrantInfo> CheckAsync(string name)
{ {
return CheckAsync(PrincipalAccessor.Principal, name); return CheckAsync(PrincipalAccessor.Principal, name);
@ -57,6 +57,12 @@ namespace Volo.Abp.Authorization.Permissions
foreach (var provider in ValueProviders) foreach (var provider in ValueProviders)
{ {
if (context.Permission.Providers.Any() &&
!context.Permission.Providers.Contains(provider.Name))
{
continue;
}
var result = await provider.CheckAsync(context); var result = await provider.CheckAsync(context);
if (result.IsGranted) if (result.IsGranted)
{ {

27
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionDefinition.cs

@ -18,6 +18,8 @@ namespace Volo.Abp.Authorization.Permissions
/// </summary> /// </summary>
public PermissionDefinition Parent { get; private set; } public PermissionDefinition Parent { get; private set; }
public List<string> Providers { get; }
public ILocalizableString DisplayName public ILocalizableString DisplayName
{ {
get => _displayName; get => _displayName;
@ -53,6 +55,7 @@ namespace Volo.Abp.Authorization.Permissions
DisplayName = displayName ?? new FixedLocalizableString(name); DisplayName = displayName ?? new FixedLocalizableString(name);
Properties = new Dictionary<string, object>(); Properties = new Dictionary<string, object>();
Providers = new List<string>();
_children = new List<PermissionDefinition>(); _children = new List<PermissionDefinition>();
} }
@ -68,6 +71,30 @@ namespace Volo.Abp.Authorization.Permissions
return child; return child;
} }
/// <summary>
/// Sets a property in the <see cref="Properties"/> dictionary.
/// This is a shortcut for nested calls on this object.
/// </summary>
public virtual PermissionDefinition WithProperty(string key, object value)
{
Properties[key] = value;
return this;
}
/// <summary>
/// Sets a property in the <see cref="Properties"/> dictionary.
/// This is a shortcut for nested calls on this object.
/// </summary>
public virtual PermissionDefinition WithProviders(params string[] providers)
{
if (!providers.IsNullOrEmpty())
{
Providers.AddRange(providers);
}
return this;
}
public override string ToString() public override string ToString()
{ {
return $"[{nameof(PermissionDefinition)} {Name}]"; return $"[{nameof(PermissionDefinition)} {Name}]";

7
framework/src/Volo.Abp.Core/Volo/Abp/Tracing/CorrelationIdOptions.cs

@ -0,0 +1,7 @@
namespace Volo.Abp.Tracing
{
public class CorrelationIdOptions
{
public string HttpHeaderName { get; set; } = "X-Correlation-Id";
}
}

18
framework/src/Volo.Abp.Core/Volo/Abp/Tracing/DefaultCorrelationIdProvider.cs

@ -0,0 +1,18 @@
using System;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Tracing
{
public class DefaultCorrelationIdProvider : ICorrelationIdProvider, ISingletonDependency
{
public string Get()
{
return CreateNewCorrelationId();
}
protected virtual string CreateNewCorrelationId()
{
return Guid.NewGuid().ToString("N");
}
}
}

10
framework/src/Volo.Abp.Core/Volo/Abp/Tracing/ICorrelationIdProvider.cs

@ -0,0 +1,10 @@
using JetBrains.Annotations;
namespace Volo.Abp.Tracing
{
public interface ICorrelationIdProvider
{
[NotNull]
string Get();
}
}

101
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Values/ValueObject.cs

@ -1,98 +1,61 @@
using System; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
namespace Volo.Abp.Domain.Values namespace Volo.Abp.Domain.Values
{ {
//Inspired from https://blogs.msdn.microsoft.com/cesardelatorre/2011/06/06/implementing-a-value-object-base-class-supertype-patternddd-patterns-related/ //Inspired from https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/microservice-ddd-cqrs-patterns/implement-value-objects
/// <summary> public abstract class ValueObject
/// Base class for value objects.
/// </summary>
/// <typeparam name="TValueObject">The type of the value object.</typeparam>
public abstract class ValueObject<TValueObject> : IEquatable<TValueObject>
where TValueObject : ValueObject<TValueObject>
{ {
public bool Equals(TValueObject other) protected static bool EqualOperator(ValueObject left, ValueObject right)
{ {
if ((object)other == null) if (ReferenceEquals(left, null) ^ ReferenceEquals(right, null))
{ {
return false; return false;
} }
return ReferenceEquals(left, null) || left.Equals(right);
}
var publicProperties = GetType().GetTypeInfo().GetProperties(); protected static bool NotEqualOperator(ValueObject left, ValueObject right)
if (!publicProperties.Any()) {
{ return !(EqualOperator(left, right));
return true;
}
return publicProperties.All(property => Equals(property.GetValue(this, null), property.GetValue(other, null)));
} }
protected abstract IEnumerable<object> GetAtomicValues();
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj == null) if (obj == null || obj.GetType() != GetType())
{ {
return false; return false;
} }
var item = obj as ValueObject<TValueObject>; ValueObject other = (ValueObject)obj;
return (object)item != null && Equals((TValueObject)item); IEnumerator<object> thisValues = GetAtomicValues().GetEnumerator();
} IEnumerator<object> otherValues = other.GetAtomicValues().GetEnumerator();
while (thisValues.MoveNext() && otherValues.MoveNext())
public override int GetHashCode()
{
//TODO: Can we cache the hash value assuming value objects are always immutable? We can make a Reset-like method to reset it's mutated.
const int index = 1;
const int initialHasCode = 31;
var publicProperties = GetType().GetTypeInfo().GetProperties();
if (!publicProperties.Any())
{ {
return initialHasCode; if (ReferenceEquals(thisValues.Current, null) ^
} ReferenceEquals(otherValues.Current, null))
var hashCode = initialHasCode;
var changeMultiplier = false;
foreach (var property in publicProperties)
{
var value = property.GetValue(this, null);
if (value == null)
{ {
//support {"a",null,null,"a"} != {null,"a","a",null} return false;
hashCode = hashCode ^ (index * 13);
continue;
} }
hashCode = hashCode * (changeMultiplier ? 59 : 114) + value.GetHashCode(); if (thisValues.Current != null &&
changeMultiplier = !changeMultiplier; !thisValues.Current.Equals(otherValues.Current))
} {
return false;
return hashCode; }
}
public static bool operator ==(ValueObject<TValueObject> x, ValueObject<TValueObject> y)
{
if (ReferenceEquals(x, y))
{
return true;
}
if (((object)x == null) || ((object)y == null))
{
return false;
} }
return !thisValues.MoveNext() && !otherValues.MoveNext();
return x.Equals(y);
} }
public static bool operator !=(ValueObject<TValueObject> x, ValueObject<TValueObject> y) public override int GetHashCode()
{ {
return !(x == y); return GetAtomicValues()
.Select(x => x != null ? x.GetHashCode() : 0)
.Aggregate((x, y) => x ^ y);
} }
// Other utilility methods
} }
} }

26
framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs

@ -22,26 +22,24 @@ namespace Volo.Abp.Http.Client.IdentityModel
public async Task Authenticate(RemoteServiceHttpClientAuthenticateContext context) public async Task Authenticate(RemoteServiceHttpClientAuthenticateContext context)
{ {
var accessToken = await GetAccessTokenFromHttpContextOrNullAsync(); if (context.RemoteService.GetUseCurrentAccessToken() != false)
if (accessToken != null)
{
context.Client.SetBearerToken(accessToken);
}
else
{ {
await IdentityModelHttpClientAuthenticator.AuthenticateAsync( var accessToken = await GetAccessTokenFromHttpContextOrNullAsync();
new IdentityModelHttpClientAuthenticateContext( if (accessToken != null)
context.Client, {
context.RemoteService.GetIdentityClient() context.Client.SetBearerToken(accessToken);
) return;
); }
} }
await IdentityModelHttpClientAuthenticator.AuthenticateAsync(
context.Client,
context.RemoteService.GetIdentityClient()
);
} }
protected virtual async Task<string> GetAccessTokenFromHttpContextOrNullAsync() protected virtual async Task<string> GetAccessTokenFromHttpContextOrNullAsync()
{ {
//TODO: What if the access_token in the current Http Request is not usable for this client?
var httpContext = HttpContextAccessor?.HttpContext; var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext == null) if (httpContext == null)
{ {

35
framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/RemoteServiceConfigurationExtensions.cs

@ -5,19 +5,48 @@ namespace Volo.Abp.Http.Client
{ {
public static class RemoteServiceConfigurationExtensions public static class RemoteServiceConfigurationExtensions
{ {
public const string IdentityClient = "IdentityClient"; public const string IdentityClientName = "IdentityClient";
public const string UseCurrentAccessTokenName = "UseCurrentAccessToken";
[CanBeNull] [CanBeNull]
public static string GetIdentityClient([NotNull] this RemoteServiceConfiguration configuration) public static string GetIdentityClient([NotNull] this RemoteServiceConfiguration configuration)
{ {
Check.NotNullOrEmpty(configuration, nameof(configuration)); Check.NotNullOrEmpty(configuration, nameof(configuration));
return configuration.GetOrDefault(IdentityClient); return configuration.GetOrDefault(IdentityClientName);
} }
public static RemoteServiceConfiguration SetIdentityClient([NotNull] this RemoteServiceConfiguration configuration, [CanBeNull] string value) public static RemoteServiceConfiguration SetIdentityClient([NotNull] this RemoteServiceConfiguration configuration, [CanBeNull] string value)
{ {
configuration[IdentityClient] = value; configuration[IdentityClientName] = value;
return configuration;
}
[CanBeNull]
public static bool? GetUseCurrentAccessToken([NotNull] this RemoteServiceConfiguration configuration)
{
Check.NotNullOrEmpty(configuration, nameof(configuration));
var value = configuration.GetOrDefault(UseCurrentAccessTokenName);
if (value == null)
{
return null;
}
return bool.Parse(value);
}
public static RemoteServiceConfiguration SetUseCurrentAccessToken([NotNull] this RemoteServiceConfiguration configuration, [CanBeNull] bool? value)
{
if (value == null)
{
configuration.Remove(UseCurrentAccessTokenName);
}
else
{
configuration[UseCurrentAccessTokenName] = value.Value.ToString().ToLowerInvariant();
}
return configuration; return configuration;
} }
} }

1
framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj

@ -20,6 +20,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Volo.Abp.Castle.Core\Volo.Abp.Castle.Core.csproj" /> <ProjectReference Include="..\Volo.Abp.Castle.Core\Volo.Abp.Castle.Core.csproj" />
<ProjectReference Include="..\Volo.Abp.Http\Volo.Abp.Http.csproj" /> <ProjectReference Include="..\Volo.Abp.Http\Volo.Abp.Http.csproj" />
<ProjectReference Include="..\Volo.Abp.Threading\Volo.Abp.Threading.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

9
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientModule.cs

@ -1,17 +1,20 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Castle; using Volo.Abp.Castle;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace Volo.Abp.Http.Client namespace Volo.Abp.Http.Client
{ {
[DependsOn(typeof(AbpHttpModule))] [DependsOn(
[DependsOn(typeof(AbpCastleCoreModule))] typeof(AbpHttpModule),
typeof(AbpCastleCoreModule),
typeof(AbpThreadingModule)
)]
public class AbpHttpClientModule : AbpModule public class AbpHttpClientModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
var configuration = context.Services.GetConfiguration(); var configuration = context.Services.GetConfiguration();
Configure<RemoteServiceOptions>(configuration); Configure<RemoteServiceOptions>(configuration);
} }
} }

6
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/RemoteServiceHttpClientAuthenticateContext.cs

@ -10,14 +10,18 @@ namespace Volo.Abp.Http.Client.Authentication
public RemoteServiceConfiguration RemoteService { get; } public RemoteServiceConfiguration RemoteService { get; }
public string RemoteServiceName { get; }
public RemoteServiceHttpClientAuthenticateContext( public RemoteServiceHttpClientAuthenticateContext(
HttpClient client, HttpClient client,
HttpRequestMessage request, HttpRequestMessage request,
RemoteServiceConfiguration remoteService) RemoteServiceConfiguration remoteService,
string remoteServiceName)
{ {
Client = client; Client = client;
Request = request; Request = request;
RemoteService = remoteService; RemoteService = remoteService;
RemoteServiceName = remoteServiceName;
} }
} }
} }

95
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Reflection; using System.Reflection;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
@ -15,21 +16,25 @@ using Volo.Abp.Http.ProxyScripting.Generators;
using Volo.Abp.Json; using Volo.Abp.Json;
using Volo.Abp.Reflection; using Volo.Abp.Reflection;
using Volo.Abp.Threading; using Volo.Abp.Threading;
using Volo.Abp.Tracing;
namespace Volo.Abp.Http.Client.DynamicProxying namespace Volo.Abp.Http.Client.DynamicProxying
{ {
//TODO: Somehow capture cancellationtoken and pass to other methods...?
public class DynamicHttpProxyInterceptor<TService> : AbpInterceptor, ITransientDependency public class DynamicHttpProxyInterceptor<TService> : AbpInterceptor, ITransientDependency
{ {
private static MethodInfo GenericInterceptAsyncMethod { get; } // ReSharper disable once StaticMemberInGenericType
protected static MethodInfo GenericInterceptAsyncMethod { get; }
protected ICancellationTokenProvider CancellationTokenProvider { get; }
protected ICorrelationIdProvider CorrelationIdProvider { get; }
protected CorrelationIdOptions CorrelationIdOptions { get; }
protected IDynamicProxyHttpClientFactory HttpClientFactory { get; }
protected IApiDescriptionFinder ApiDescriptionFinder { get; }
protected RemoteServiceOptions RemoteServiceOptions { get; }
protected AbpHttpClientOptions ClientOptions { get; }
protected IJsonSerializer JsonSerializer { get; }
protected IRemoteServiceHttpClientAuthenticator ClientAuthenticator { get; }
private readonly IDynamicProxyHttpClientFactory _httpClientFactory;
private readonly IApiDescriptionFinder _apiDescriptionFinder;
private readonly RemoteServiceOptions _remoteServiceOptions;
private readonly AbpHttpClientOptions _clientOptions;
private readonly IJsonSerializer _jsonSerializer;
private readonly IRemoteServiceHttpClientAuthenticator _clientAuthenticator;
public ILogger<DynamicHttpProxyInterceptor<TService>> Logger { get; set; } public ILogger<DynamicHttpProxyInterceptor<TService>> Logger { get; set; }
@ -46,14 +51,20 @@ namespace Volo.Abp.Http.Client.DynamicProxying
IOptionsSnapshot<RemoteServiceOptions> remoteServiceOptions, IOptionsSnapshot<RemoteServiceOptions> remoteServiceOptions,
IApiDescriptionFinder apiDescriptionFinder, IApiDescriptionFinder apiDescriptionFinder,
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
IRemoteServiceHttpClientAuthenticator clientAuthenticator) IRemoteServiceHttpClientAuthenticator clientAuthenticator,
ICancellationTokenProvider cancellationTokenProvider,
ICorrelationIdProvider correlationIdProvider,
IOptions<CorrelationIdOptions> correlationIdOptions)
{ {
_httpClientFactory = httpClientFactory; CancellationTokenProvider = cancellationTokenProvider;
_apiDescriptionFinder = apiDescriptionFinder; CorrelationIdProvider = correlationIdProvider;
_jsonSerializer = jsonSerializer; CorrelationIdOptions = correlationIdOptions.Value;
_clientAuthenticator = clientAuthenticator; HttpClientFactory = httpClientFactory;
_clientOptions = clientOptions.Value; ApiDescriptionFinder = apiDescriptionFinder;
_remoteServiceOptions = remoteServiceOptions.Value; JsonSerializer = jsonSerializer;
ClientAuthenticator = clientAuthenticator;
ClientOptions = clientOptions.Value;
RemoteServiceOptions = remoteServiceOptions.Value;
Logger = NullLogger<DynamicHttpProxyInterceptor<TService>>.Instance; Logger = NullLogger<DynamicHttpProxyInterceptor<TService>>.Instance;
} }
@ -62,11 +73,11 @@ namespace Volo.Abp.Http.Client.DynamicProxying
{ {
if (invocation.Method.ReturnType == typeof(void)) if (invocation.Method.ReturnType == typeof(void))
{ {
AsyncHelper.RunSync(() => MakeRequest(invocation)); AsyncHelper.RunSync(() => MakeRequestAsync(invocation));
} }
else else
{ {
var responseAsString = AsyncHelper.RunSync(() => MakeRequest(invocation)); var responseAsString = AsyncHelper.RunSync(() => MakeRequestAsync(invocation));
//TODO: Think on that //TODO: Think on that
if (TypeHelper.IsPrimitiveExtended(invocation.Method.ReturnType, true)) if (TypeHelper.IsPrimitiveExtended(invocation.Method.ReturnType, true))
@ -75,7 +86,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying
} }
else else
{ {
invocation.ReturnValue = _jsonSerializer.Deserialize( invocation.ReturnValue = JsonSerializer.Deserialize(
invocation.Method.ReturnType, invocation.Method.ReturnType,
responseAsString responseAsString
); );
@ -87,7 +98,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying
{ {
if (invocation.Method.ReturnType.GenericTypeArguments.IsNullOrEmpty()) if (invocation.Method.ReturnType.GenericTypeArguments.IsNullOrEmpty())
{ {
return MakeRequest(invocation); return MakeRequestAsync(invocation);
} }
invocation.ReturnValue = GenericInterceptAsyncMethod invocation.ReturnValue = GenericInterceptAsyncMethod
@ -99,7 +110,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying
private async Task<T> MakeRequestAndGetResultAsync<T>(IAbpMethodInvocation invocation) private async Task<T> MakeRequestAndGetResultAsync<T>(IAbpMethodInvocation invocation)
{ {
var responseAsString = await MakeRequest(invocation); var responseAsString = await MakeRequestAsync(invocation);
//TODO: Think on that //TODO: Think on that
if (TypeHelper.IsPrimitiveExtended(typeof(T), true)) if (TypeHelper.IsPrimitiveExtended(typeof(T), true))
@ -107,36 +118,37 @@ namespace Volo.Abp.Http.Client.DynamicProxying
return (T)Convert.ChangeType(responseAsString, typeof(T)); return (T)Convert.ChangeType(responseAsString, typeof(T));
} }
return _jsonSerializer.Deserialize<T>(responseAsString); return JsonSerializer.Deserialize<T>(responseAsString);
} }
private async Task<string> MakeRequest(IAbpMethodInvocation invocation) private async Task<string> MakeRequestAsync(IAbpMethodInvocation invocation)
{ {
using (var client = _httpClientFactory.Create()) using (var client = HttpClientFactory.Create())
{ {
var clientConfig = _clientOptions.HttpClientProxies.GetOrDefault(typeof(TService)) ?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}."); var clientConfig = ClientOptions.HttpClientProxies.GetOrDefault(typeof(TService)) ?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}.");
var remoteServiceConfig = _remoteServiceOptions.RemoteServices.GetConfigurationOrDefault(clientConfig.RemoteServiceName); var remoteServiceConfig = RemoteServiceOptions.RemoteServices.GetConfigurationOrDefault(clientConfig.RemoteServiceName);
var action = await _apiDescriptionFinder.FindActionAsync(remoteServiceConfig.BaseUrl, typeof(TService), invocation.Method); var action = await ApiDescriptionFinder.FindActionAsync(remoteServiceConfig.BaseUrl, typeof(TService), invocation.Method);
var apiVersion = GetApiVersionInfo(action); var apiVersion = GetApiVersionInfo(action);
var url = remoteServiceConfig.BaseUrl + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary, apiVersion); var url = remoteServiceConfig.BaseUrl + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary, apiVersion);
var requestMessage = new HttpRequestMessage(action.GetHttpMethod(), url) var requestMessage = new HttpRequestMessage(action.GetHttpMethod(), url)
{ {
Content = RequestPayloadBuilder.BuildContent(action, invocation.ArgumentsDictionary, _jsonSerializer, apiVersion) Content = RequestPayloadBuilder.BuildContent(action, invocation.ArgumentsDictionary, JsonSerializer, apiVersion)
}; };
AddHeaders(invocation, action, requestMessage, apiVersion); AddHeaders(invocation, action, requestMessage, apiVersion);
await _clientAuthenticator.Authenticate( await ClientAuthenticator.Authenticate(
new RemoteServiceHttpClientAuthenticateContext( new RemoteServiceHttpClientAuthenticateContext(
client, client,
requestMessage, requestMessage,
remoteServiceConfig remoteServiceConfig,
clientConfig.RemoteServiceName
) )
); );
var response = await client.SendAsync(requestMessage); var response = await client.SendAsync(requestMessage, GetCancellationToken());
if (!response.IsSuccessStatusCode) if (!response.IsSuccessStatusCode)
{ {
@ -175,8 +187,9 @@ namespace Volo.Abp.Http.Client.DynamicProxying
return action.SupportedVersions.Last(); //TODO: Ensure to get the latest version! return action.SupportedVersions.Last(); //TODO: Ensure to get the latest version!
} }
private static void AddHeaders(IAbpMethodInvocation invocation, ActionApiDescriptionModel action, HttpRequestMessage requestMessage, ApiVersionInfo apiVersion) protected virtual void AddHeaders(IAbpMethodInvocation invocation, ActionApiDescriptionModel action, HttpRequestMessage requestMessage, ApiVersionInfo apiVersion)
{ {
//API Version
if (!apiVersion.Version.IsNullOrEmpty()) if (!apiVersion.Version.IsNullOrEmpty())
{ {
//TODO: What about other media types? //TODO: What about other media types?
@ -185,8 +198,8 @@ namespace Volo.Abp.Http.Client.DynamicProxying
requestMessage.Headers.Add("api-version", apiVersion.Version); requestMessage.Headers.Add("api-version", apiVersion.Version);
} }
//Header parameters
var headers = action.Parameters.Where(p => p.BindingSourceId == ParameterBindingSources.Header).ToArray(); var headers = action.Parameters.Where(p => p.BindingSourceId == ParameterBindingSources.Header).ToArray();
foreach (var headerParameter in headers) foreach (var headerParameter in headers)
{ {
var value = HttpActionParameterHelper.FindParameterValue(invocation.ArgumentsDictionary, headerParameter); var value = HttpActionParameterHelper.FindParameterValue(invocation.ArgumentsDictionary, headerParameter);
@ -195,22 +208,25 @@ namespace Volo.Abp.Http.Client.DynamicProxying
requestMessage.Headers.Add(headerParameter.Name, value.ToString()); requestMessage.Headers.Add(headerParameter.Name, value.ToString());
} }
} }
//CorrelationId
requestMessage.Headers.Add(CorrelationIdOptions.HttpHeaderName, CorrelationIdProvider.Get());
} }
private string GetConfiguredApiVersion() private string GetConfiguredApiVersion()
{ {
var clientConfig = _clientOptions.HttpClientProxies.GetOrDefault(typeof(TService)) var clientConfig = ClientOptions.HttpClientProxies.GetOrDefault(typeof(TService))
?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}."); ?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}.");
return _remoteServiceOptions.RemoteServices.GetOrDefault(clientConfig.RemoteServiceName)?.Version return RemoteServiceOptions.RemoteServices.GetOrDefault(clientConfig.RemoteServiceName)?.Version
?? _remoteServiceOptions.RemoteServices.Default?.Version; ?? RemoteServiceOptions.RemoteServices.Default?.Version;
} }
private async Task ThrowExceptionForResponseAsync(HttpResponseMessage response) private async Task ThrowExceptionForResponseAsync(HttpResponseMessage response)
{ {
if (response.Headers.Contains(AbpHttpConsts.AbpErrorFormat)) if (response.Headers.Contains(AbpHttpConsts.AbpErrorFormat))
{ {
var errorResponse = _jsonSerializer.Deserialize<RemoteServiceErrorResponse>( var errorResponse = JsonSerializer.Deserialize<RemoteServiceErrorResponse>(
await response.Content.ReadAsStringAsync() await response.Content.ReadAsStringAsync()
); );
@ -219,5 +235,10 @@ namespace Volo.Abp.Http.Client.DynamicProxying
throw new AbpException($"Remote service returns error! HttpStatusCode: {response.StatusCode}, ReasonPhrase: {response.ReasonPhrase}"); throw new AbpException($"Remote service returns error! HttpStatusCode: {response.StatusCode}, ReasonPhrase: {response.ReasonPhrase}");
} }
protected virtual CancellationToken GetCancellationToken()
{
return CancellationTokenProvider.Token;
}
} }
} }

3
framework/src/Volo.Abp.Http/Volo/Abp/Http/AbpHttpModule.cs

@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Http.ProxyScripting.Configuration;
using Volo.Abp.Http.ProxyScripting.Configuration;
using Volo.Abp.Http.ProxyScripting.Generators.JQuery; using Volo.Abp.Http.ProxyScripting.Generators.JQuery;
using Volo.Abp.Json; using Volo.Abp.Json;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;

3
framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs

@ -15,7 +15,6 @@ namespace Volo.Abp.IdentityModel
public class IdentityModelHttpClientAuthenticator : IIdentityModelHttpClientAuthenticator, ITransientDependency public class IdentityModelHttpClientAuthenticator : IIdentityModelHttpClientAuthenticator, ITransientDependency
{ {
public ILogger<IdentityModelHttpClientAuthenticator> Logger { get; set; } public ILogger<IdentityModelHttpClientAuthenticator> Logger { get; set; }
protected IdentityClientOptions ClientOptions { get; } protected IdentityClientOptions ClientOptions { get; }
public IdentityModelHttpClientAuthenticator( public IdentityModelHttpClientAuthenticator(
@ -84,6 +83,8 @@ namespace Volo.Abp.IdentityModel
protected virtual async Task<TokenResponse> GetTokenResponse(DiscoveryResponse discoveryResponse, IdentityClientConfiguration configuration) protected virtual async Task<TokenResponse> GetTokenResponse(DiscoveryResponse discoveryResponse, IdentityClientConfiguration configuration)
{ {
//TODO: Pass cancellation token
var tokenClient = new TokenClient(discoveryResponse.TokenEndpoint, configuration.ClientId, configuration.ClientSecret); var tokenClient = new TokenClient(discoveryResponse.TokenEndpoint, configuration.ClientId, configuration.ClientSecret);
switch (configuration.GrantType) switch (configuration.GrantType)

44
framework/src/Volo.Abp.Security/System/Security/Principal/AbpClaimsIdentityExtensions.cs

@ -21,6 +21,21 @@ namespace System.Security.Principal
return Guid.Parse(userIdOrNull.Value); return Guid.Parse(userIdOrNull.Value);
} }
public static Guid? FindUserId([NotNull] this IIdentity identity)
{
Check.NotNull(identity, nameof(identity));
var claimsIdentity = identity as ClaimsIdentity;
var userIdOrNull = claimsIdentity?.Claims?.FirstOrDefault(c => c.Type == AbpClaimTypes.UserId);
if (userIdOrNull == null || userIdOrNull.Value.IsNullOrWhiteSpace())
{
return null;
}
return Guid.Parse(userIdOrNull.Value);
}
public static Guid? FindTenantId([NotNull] this ClaimsPrincipal principal) public static Guid? FindTenantId([NotNull] this ClaimsPrincipal principal)
{ {
Check.NotNull(principal, nameof(principal)); Check.NotNull(principal, nameof(principal));
@ -34,34 +49,47 @@ namespace System.Security.Principal
return Guid.Parse(tenantIdOrNull.Value); return Guid.Parse(tenantIdOrNull.Value);
} }
public static Guid? FindUserId([NotNull] this IIdentity identity) public static Guid? FindTenantId([NotNull] this IIdentity identity)
{ {
Check.NotNull(identity, nameof(identity)); Check.NotNull(identity, nameof(identity));
var claimsIdentity = identity as ClaimsIdentity; var claimsIdentity = identity as ClaimsIdentity;
var userIdOrNull = claimsIdentity?.Claims?.FirstOrDefault(c => c.Type == AbpClaimTypes.UserId); var tenantIdOrNull = claimsIdentity?.Claims?.FirstOrDefault(c => c.Type == AbpClaimTypes.TenantId);
if (userIdOrNull == null || userIdOrNull.Value.IsNullOrWhiteSpace()) if (tenantIdOrNull == null || tenantIdOrNull.Value.IsNullOrWhiteSpace())
{ {
return null; return null;
} }
return Guid.Parse(userIdOrNull.Value); return Guid.Parse(tenantIdOrNull.Value);
} }
public static Guid? FindTenantId([NotNull] this IIdentity identity) public static string FindClientId([NotNull] this ClaimsPrincipal principal)
{
Check.NotNull(principal, nameof(principal));
var clientIdOrNull = principal.Claims?.FirstOrDefault(c => c.Type == AbpClaimTypes.ClientId);
if (clientIdOrNull == null || clientIdOrNull.Value.IsNullOrWhiteSpace())
{
return null;
}
return clientIdOrNull.Value;
}
public static string FindClientId([NotNull] this IIdentity identity)
{ {
Check.NotNull(identity, nameof(identity)); Check.NotNull(identity, nameof(identity));
var claimsIdentity = identity as ClaimsIdentity; var claimsIdentity = identity as ClaimsIdentity;
var tenantIdOrNull = claimsIdentity?.Claims?.FirstOrDefault(c => c.Type == AbpClaimTypes.TenantId); var clientIdOrNull = claimsIdentity?.Claims?.FirstOrDefault(c => c.Type == AbpClaimTypes.ClientId);
if (tenantIdOrNull == null || tenantIdOrNull.Value.IsNullOrWhiteSpace()) if (clientIdOrNull == null || clientIdOrNull.Value.IsNullOrWhiteSpace())
{ {
return null; return null;
} }
return Guid.Parse(tenantIdOrNull.Value); return clientIdOrNull.Value;
} }
} }
} }

20
framework/src/Volo.Abp.Security/Volo/Abp/Clients/CurrentClient.cs

@ -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;
}
}
}

9
framework/src/Volo.Abp.Security/Volo/Abp/Clients/ICurrentClient.cs

@ -0,0 +1,9 @@
namespace Volo.Abp.Clients
{
public interface ICurrentClient
{
string Id { get; }
bool IsAuthenticated { get; }
}
}

5
framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/AbpClaimTypes.cs

@ -47,5 +47,10 @@ namespace Volo.Abp.Security.Claims
/// Default: "phone_number_verified". /// Default: "phone_number_verified".
/// </summary> /// </summary>
public static string TenantId { get; set; } = "tenantid"; public static string TenantId { get; set; } = "tenantid";
/// <summary>
/// Default: "client_id".
/// </summary>
public static string ClientId { get; set; } = "client_id";
} }
} }

6
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs

@ -2,10 +2,16 @@
{ {
public static class AuditLogConsts public static class AuditLogConsts
{ {
public const int MaxApplicationNameLength = 96;
public const int MaxClientIpAddressLength = 64; public const int MaxClientIpAddressLength = 64;
public const int MaxClientNameLength = 128; public const int MaxClientNameLength = 128;
public const int MaxClientIdLength = 64;
public const int MaxCorrelationIdLength = 64;
public const int MaxBrowserInfoLength = 512; public const int MaxBrowserInfoLength = 512;
public const int MaxExceptionsLength = 4000; public const int MaxExceptionsLength = 4000;

10
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Volo.Abp.Auditing; using Volo.Abp.Auditing;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
@ -12,6 +11,8 @@ namespace Volo.Abp.AuditLogging
[DisableAuditing] [DisableAuditing]
public class AuditLog : AggregateRoot<Guid>, IMultiTenant public class AuditLog : AggregateRoot<Guid>, IMultiTenant
{ {
public virtual string ApplicationName { get; set; }
public virtual Guid? UserId { get; protected set; } public virtual Guid? UserId { get; protected set; }
public virtual string UserName { get; protected set; } public virtual string UserName { get; protected set; }
@ -30,6 +31,10 @@ namespace Volo.Abp.AuditLogging
public virtual string ClientName { get; protected set; } public virtual string ClientName { get; protected set; }
public string ClientId { get; set; }
public string CorrelationId { get; set; }
public virtual string BrowserInfo { get; protected set; } public virtual string BrowserInfo { get; protected set; }
public virtual string HttpMethod { get; protected set; } public virtual string HttpMethod { get; protected set; }
@ -54,6 +59,7 @@ namespace Volo.Abp.AuditLogging
public AuditLog(IGuidGenerator guidGenerator, AuditLogInfo auditInfo) public AuditLog(IGuidGenerator guidGenerator, AuditLogInfo auditInfo)
{ {
Id = guidGenerator.Create(); Id = guidGenerator.Create();
ApplicationName = auditInfo.ApplicationName;
TenantId = auditInfo.TenantId; TenantId = auditInfo.TenantId;
UserId = auditInfo.UserId; UserId = auditInfo.UserId;
UserName = auditInfo.UserName.Truncate(AuditLogConsts.MaxUserNameLength); UserName = auditInfo.UserName.Truncate(AuditLogConsts.MaxUserNameLength);
@ -61,6 +67,8 @@ namespace Volo.Abp.AuditLogging
ExecutionDuration = auditInfo.ExecutionDuration; ExecutionDuration = auditInfo.ExecutionDuration;
ClientIpAddress = auditInfo.ClientIpAddress.Truncate(AuditLogConsts.MaxClientIpAddressLength); ClientIpAddress = auditInfo.ClientIpAddress.Truncate(AuditLogConsts.MaxClientIpAddressLength);
ClientName = auditInfo.ClientName.Truncate(AuditLogConsts.MaxClientNameLength); ClientName = auditInfo.ClientName.Truncate(AuditLogConsts.MaxClientNameLength);
ClientId = auditInfo.ClientId.Truncate(AuditLogConsts.MaxClientIdLength);
CorrelationId = auditInfo.CorrelationId.Truncate(AuditLogConsts.MaxCorrelationIdLength);
BrowserInfo = auditInfo.BrowserInfo.Truncate(AuditLogConsts.MaxBrowserInfoLength); BrowserInfo = auditInfo.BrowserInfo.Truncate(AuditLogConsts.MaxBrowserInfoLength);
HttpMethod = auditInfo.HttpMethod.Truncate(AuditLogConsts.MaxHttpMethodLength); HttpMethod = auditInfo.HttpMethod.Truncate(AuditLogConsts.MaxHttpMethodLength);
Url = auditInfo.Url.Truncate(AuditLogConsts.MaxUrlLength); Url = auditInfo.Url.Truncate(AuditLogConsts.MaxUrlLength);

3
modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs

@ -24,8 +24,11 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
b.ConfigureExtraProperties(); b.ConfigureExtraProperties();
b.Property(x => x.ApplicationName).HasMaxLength(AuditLogConsts.MaxApplicationNameLength).HasColumnName(nameof(AuditLog.ApplicationName));
b.Property(x => x.ClientIpAddress).HasMaxLength(AuditLogConsts.MaxClientIpAddressLength).HasColumnName(nameof(AuditLog.ClientIpAddress)); b.Property(x => x.ClientIpAddress).HasMaxLength(AuditLogConsts.MaxClientIpAddressLength).HasColumnName(nameof(AuditLog.ClientIpAddress));
b.Property(x => x.ClientName).HasMaxLength(AuditLogConsts.MaxClientNameLength).HasColumnName(nameof(AuditLog.ClientName)); b.Property(x => x.ClientName).HasMaxLength(AuditLogConsts.MaxClientNameLength).HasColumnName(nameof(AuditLog.ClientName));
b.Property(x => x.ClientId).HasMaxLength(AuditLogConsts.MaxClientIdLength).HasColumnName(nameof(AuditLog.ClientId));
b.Property(x => x.CorrelationId).HasMaxLength(AuditLogConsts.MaxCorrelationIdLength).HasColumnName(nameof(AuditLog.CorrelationId));
b.Property(x => x.BrowserInfo).HasMaxLength(AuditLogConsts.MaxBrowserInfoLength).HasColumnName(nameof(AuditLog.BrowserInfo)); b.Property(x => x.BrowserInfo).HasMaxLength(AuditLogConsts.MaxBrowserInfoLength).HasColumnName(nameof(AuditLog.BrowserInfo));
b.Property(x => x.HttpMethod).HasMaxLength(AuditLogConsts.MaxHttpMethodLength).HasColumnName(nameof(AuditLog.HttpMethod)); b.Property(x => x.HttpMethod).HasMaxLength(AuditLogConsts.MaxHttpMethodLength).HasColumnName(nameof(AuditLog.HttpMethod));
b.Property(x => x.Url).HasMaxLength(AuditLogConsts.MaxUrlLength).HasColumnName(nameof(AuditLog.Url)); b.Property(x => x.Url).HasMaxLength(AuditLogConsts.MaxUrlLength).HasColumnName(nameof(AuditLog.Url));

21
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs

@ -60,20 +60,19 @@ namespace Volo.Blogging.Posts
{ {
if (postDto.CreatorId.HasValue) if (postDto.CreatorId.HasValue)
{ {
var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value); if (!userDictionary.ContainsKey(postDto.CreatorId.Value))
if (creatorUser != null && !userDictionary.ContainsKey(creatorUser.Id))
{ {
userDictionary.Add(creatorUser.Id, ObjectMapper.Map<BlogUser, BlogUserDto>(creatorUser)); var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value);
if (creatorUser != null)
{
userDictionary[creatorUser.Id] = ObjectMapper.Map<BlogUser, BlogUserDto>(creatorUser);
}
} }
}
}
foreach (var postDto in postDtos) if (userDictionary.ContainsKey(postDto.CreatorId.Value))
{ {
if (postDto.CreatorId.HasValue && userDictionary.ContainsKey((Guid)postDto.CreatorId)) postDto.Writer = userDictionary[(Guid)postDto.CreatorId];
{ }
postDto.Writer = userDictionary[(Guid)postDto.CreatorId];
} }
} }

20
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/BloggingEntityFrameworkCoreQueryableExtensions.cs

@ -0,0 +1,20 @@
using Volo.Blogging.Posts;
using System.Linq;
using Microsoft.EntityFrameworkCore;
namespace Volo.Blogging
{
public static class BloggingEntityFrameworkCoreQueryableExtensions
{
public static IQueryable<Post> IncludeDetails(this IQueryable<Post> queryable, bool include = true)
{
if (!include)
{
return queryable;
}
return queryable
.Include(x => x.Tags);
}
}
}

6
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs

@ -7,6 +7,7 @@ using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Blogging.EntityFrameworkCore; using Volo.Blogging.EntityFrameworkCore;
using System.Linq.Dynamic.Core;
namespace Volo.Blogging.Posts namespace Volo.Blogging.Posts
{ {
@ -34,5 +35,10 @@ namespace Volo.Blogging.Posts
return post; return post;
} }
public override IQueryable<Post> WithDetails()
{
return GetQueryable().IncludeDetails();
}
} }
} }

2
modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs

@ -29,7 +29,7 @@ namespace Volo.Blogging
} }
[Fact] [Fact]
public async Task Should_Get_Fore_Reading() public async Task Should_Get_For_Reading()
{ {
var blogId = (await _blogRepository.GetListAsync()).First().Id; var blogId = (await _blogRepository.GetListAsync()).First().Id;
var post = (await _postRepository.GetListAsync()).First(p=>p.BlogId == blogId); var post = (await _postRepository.GetListAsync()).First(p=>p.BlogId == blogId);

3
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo.Abp.Identity.Application.Contracts.csproj

@ -19,9 +19,8 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Volo.Abp.Identity.Domain.Shared\Volo.Abp.Identity.Domain.Shared.csproj" /> <ProjectReference Include="..\Volo.Abp.Identity.Domain.Shared\Volo.Abp.Identity.Domain.Shared.csproj" />
<ProjectReference Include="..\..\..\permission-management\src\Volo.Abp.PermissionManagement.Application.Contracts\Volo.Abp.PermissionManagement.Application.Contracts.csproj" /> <ProjectReference Include="..\..\..\permission-management\src\Volo.Abp.PermissionManagement.Application.Contracts\Volo.Abp.PermissionManagement.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\users\src\Volo.Abp.Users.Abstractions\Volo.Abp.Users.Abstractions.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Authorization\Volo.Abp.Authorization.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Authorization\Volo.Abp.Authorization.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Ddd.Application\Volo.Abp.Ddd.Application.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Ddd.Application\Volo.Abp.Ddd.Application.csproj" />
</ItemGroup> </ItemGroup>

15
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/AbpIdentityApplicationContractsModule.cs

@ -1,19 +1,22 @@
using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Application;
using Volo.Abp.Application;
using Volo.Abp.Authorization; using Volo.Abp.Authorization;
using Volo.Abp.Authorization.Permissions; using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Identity.Localization; using Volo.Abp.Identity.Localization;
using Volo.Abp.Localization; using Volo.Abp.Localization;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement; using Volo.Abp.PermissionManagement;
using Volo.Abp.Users;
using Volo.Abp.VirtualFileSystem; using Volo.Abp.VirtualFileSystem;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity
{ {
[DependsOn(typeof(AbpIdentityDomainSharedModule))] [DependsOn(
[DependsOn(typeof(AbpAuthorizationModule))] typeof(AbpIdentityDomainSharedModule),
[DependsOn(typeof(AbpDddApplicationModule))] typeof(AbpUsersAbstractionModule),
[DependsOn(typeof(AbpPermissionManagementApplicationContractsModule))] typeof(AbpAuthorizationModule),
typeof(AbpDddApplicationModule),
typeof(AbpPermissionManagementApplicationContractsModule)
)]
public class AbpIdentityApplicationContractsModule : AbpModule public class AbpIdentityApplicationContractsModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)

14
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs

@ -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);
}
}

2
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityPermissionDefinitionProvider.cs

@ -21,6 +21,8 @@ namespace Volo.Abp.Identity
usersPermission.AddChild(IdentityPermissions.Users.Update, L("Permission:Edit")); usersPermission.AddChild(IdentityPermissions.Users.Update, L("Permission:Edit"));
usersPermission.AddChild(IdentityPermissions.Users.Delete, L("Permission:Delete")); usersPermission.AddChild(IdentityPermissions.Users.Delete, L("Permission:Delete"));
usersPermission.AddChild(IdentityPermissions.Users.ManagePermissions, L("Permission:ChangePermissions")); usersPermission.AddChild(IdentityPermissions.Users.ManagePermissions, L("Permission:ChangePermissions"));
identityGroup.AddPermission(IdentityPermissions.UserLookup.Default, L("Permission:UserLookup"));
} }
private static LocalizableString L(string name) private static LocalizableString L(string name)

8
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityPermissions.cs

@ -22,6 +22,11 @@
public const string ManagePermissions = Default + ".ManagePermissions"; public const string ManagePermissions = Default + ".ManagePermissions";
} }
public static class UserLookup
{
public const string Default = GroupName + ".UserLookup";
}
public static string[] GetAll() public static string[] GetAll()
{ {
return new[] return new[]
@ -36,7 +41,8 @@
Users.Create, Users.Create,
Users.Update, Users.Update,
Users.Delete, Users.Delete,
Users.ManagePermissions Users.ManagePermissions,
UserLookup.Default
}; };
} }
} }

3
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/en.json

@ -7,6 +7,7 @@
"Permission:Edit": "Edit", "Permission:Edit": "Edit",
"Permission:Delete": "Delete", "Permission:Delete": "Delete",
"Permission:ChangePermissions": "Change permissions", "Permission:ChangePermissions": "Change permissions",
"Permission:UserManagement": "User management" "Permission:UserManagement": "User management",
"Permission:UserLookup": "User lookup"
} }
} }

6
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/pt-BR.json

@ -1,12 +1,12 @@
{ {
"culture": "pt-BR", "culture": "pt-BR",
"texts": { "texts": {
"Permission:IdentityManagement": "Gerenciamento de Acessos", "Permission:IdentityManagement": "Acessos",
"Permission:RoleManagement": "Gerenciamento de Perfis", "Permission:RoleManagement": "Perfis",
"Permission:Create": "Criar", "Permission:Create": "Criar",
"Permission:Edit": "Editar", "Permission:Edit": "Editar",
"Permission:Delete": "Excluir", "Permission:Delete": "Excluir",
"Permission:ChangePermissions": "Alterar Permissões", "Permission:ChangePermissions": "Alterar Permissões",
"Permission:UserManagement": "Gerenciamento de Usuários" "Permission:UserManagement": "Usuários"
} }
} }

3
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/tr.json

@ -7,6 +7,7 @@
"Permission:Edit": "Düzenleme", "Permission:Edit": "Düzenleme",
"Permission:Delete": "Silme", "Permission:Delete": "Silme",
"Permission:ChangePermissions": "İzinleri değiştirme", "Permission:ChangePermissions": "İzinleri değiştirme",
"Permission:UserManagement": "Kullanıcı yönetimi" "Permission:UserManagement": "Kullanıcı yönetimi",
"Permission:UserLookup": "Kullanıcı sorgulama"
} }
} }

41
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs

@ -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);
}
}
}

4
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs

@ -30,7 +30,7 @@ namespace Volo.Abp.Identity
includeDetails: false, includeDetails: false,
cancellationToken: cancellationToken cancellationToken: cancellationToken
) )
).ToAbpUserData(); )?.ToAbpUserData();
} }
public async Task<IUserData> FindByUserNameAsync( public async Task<IUserData> FindByUserNameAsync(
@ -43,7 +43,7 @@ namespace Volo.Abp.Identity
includeDetails: false, includeDetails: false,
cancellationToken: cancellationToken cancellationToken: cancellationToken
) )
).ToAbpUserData(); )?.ToAbpUserData();
} }
} }
} }

3
modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj

@ -15,9 +15,6 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Volo.Abp.Identity.Application.Contracts\Volo.Abp.Identity.Application.Contracts.csproj" /> <ProjectReference Include="..\Volo.Abp.Identity.Application.Contracts\Volo.Abp.Identity.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\users\src\Volo.Abp.Users.Abstractions\Volo.Abp.Users.Abstractions.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Http.Client\Volo.Abp.Http.Client.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Http.Client\Volo.Abp.Http.Client.csproj" />
</ItemGroup> </ItemGroup>

2
modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/AbpIdentityHttpApiClientModule.cs

@ -1,13 +1,11 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Http.Client; using Volo.Abp.Http.Client;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Users;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity
{ {
[DependsOn( [DependsOn(
typeof(AbpIdentityApplicationContractsModule), typeof(AbpIdentityApplicationContractsModule),
typeof(AbpUsersAbstractionModule),
typeof(AbpHttpClientModule))] typeof(AbpHttpClientModule))]
public class AbpIdentityHttpApiClientModule : AbpModule public class AbpIdentityHttpApiClientModule : AbpModule
{ {

14
modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs

@ -1,5 +1,4 @@
using System; using System;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -10,24 +9,21 @@ namespace Volo.Abp.Identity
[Dependency(TryRegister = true)] [Dependency(TryRegister = true)]
public class HttpClientExternalUserLookupServiceProvider : IExternalUserLookupServiceProvider, ITransientDependency public class HttpClientExternalUserLookupServiceProvider : IExternalUserLookupServiceProvider, ITransientDependency
{ {
private readonly IIdentityUserAppService _userAppService; private readonly IIdentityUserLookupAppService _userLookupAppService;
public HttpClientExternalUserLookupServiceProvider(IIdentityUserAppService userAppService) public HttpClientExternalUserLookupServiceProvider(IIdentityUserLookupAppService userLookupAppService)
{ {
_userAppService = userAppService; _userLookupAppService = userLookupAppService;
} }
public async Task<IUserData> FindByIdAsync(Guid id, CancellationToken cancellationToken = default) public async Task<IUserData> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{ {
//TODO: Should return null if not found! return await _userLookupAppService.FindByIdAsync(id);
return (await _userAppService.GetAsync(id)).ToUserInfo();
} }
public async Task<IUserData> FindByUserNameAsync(string userName, CancellationToken cancellationToken = default) public async Task<IUserData> FindByUserNameAsync(string userName, CancellationToken cancellationToken = default)
{ {
//TODO: Should return null if not found! return await _userLookupAppService.FindByUserNameAsync(userName);
//TODO: Search by UserName, not by a general filter!
return (await _userAppService.GetListAsync(new GetIdentityUsersInput { Filter = userName })).Items.FirstOrDefault()?.ToUserInfo();
} }
} }
} }

36
modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs

@ -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);
}
}
}

2
modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/pt-BR.json

@ -1,7 +1,7 @@
{ {
"culture": "pt-BR", "culture": "pt-BR",
"texts": { "texts": {
"Menu:IdentityManagement": "Gerenciamento de Acessos", "Menu:IdentityManagement": "Acessos",
"Users": "Usuários", "Users": "Usuários",
"NewUser": "Novo Usuário", "NewUser": "Novo Usuário",
"UserName": "Usuário", "UserName": "Usuário",

2
modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RolePermissionManagementProvider.cs

@ -36,7 +36,7 @@ namespace Volo.Abp.PermissionManagement.Identity
); );
} }
if (providerName == "User") if (providerName == UserPermissionValueProvider.ProviderName)
{ {
var userId = Guid.Parse(providerKey); var userId = Guid.Parse(providerKey);
var roleNames = await _userRoleFinder.GetRolesAsync(userId); var roleNames = await _userRoleFinder.GetRolesAsync(userId);

4
modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/UserPermissionManagementProvider.cs

@ -8,8 +8,8 @@ namespace Volo.Abp.PermissionManagement.Identity
{ {
public override string Name => UserPermissionValueProvider.ProviderName; public override string Name => UserPermissionValueProvider.ProviderName;
public UserPermissionManagementProvider(IPermissionGrantRepository public UserPermissionManagementProvider(
permissionGrantRepository, IPermissionGrantRepository permissionGrantRepository,
IGuidGenerator guidGenerator, IGuidGenerator guidGenerator,
ICurrentTenant currentTenant) ICurrentTenant currentTenant)
: base( : base(

9
modules/identityserver/Volo.Abp.IdentityServer.sln

@ -21,7 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.IdentityServer.Tes
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.IdentityServer.MongoDB.Tests", "test\Volo.Abp.IdentityServer.MongoDB.Tests\Volo.Abp.IdentityServer.MongoDB.Tests.csproj", "{2E18B471-7FCA-497B-90FF-6AA9172CC62F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.IdentityServer.MongoDB.Tests", "test\Volo.Abp.IdentityServer.MongoDB.Tests\Volo.Abp.IdentityServer.MongoDB.Tests.csproj", "{2E18B471-7FCA-497B-90FF-6AA9172CC62F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.IdentityServer.Domain.Tests", "test\Volo.Abp.IdentityServer.Domain.Tests\Volo.Abp.IdentityServer.Domain.Tests.csproj", "{0680D0B6-51C0-4812-8A0B-192FDE717E60}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.IdentityServer.Domain.Tests", "test\Volo.Abp.IdentityServer.Domain.Tests\Volo.Abp.IdentityServer.Domain.Tests.csproj", "{0680D0B6-51C0-4812-8A0B-192FDE717E60}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.PermissionManagement.Domain.IdentityServer", "src\Volo.Abp.PermissionManagement.Domain.IdentityServer\Volo.Abp.PermissionManagement.Domain.IdentityServer.csproj", "{072BD630-FB89-45FC-BA2D-12A9745AAB93}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -61,6 +63,10 @@ Global
{0680D0B6-51C0-4812-8A0B-192FDE717E60}.Debug|Any CPU.Build.0 = Debug|Any CPU {0680D0B6-51C0-4812-8A0B-192FDE717E60}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0680D0B6-51C0-4812-8A0B-192FDE717E60}.Release|Any CPU.ActiveCfg = Release|Any CPU {0680D0B6-51C0-4812-8A0B-192FDE717E60}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0680D0B6-51C0-4812-8A0B-192FDE717E60}.Release|Any CPU.Build.0 = Release|Any CPU {0680D0B6-51C0-4812-8A0B-192FDE717E60}.Release|Any CPU.Build.0 = Release|Any CPU
{072BD630-FB89-45FC-BA2D-12A9745AAB93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{072BD630-FB89-45FC-BA2D-12A9745AAB93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{072BD630-FB89-45FC-BA2D-12A9745AAB93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{072BD630-FB89-45FC-BA2D-12A9745AAB93}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -74,6 +80,7 @@ Global
{9CD1BFDB-DD76-4194-ACAD-A64541AC2069} = {2C792EC1-BA27-44ED-B7CC-D0939553F1B2} {9CD1BFDB-DD76-4194-ACAD-A64541AC2069} = {2C792EC1-BA27-44ED-B7CC-D0939553F1B2}
{2E18B471-7FCA-497B-90FF-6AA9172CC62F} = {2C792EC1-BA27-44ED-B7CC-D0939553F1B2} {2E18B471-7FCA-497B-90FF-6AA9172CC62F} = {2C792EC1-BA27-44ED-B7CC-D0939553F1B2}
{0680D0B6-51C0-4812-8A0B-192FDE717E60} = {2C792EC1-BA27-44ED-B7CC-D0939553F1B2} {0680D0B6-51C0-4812-8A0B-192FDE717E60} = {2C792EC1-BA27-44ED-B7CC-D0939553F1B2}
{072BD630-FB89-45FC-BA2D-12A9745AAB93} = {59A0FC0F-EA6D-477B-84A7-3B1E41B4C858}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {45562023-C330-4060-A583-2BA10F472D3D} SolutionGuid = {45562023-C330-4060-A583-2BA10F472D3D}

21
modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo.Abp.PermissionManagement.Domain.IdentityServer.csproj

@ -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>

18
modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs

@ -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";
});
}
}
}

23
modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/ClientPermissionManagementProvider.cs

@ -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)
{
}
}
}

22
modules/permission-management/src/Volo.Abp.PermissionManagement.Application/Volo/Abp/PermissionManagement/PermissionAppService.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
@ -51,6 +52,11 @@ namespace Volo.Abp.PermissionManagement
foreach (var permission in group.GetPermissionsWithChildren()) foreach (var permission in group.GetPermissionsWithChildren())
{ {
if (permission.Providers.Any() && !permission.Providers.Contains(providerName))
{
continue;
}
var grantInfoDto = new PermissionGrantInfoDto var grantInfoDto = new PermissionGrantInfoDto
{ {
Name = permission.Name, Name = permission.Name,
@ -75,7 +81,10 @@ namespace Volo.Abp.PermissionManagement
groupDto.Permissions.Add(grantInfoDto); groupDto.Permissions.Add(grantInfoDto);
} }
result.Groups.Add(groupDto); if (groupDto.Permissions.Any())
{
result.Groups.Add(groupDto);
}
} }
return result; return result;
@ -85,9 +94,16 @@ namespace Volo.Abp.PermissionManagement
{ {
await CheckProviderPolicy(providerName); await CheckProviderPolicy(providerName);
foreach (var permission in input.Permissions) foreach (var permissionDto in input.Permissions)
{ {
await _permissionManager.SetAsync(permission.Name, providerName, providerKey, permission.IsGranted); var permissionDefinition = _permissionDefinitionManager.Get(permissionDto.Name);
if (permissionDefinition.Providers.Any() &&
!permissionDefinition.Providers.Contains(providerName))
{
throw new ApplicationException($"The permission named '{permissionDto.Name}' has not compatible with the provider named '{providerName}'");
}
await _permissionManager.SetAsync(permissionDto.Name, providerName, providerKey, permissionDto.IsGranted);
} }
} }

2
modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/Localization/ApplicationContracts/pt-BR.json

@ -1,7 +1,7 @@
{ {
"culture": "pt-BR", "culture": "pt-BR",
"texts": { "texts": {
"Permission:TenantManagement": "Gerenciamento de Inquilinos", "Permission:TenantManagement": "Inquilinos",
"Permission:Create": "Criar", "Permission:Create": "Criar",
"Permission:Edit": "Editar", "Permission:Edit": "Editar",
"Permission:Delete": "Excluir" "Permission:Delete": "Excluir"

13
modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserData.cs

@ -28,6 +28,19 @@ namespace Volo.Abp.Users
} }
public UserData(IUserData userData)
{
Id = userData.Id;
UserName = userData.UserName;
Email = userData.Email;
Name = userData.Name;
Surname = userData.Surname;
EmailConfirmed = userData.EmailConfirmed;
PhoneNumber = userData.PhoneNumber;
PhoneNumberConfirmed = userData.PhoneNumberConfirmed;
TenantId = userData.TenantId;
}
public UserData( public UserData(
Guid id, Guid id,
[NotNull] string userName, [NotNull] string userName,

1
nupkg/common.ps1

@ -140,6 +140,7 @@ $projects = (
# modules/identityserver # modules/identityserver
"modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared", "modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared",
"modules/identityserver/src/Volo.Abp.IdentityServer.Domain", "modules/identityserver/src/Volo.Abp.IdentityServer.Domain",
"modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer",
"modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore", "modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore",
"modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB", "modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB",

7
samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerHostModule.cs

@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Account.Web; using Volo.Abp.Account.Web;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.Auditing;
using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Authorization.Permissions; using Volo.Abp.Authorization.Permissions;
using Volo.Abp.EventBus.RabbitMq; using Volo.Abp.EventBus.RabbitMq;
@ -60,6 +61,12 @@ namespace AuthServer.Host
{ {
options.Configuration = configuration["Redis:Configuration"]; options.Configuration = configuration["Redis:Configuration"];
}); });
Configure<AbpAuditingOptions>(options =>
{
options.IsEnabledForGetRequests = true;
options.ApplicationName = "AuthServer";
});
} }
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)

1150
samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190208210234_Added_ClientId_And_CorrelationId_To_AuditLogs.Designer.cs

File diff suppressed because it is too large

72
samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190208210234_Added_ClientId_And_CorrelationId_To_AuditLogs.cs

@ -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" }
);
}
}
}

1154
samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190209193341_Added_ApplicationName_To_AuditLogs.Designer.cs

File diff suppressed because it is too large

23
samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190209193341_Added_ApplicationName_To_AuditLogs.cs

@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace AuthServer.Host.Migrations
{
public partial class Added_ApplicationName_To_AuditLogs : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "ApplicationName",
table: "AbpAuditLogs",
maxLength: 96,
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ApplicationName",
table: "AbpAuditLogs");
}
}
}

14
samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/AuthServerDbContextModelSnapshot.cs

@ -24,10 +24,18 @@ namespace AuthServer.Host.Migrations
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd(); .ValueGeneratedOnAdd();
b.Property<string>("ApplicationName")
.HasColumnName("ApplicationName")
.HasMaxLength(96);
b.Property<string>("BrowserInfo") b.Property<string>("BrowserInfo")
.HasColumnName("BrowserInfo") .HasColumnName("BrowserInfo")
.HasMaxLength(512); .HasMaxLength(512);
b.Property<string>("ClientId")
.HasColumnName("ClientId")
.HasMaxLength(64);
b.Property<string>("ClientIpAddress") b.Property<string>("ClientIpAddress")
.HasColumnName("ClientIpAddress") .HasColumnName("ClientIpAddress")
.HasMaxLength(64); .HasMaxLength(64);
@ -42,6 +50,10 @@ namespace AuthServer.Host.Migrations
b.Property<string>("ConcurrencyStamp"); b.Property<string>("ConcurrencyStamp");
b.Property<string>("CorrelationId")
.HasColumnName("CorrelationId")
.HasMaxLength(64);
b.Property<string>("Exceptions") b.Property<string>("Exceptions")
.HasColumnName("Exceptions") .HasColumnName("Exceptions")
.HasMaxLength(4000); .HasMaxLength(4000);
@ -753,7 +765,7 @@ namespace AuthServer.Host.Migrations
b.Property<Guid>("ClientId"); b.Property<Guid>("ClientId");
b.Property<string>("PostLogoutRedirectUri") b.Property<string>("PostLogoutRedirectUri")
.HasMaxLength(2000); .HasMaxLength(200);
b.HasKey("ClientId", "PostLogoutRedirectUri"); b.HasKey("ClientId", "PostLogoutRedirectUri");

BIN
samples/MicroserviceDemo/databases/MsDemo_Identity.zip

Binary file not shown.

1
samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGateway.Host.csproj

@ -27,6 +27,7 @@
<ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.Identity.HttpApi\Volo.Abp.Identity.HttpApi.csproj" /> <ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.Identity.HttpApi\Volo.Abp.Identity.HttpApi.csproj" />
<ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.Identity.HttpApi.Client\Volo.Abp.Identity.HttpApi.Client.csproj" /> <ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.Identity.HttpApi.Client\Volo.Abp.Identity.HttpApi.Client.csproj" />
<ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.PermissionManagement.Domain.Identity\Volo.Abp.PermissionManagement.Domain.Identity.csproj" /> <ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.PermissionManagement.Domain.Identity\Volo.Abp.PermissionManagement.Domain.Identity.csproj" />
<ProjectReference Include="..\..\..\..\modules\identityserver\src\Volo.Abp.PermissionManagement.Domain.IdentityServer\Volo.Abp.PermissionManagement.Domain.IdentityServer.csproj" />
<ProjectReference Include="..\..\..\..\modules\permission-management\src\Volo.Abp.PermissionManagement.Application\Volo.Abp.PermissionManagement.Application.csproj" /> <ProjectReference Include="..\..\..\..\modules\permission-management\src\Volo.Abp.PermissionManagement.Application\Volo.Abp.PermissionManagement.Application.csproj" />
<ProjectReference Include="..\..\..\..\modules\permission-management\src\Volo.Abp.PermissionManagement.HttpApi\Volo.Abp.PermissionManagement.HttpApi.csproj" /> <ProjectReference Include="..\..\..\..\modules\permission-management\src\Volo.Abp.PermissionManagement.HttpApi\Volo.Abp.PermissionManagement.HttpApi.csproj" />
<ProjectReference Include="..\..\..\..\modules\permission-management\src\Volo.Abp.PermissionManagement.EntityFrameworkCore\Volo.Abp.PermissionManagement.EntityFrameworkCore.csproj" /> <ProjectReference Include="..\..\..\..\modules\permission-management\src\Volo.Abp.PermissionManagement.EntityFrameworkCore\Volo.Abp.PermissionManagement.EntityFrameworkCore.csproj" />

4
samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGatewayHostModule.cs

@ -14,6 +14,7 @@ using Volo.Abp.PermissionManagement;
using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.PermissionManagement.HttpApi; using Volo.Abp.PermissionManagement.HttpApi;
using Volo.Abp.PermissionManagement.Identity; using Volo.Abp.PermissionManagement.Identity;
using Volo.Abp.PermissionManagement.IdentityServer;
using Volo.Abp.Security.Claims; using Volo.Abp.Security.Claims;
using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Blogging; using Volo.Blogging;
@ -31,7 +32,8 @@ namespace BackendAdminAppGateway.Host
typeof(AbpPermissionManagementHttpApiModule), typeof(AbpPermissionManagementHttpApiModule),
typeof(AbpSettingManagementEntityFrameworkCoreModule), typeof(AbpSettingManagementEntityFrameworkCoreModule),
typeof(BloggingApplicationContractsModule), typeof(BloggingApplicationContractsModule),
typeof(AbpPermissionManagementDomainIdentityModule) typeof(AbpPermissionManagementDomainIdentityModule),
typeof(AbpPermissionManagementDomainIdentityServerModule)
)] )]
public class BackendAdminAppGatewayHostModule : AbpModule public class BackendAdminAppGatewayHostModule : AbpModule
{ {

7
samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingServiceHostModule.cs

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.Swagger;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Autofac; using Volo.Abp.Autofac;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
@ -80,6 +81,12 @@ namespace BloggingService.Host
{ {
options.Configuration = configuration["Redis:Configuration"]; options.Configuration = configuration["Redis:Configuration"];
}); });
Configure<AbpAuditingOptions>(options =>
{
options.IsEnabledForGetRequests = true;
options.ApplicationName = "BloggingService";
});
} }
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)

12
samples/MicroserviceDemo/microservices/BloggingService.Host/appsettings.json

@ -9,7 +9,17 @@
}, },
"RemoteServices": { "RemoteServices": {
"Default": { "Default": {
"BaseUrl": "http://localhost:65129/" "BaseUrl": "http://localhost:65129/",
"UseCurrentAccessToken": "false"
}
},
"IdentityClients": {
"Default": {
"GrantType": "client_credentials",
"ClientId": "blogging-service-client",
"ClientSecret": "1q2w3e*",
"Authority": "http://localhost:64999",
"Scope": "InternalGateway IdentityService"
} }
}, },
"Redis": { "Redis": {

7
samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityServiceHostModule.cs

@ -2,6 +2,7 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.Swagger;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Autofac; using Volo.Abp.Autofac;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
@ -71,6 +72,12 @@ namespace IdentityService.Host
{ {
options.Configuration = configuration["Redis:Configuration"]; options.Configuration = configuration["Redis:Configuration"];
}); });
Configure<AbpAuditingOptions>(options =>
{
options.IsEnabledForGetRequests = true;
options.ApplicationName = "IdentityService";
});
} }
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)

1
samples/MicroserviceDemo/microservices/ProductService.Host/ProductService.Host.csproj

@ -41,6 +41,7 @@
<ItemGroup> <ItemGroup>
<Compile Remove="Migrations\20190121115804_Initial.cs" /> <Compile Remove="Migrations\20190121115804_Initial.cs" />
<Compile Remove="Migrations\20190209193421_Added_ApplicationName_To_AuditLogs.cs" />
</ItemGroup> </ItemGroup>
</Project> </Project>

7
samples/MicroserviceDemo/microservices/ProductService.Host/ProductServiceHostModule.cs

@ -4,6 +4,7 @@ using ProductManagement;
using ProductManagement.EntityFrameworkCore; using ProductManagement.EntityFrameworkCore;
using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.Swagger;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Autofac; using Volo.Abp.Autofac;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
@ -71,6 +72,12 @@ namespace ProductService.Host
{ {
options.Configuration = configuration["Redis:Configuration"]; options.Configuration = configuration["Redis:Configuration"];
}); });
Configure<AbpAuditingOptions>(options =>
{
options.IsEnabledForGetRequests = true;
options.ApplicationName = "ProductService";
});
} }
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)

Loading…
Cancel
Save