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>
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>
/// Default: true.
/// </summary>

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

@ -10,6 +10,8 @@ namespace Volo.Abp.Auditing
//TODO: Make serializable!
public class AuditLogInfo : IMultiTenant, IHasExtraProperties
{
public string ApplicationName { get; set; }
public Guid? UserId { get; set; }
public string UserName { get; set; }
@ -24,6 +26,10 @@ namespace Volo.Abp.Auditing
public int ExecutionDuration { get; set; }
public string ClientId { get; set; }
public string CorrelationId { get; set; }
public string ClientIpAddress { 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.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.Clients;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Timing;
using Volo.Abp.Tracing;
using Volo.Abp.Users;
namespace Volo.Abp.Auditing
@ -18,30 +20,36 @@ namespace Volo.Abp.Auditing
protected IAuditingStore AuditingStore { get; }
protected ICurrentUser CurrentUser { get; }
protected ICurrentTenant CurrentTenant { get; }
protected ICurrentClient CurrentClient { get; }
protected IClock Clock { get; }
protected AbpAuditingOptions Options;
protected IAuditSerializer AuditSerializer;
protected IServiceProvider ServiceProvider;
protected ICorrelationIdProvider CorrelationIdProvider { get; }
public AuditingHelper(
IAuditSerializer auditSerializer,
IOptions<AbpAuditingOptions> options,
ICurrentUser currentUser,
ICurrentTenant currentTenant,
ICurrentClient currentClient,
IClock clock,
IAuditingStore auditingStore,
ILogger<AuditingHelper> logger,
IServiceProvider serviceProvider)
IServiceProvider serviceProvider,
ICorrelationIdProvider correlationIdProvider)
{
Options = options.Value;
AuditSerializer = auditSerializer;
CurrentUser = currentUser;
CurrentTenant = currentTenant;
CurrentClient = currentClient;
Clock = clock;
AuditingStore = auditingStore;
Logger = logger;
ServiceProvider = serviceProvider;
CorrelationIdProvider = correlationIdProvider;
}
public virtual bool ShouldSaveAudit(MethodInfo methodInfo, bool defaultValue = false)
@ -82,9 +90,12 @@ namespace Volo.Abp.Auditing
{
var auditInfo = new AuditLogInfo
{
ApplicationName = Options.ApplicationName,
TenantId = CurrentTenant.Id,
UserId = CurrentUser.Id,
UserName = CurrentUser.UserName,
ClientId = CurrentClient.Id,
CorrelationId = CorrelationIdProvider.Get(),
//ImpersonatorUserId = AbpSession.ImpersonatorUserId, //TODO: Impersonation system is not available yet!
//ImpersonatorTenantId = AbpSession.ImpersonatorTenantId,
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<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.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Clients;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Users;
@ -10,11 +11,16 @@ namespace Volo.Abp.Authorization
{
private readonly IAuthorizationService _authorizationService;
private readonly ICurrentUser _currentUser;
private readonly ICurrentClient _currentClient;
public MethodInvocationAuthorizationService(IAuthorizationService authorizationService, ICurrentUser currentUser)
public MethodInvocationAuthorizationService(
IAuthorizationService authorizationService,
ICurrentUser currentUser,
ICurrentClient currentClient)
{
_authorizationService = authorizationService;
_currentUser = currentUser;
_currentClient = currentClient;
}
public async Task CheckAsync(MethodInvocationAuthorizationContext context)
@ -53,7 +59,8 @@ namespace Volo.Abp.Authorization
{
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.");
}

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.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Security.Claims;
@ -40,7 +40,7 @@ namespace Volo.Abp.Authorization.Permissions
true
);
}
public virtual Task<PermissionGrantInfo> CheckAsync(string name)
{
return CheckAsync(PrincipalAccessor.Principal, name);
@ -57,6 +57,12 @@ namespace Volo.Abp.Authorization.Permissions
foreach (var provider in ValueProviders)
{
if (context.Permission.Providers.Any() &&
!context.Permission.Providers.Contains(provider.Name))
{
continue;
}
var result = await provider.CheckAsync(context);
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>
public PermissionDefinition Parent { get; private set; }
public List<string> Providers { get; }
public ILocalizableString DisplayName
{
get => _displayName;
@ -53,6 +55,7 @@ namespace Volo.Abp.Authorization.Permissions
DisplayName = displayName ?? new FixedLocalizableString(name);
Properties = new Dictionary<string, object>();
Providers = new List<string>();
_children = new List<PermissionDefinition>();
}
@ -68,6 +71,30 @@ namespace Volo.Abp.Authorization.Permissions
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()
{
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.Reflection;
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/
/// <summary>
/// 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>
//Inspired from https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/microservice-ddd-cqrs-patterns/implement-value-objects
public abstract class ValueObject
{
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 ReferenceEquals(left, null) || left.Equals(right);
}
var publicProperties = GetType().GetTypeInfo().GetProperties();
if (!publicProperties.Any())
{
return true;
}
return publicProperties.All(property => Equals(property.GetValue(this, null), property.GetValue(other, null)));
protected static bool NotEqualOperator(ValueObject left, ValueObject right)
{
return !(EqualOperator(left, right));
}
protected abstract IEnumerable<object> GetAtomicValues();
public override bool Equals(object obj)
{
if (obj == null)
if (obj == null || obj.GetType() != GetType())
{
return false;
}
var item = obj as ValueObject<TValueObject>;
return (object)item != null && Equals((TValueObject)item);
}
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())
ValueObject other = (ValueObject)obj;
IEnumerator<object> thisValues = GetAtomicValues().GetEnumerator();
IEnumerator<object> otherValues = other.GetAtomicValues().GetEnumerator();
while (thisValues.MoveNext() && otherValues.MoveNext())
{
return initialHasCode;
}
var hashCode = initialHasCode;
var changeMultiplier = false;
foreach (var property in publicProperties)
{
var value = property.GetValue(this, null);
if (value == null)
if (ReferenceEquals(thisValues.Current, null) ^
ReferenceEquals(otherValues.Current, null))
{
//support {"a",null,null,"a"} != {null,"a","a",null}
hashCode = hashCode ^ (index * 13);
continue;
return false;
}
hashCode = hashCode * (changeMultiplier ? 59 : 114) + value.GetHashCode();
changeMultiplier = !changeMultiplier;
}
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;
if (thisValues.Current != null &&
!thisValues.Current.Equals(otherValues.Current))
{
return false;
}
}
return x.Equals(y);
return !thisValues.MoveNext() && !otherValues.MoveNext();
}
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)
{
var accessToken = await GetAccessTokenFromHttpContextOrNullAsync();
if (accessToken != null)
{
context.Client.SetBearerToken(accessToken);
}
else
if (context.RemoteService.GetUseCurrentAccessToken() != false)
{
await IdentityModelHttpClientAuthenticator.AuthenticateAsync(
new IdentityModelHttpClientAuthenticateContext(
context.Client,
context.RemoteService.GetIdentityClient()
)
);
var accessToken = await GetAccessTokenFromHttpContextOrNullAsync();
if (accessToken != null)
{
context.Client.SetBearerToken(accessToken);
return;
}
}
await IdentityModelHttpClientAuthenticator.AuthenticateAsync(
context.Client,
context.RemoteService.GetIdentityClient()
);
}
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;
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 const string IdentityClient = "IdentityClient";
public const string IdentityClientName = "IdentityClient";
public const string UseCurrentAccessTokenName = "UseCurrentAccessToken";
[CanBeNull]
public static string GetIdentityClient([NotNull] this RemoteServiceConfiguration 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)
{
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;
}
}

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

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

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

@ -1,17 +1,20 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Castle;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace Volo.Abp.Http.Client
{
[DependsOn(typeof(AbpHttpModule))]
[DependsOn(typeof(AbpCastleCoreModule))]
[DependsOn(
typeof(AbpHttpModule),
typeof(AbpCastleCoreModule),
typeof(AbpThreadingModule)
)]
public class AbpHttpClientModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
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 string RemoteServiceName { get; }
public RemoteServiceHttpClientAuthenticateContext(
HttpClient client,
HttpRequestMessage request,
RemoteServiceConfiguration remoteService)
RemoteServiceConfiguration remoteService,
string remoteServiceName)
{
Client = client;
Request = request;
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.Net.Http;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
@ -15,21 +16,25 @@ using Volo.Abp.Http.ProxyScripting.Generators;
using Volo.Abp.Json;
using Volo.Abp.Reflection;
using Volo.Abp.Threading;
using Volo.Abp.Tracing;
namespace Volo.Abp.Http.Client.DynamicProxying
{
//TODO: Somehow capture cancellationtoken and pass to other methods...?
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; }
@ -46,14 +51,20 @@ namespace Volo.Abp.Http.Client.DynamicProxying
IOptionsSnapshot<RemoteServiceOptions> remoteServiceOptions,
IApiDescriptionFinder apiDescriptionFinder,
IJsonSerializer jsonSerializer,
IRemoteServiceHttpClientAuthenticator clientAuthenticator)
IRemoteServiceHttpClientAuthenticator clientAuthenticator,
ICancellationTokenProvider cancellationTokenProvider,
ICorrelationIdProvider correlationIdProvider,
IOptions<CorrelationIdOptions> correlationIdOptions)
{
_httpClientFactory = httpClientFactory;
_apiDescriptionFinder = apiDescriptionFinder;
_jsonSerializer = jsonSerializer;
_clientAuthenticator = clientAuthenticator;
_clientOptions = clientOptions.Value;
_remoteServiceOptions = remoteServiceOptions.Value;
CancellationTokenProvider = cancellationTokenProvider;
CorrelationIdProvider = correlationIdProvider;
CorrelationIdOptions = correlationIdOptions.Value;
HttpClientFactory = httpClientFactory;
ApiDescriptionFinder = apiDescriptionFinder;
JsonSerializer = jsonSerializer;
ClientAuthenticator = clientAuthenticator;
ClientOptions = clientOptions.Value;
RemoteServiceOptions = remoteServiceOptions.Value;
Logger = NullLogger<DynamicHttpProxyInterceptor<TService>>.Instance;
}
@ -62,11 +73,11 @@ namespace Volo.Abp.Http.Client.DynamicProxying
{
if (invocation.Method.ReturnType == typeof(void))
{
AsyncHelper.RunSync(() => MakeRequest(invocation));
AsyncHelper.RunSync(() => MakeRequestAsync(invocation));
}
else
{
var responseAsString = AsyncHelper.RunSync(() => MakeRequest(invocation));
var responseAsString = AsyncHelper.RunSync(() => MakeRequestAsync(invocation));
//TODO: Think on that
if (TypeHelper.IsPrimitiveExtended(invocation.Method.ReturnType, true))
@ -75,7 +86,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying
}
else
{
invocation.ReturnValue = _jsonSerializer.Deserialize(
invocation.ReturnValue = JsonSerializer.Deserialize(
invocation.Method.ReturnType,
responseAsString
);
@ -87,7 +98,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying
{
if (invocation.Method.ReturnType.GenericTypeArguments.IsNullOrEmpty())
{
return MakeRequest(invocation);
return MakeRequestAsync(invocation);
}
invocation.ReturnValue = GenericInterceptAsyncMethod
@ -99,7 +110,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying
private async Task<T> MakeRequestAndGetResultAsync<T>(IAbpMethodInvocation invocation)
{
var responseAsString = await MakeRequest(invocation);
var responseAsString = await MakeRequestAsync(invocation);
//TODO: Think on that
if (TypeHelper.IsPrimitiveExtended(typeof(T), true))
@ -107,36 +118,37 @@ namespace Volo.Abp.Http.Client.DynamicProxying
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 remoteServiceConfig = _remoteServiceOptions.RemoteServices.GetConfigurationOrDefault(clientConfig.RemoteServiceName);
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 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 url = remoteServiceConfig.BaseUrl + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary, apiVersion);
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);
await _clientAuthenticator.Authenticate(
await ClientAuthenticator.Authenticate(
new RemoteServiceHttpClientAuthenticateContext(
client,
requestMessage,
remoteServiceConfig
remoteServiceConfig,
clientConfig.RemoteServiceName
)
);
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage, GetCancellationToken());
if (!response.IsSuccessStatusCode)
{
@ -175,8 +187,9 @@ namespace Volo.Abp.Http.Client.DynamicProxying
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())
{
//TODO: What about other media types?
@ -185,8 +198,8 @@ namespace Volo.Abp.Http.Client.DynamicProxying
requestMessage.Headers.Add("api-version", apiVersion.Version);
}
//Header parameters
var headers = action.Parameters.Where(p => p.BindingSourceId == ParameterBindingSources.Header).ToArray();
foreach (var headerParameter in headers)
{
var value = HttpActionParameterHelper.FindParameterValue(invocation.ArgumentsDictionary, headerParameter);
@ -195,22 +208,25 @@ namespace Volo.Abp.Http.Client.DynamicProxying
requestMessage.Headers.Add(headerParameter.Name, value.ToString());
}
}
//CorrelationId
requestMessage.Headers.Add(CorrelationIdOptions.HttpHeaderName, CorrelationIdProvider.Get());
}
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}.");
return _remoteServiceOptions.RemoteServices.GetOrDefault(clientConfig.RemoteServiceName)?.Version
?? _remoteServiceOptions.RemoteServices.Default?.Version;
return RemoteServiceOptions.RemoteServices.GetOrDefault(clientConfig.RemoteServiceName)?.Version
?? RemoteServiceOptions.RemoteServices.Default?.Version;
}
private async Task ThrowExceptionForResponseAsync(HttpResponseMessage response)
{
if (response.Headers.Contains(AbpHttpConsts.AbpErrorFormat))
{
var errorResponse = _jsonSerializer.Deserialize<RemoteServiceErrorResponse>(
var errorResponse = JsonSerializer.Deserialize<RemoteServiceErrorResponse>(
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}");
}
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.Json;
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 ILogger<IdentityModelHttpClientAuthenticator> Logger { get; set; }
protected IdentityClientOptions ClientOptions { get; }
public IdentityModelHttpClientAuthenticator(
@ -84,6 +83,8 @@ namespace Volo.Abp.IdentityModel
protected virtual async Task<TokenResponse> GetTokenResponse(DiscoveryResponse discoveryResponse, IdentityClientConfiguration configuration)
{
//TODO: Pass cancellation token
var tokenClient = new TokenClient(discoveryResponse.TokenEndpoint, configuration.ClientId, configuration.ClientSecret);
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);
}
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)
{
Check.NotNull(principal, nameof(principal));
@ -34,34 +49,47 @@ namespace System.Security.Principal
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));
var claimsIdentity = identity as ClaimsIdentity;
var userIdOrNull = claimsIdentity?.Claims?.FirstOrDefault(c => c.Type == AbpClaimTypes.UserId);
if (userIdOrNull == null || userIdOrNull.Value.IsNullOrWhiteSpace())
var tenantIdOrNull = claimsIdentity?.Claims?.FirstOrDefault(c => c.Type == AbpClaimTypes.TenantId);
if (tenantIdOrNull == null || tenantIdOrNull.Value.IsNullOrWhiteSpace())
{
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));
var claimsIdentity = identity as ClaimsIdentity;
var tenantIdOrNull = claimsIdentity?.Claims?.FirstOrDefault(c => c.Type == AbpClaimTypes.TenantId);
if (tenantIdOrNull == null || tenantIdOrNull.Value.IsNullOrWhiteSpace())
var clientIdOrNull = claimsIdentity?.Claims?.FirstOrDefault(c => c.Type == AbpClaimTypes.ClientId);
if (clientIdOrNull == null || clientIdOrNull.Value.IsNullOrWhiteSpace())
{
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".
/// </summary>
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 const int MaxApplicationNameLength = 96;
public const int MaxClientIpAddressLength = 64;
public const int MaxClientNameLength = 128;
public const int MaxClientIdLength = 64;
public const int MaxCorrelationIdLength = 64;
public const int MaxBrowserInfoLength = 512;
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.Linq;
using Volo.Abp.Auditing;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy;
@ -12,6 +11,8 @@ namespace Volo.Abp.AuditLogging
[DisableAuditing]
public class AuditLog : AggregateRoot<Guid>, IMultiTenant
{
public virtual string ApplicationName { get; set; }
public virtual Guid? UserId { 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 string ClientId { get; set; }
public string CorrelationId { get; set; }
public virtual string BrowserInfo { get; protected set; }
public virtual string HttpMethod { get; protected set; }
@ -54,6 +59,7 @@ namespace Volo.Abp.AuditLogging
public AuditLog(IGuidGenerator guidGenerator, AuditLogInfo auditInfo)
{
Id = guidGenerator.Create();
ApplicationName = auditInfo.ApplicationName;
TenantId = auditInfo.TenantId;
UserId = auditInfo.UserId;
UserName = auditInfo.UserName.Truncate(AuditLogConsts.MaxUserNameLength);
@ -61,6 +67,8 @@ namespace Volo.Abp.AuditLogging
ExecutionDuration = auditInfo.ExecutionDuration;
ClientIpAddress = auditInfo.ClientIpAddress.Truncate(AuditLogConsts.MaxClientIpAddressLength);
ClientName = auditInfo.ClientName.Truncate(AuditLogConsts.MaxClientNameLength);
ClientId = auditInfo.ClientId.Truncate(AuditLogConsts.MaxClientIdLength);
CorrelationId = auditInfo.CorrelationId.Truncate(AuditLogConsts.MaxCorrelationIdLength);
BrowserInfo = auditInfo.BrowserInfo.Truncate(AuditLogConsts.MaxBrowserInfoLength);
HttpMethod = auditInfo.HttpMethod.Truncate(AuditLogConsts.MaxHttpMethodLength);
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.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.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.HttpMethod).HasMaxLength(AuditLogConsts.MaxHttpMethodLength).HasColumnName(nameof(AuditLog.HttpMethod));
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)
{
var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value);
if (creatorUser != null && !userDictionary.ContainsKey(creatorUser.Id))
if (!userDictionary.ContainsKey(postDto.CreatorId.Value))
{
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 (postDto.CreatorId.HasValue && userDictionary.ContainsKey((Guid)postDto.CreatorId))
{
postDto.Writer = userDictionary[(Guid)postDto.CreatorId];
if (userDictionary.ContainsKey(postDto.CreatorId.Value))
{
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.EntityFrameworkCore;
using Volo.Blogging.EntityFrameworkCore;
using System.Linq.Dynamic.Core;
namespace Volo.Blogging.Posts
{
@ -34,5 +35,10 @@ namespace Volo.Blogging.Posts
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]
public async Task Should_Get_Fore_Reading()
public async Task Should_Get_For_Reading()
{
var blogId = (await _blogRepository.GetListAsync()).First().Id;
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>
<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="..\..\..\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.Ddd.Application\Volo.Abp.Ddd.Application.csproj" />
</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.Permissions;
using Volo.Abp.Identity.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement;
using Volo.Abp.Users;
using Volo.Abp.VirtualFileSystem;
namespace Volo.Abp.Identity
{
[DependsOn(typeof(AbpIdentityDomainSharedModule))]
[DependsOn(typeof(AbpAuthorizationModule))]
[DependsOn(typeof(AbpDddApplicationModule))]
[DependsOn(typeof(AbpPermissionManagementApplicationContractsModule))]
[DependsOn(
typeof(AbpIdentityDomainSharedModule),
typeof(AbpUsersAbstractionModule),
typeof(AbpAuthorizationModule),
typeof(AbpDddApplicationModule),
typeof(AbpPermissionManagementApplicationContractsModule)
)]
public class AbpIdentityApplicationContractsModule : AbpModule
{
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.Delete, L("Permission:Delete"));
usersPermission.AddChild(IdentityPermissions.Users.ManagePermissions, L("Permission:ChangePermissions"));
identityGroup.AddPermission(IdentityPermissions.UserLookup.Default, L("Permission:UserLookup"));
}
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 static class UserLookup
{
public const string Default = GroupName + ".UserLookup";
}
public static string[] GetAll()
{
return new[]
@ -36,7 +41,8 @@
Users.Create,
Users.Update,
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:Delete": "Delete",
"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",
"texts": {
"Permission:IdentityManagement": "Gerenciamento de Acessos",
"Permission:RoleManagement": "Gerenciamento de Perfis",
"Permission:IdentityManagement": "Acessos",
"Permission:RoleManagement": "Perfis",
"Permission:Create": "Criar",
"Permission:Edit": "Editar",
"Permission:Delete": "Excluir",
"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:Delete": "Silme",
"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,
cancellationToken: cancellationToken
)
).ToAbpUserData();
)?.ToAbpUserData();
}
public async Task<IUserData> FindByUserNameAsync(
@ -43,7 +43,7 @@ namespace Volo.Abp.Identity
includeDetails: false,
cancellationToken: cancellationToken
)
).ToAbpUserData();
)?.ToAbpUserData();
}
}
}

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

@ -15,9 +15,6 @@
<ItemGroup>
<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" />
</ItemGroup>

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

@ -1,13 +1,11 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Http.Client;
using Volo.Abp.Modularity;
using Volo.Abp.Users;
namespace Volo.Abp.Identity
{
[DependsOn(
typeof(AbpIdentityApplicationContractsModule),
typeof(AbpUsersAbstractionModule),
typeof(AbpHttpClientModule))]
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.Linq;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
@ -10,24 +9,21 @@ namespace Volo.Abp.Identity
[Dependency(TryRegister = true)]
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)
{
//TODO: Should return null if not found!
return (await _userAppService.GetAsync(id)).ToUserInfo();
return await _userLookupAppService.FindByIdAsync(id);
}
public async Task<IUserData> FindByUserNameAsync(string userName, CancellationToken cancellationToken = default)
{
//TODO: Should return null if not found!
//TODO: Search by UserName, not by a general filter!
return (await _userAppService.GetListAsync(new GetIdentityUsersInput { Filter = userName })).Items.FirstOrDefault()?.ToUserInfo();
return await _userLookupAppService.FindByUserNameAsync(userName);
}
}
}

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",
"texts": {
"Menu:IdentityManagement": "Gerenciamento de Acessos",
"Menu:IdentityManagement": "Acessos",
"Users": "Usuários",
"NewUser": "Novo 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 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 UserPermissionManagementProvider(IPermissionGrantRepository
permissionGrantRepository,
public UserPermissionManagementProvider(
IPermissionGrantRepository permissionGrantRepository,
IGuidGenerator guidGenerator,
ICurrentTenant currentTenant)
: base(

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

@ -21,7 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.IdentityServer.Tes
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}"
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
Global
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}.Release|Any CPU.ActiveCfg = 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
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -74,6 +80,7 @@ Global
{9CD1BFDB-DD76-4194-ACAD-A64541AC2069} = {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}
{072BD630-FB89-45FC-BA2D-12A9745AAB93} = {59A0FC0F-EA6D-477B-84A7-3B1E41B4C858}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
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.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Localization;
@ -51,6 +52,11 @@ namespace Volo.Abp.PermissionManagement
foreach (var permission in group.GetPermissionsWithChildren())
{
if (permission.Providers.Any() && !permission.Providers.Contains(providerName))
{
continue;
}
var grantInfoDto = new PermissionGrantInfoDto
{
Name = permission.Name,
@ -75,7 +81,10 @@ namespace Volo.Abp.PermissionManagement
groupDto.Permissions.Add(grantInfoDto);
}
result.Groups.Add(groupDto);
if (groupDto.Permissions.Any())
{
result.Groups.Add(groupDto);
}
}
return result;
@ -85,9 +94,16 @@ namespace Volo.Abp.PermissionManagement
{
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",
"texts": {
"Permission:TenantManagement": "Gerenciamento de Inquilinos",
"Permission:TenantManagement": "Inquilinos",
"Permission:Create": "Criar",
"Permission:Edit": "Editar",
"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(
Guid id,
[NotNull] string userName,

1
nupkg/common.ps1

@ -140,6 +140,7 @@ $projects = (
# modules/identityserver
"modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared",
"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.MongoDB",

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

@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Account.Web;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.Auditing;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.EventBus.RabbitMq;
@ -60,6 +61,12 @@ namespace AuthServer.Host
{
options.Configuration = configuration["Redis:Configuration"];
});
Configure<AbpAuditingOptions>(options =>
{
options.IsEnabledForGetRequests = true;
options.ApplicationName = "AuthServer";
});
}
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")
.ValueGeneratedOnAdd();
b.Property<string>("ApplicationName")
.HasColumnName("ApplicationName")
.HasMaxLength(96);
b.Property<string>("BrowserInfo")
.HasColumnName("BrowserInfo")
.HasMaxLength(512);
b.Property<string>("ClientId")
.HasColumnName("ClientId")
.HasMaxLength(64);
b.Property<string>("ClientIpAddress")
.HasColumnName("ClientIpAddress")
.HasMaxLength(64);
@ -42,6 +50,10 @@ namespace AuthServer.Host.Migrations
b.Property<string>("ConcurrencyStamp");
b.Property<string>("CorrelationId")
.HasColumnName("CorrelationId")
.HasMaxLength(64);
b.Property<string>("Exceptions")
.HasColumnName("Exceptions")
.HasMaxLength(4000);
@ -753,7 +765,7 @@ namespace AuthServer.Host.Migrations
b.Property<Guid>("ClientId");
b.Property<string>("PostLogoutRedirectUri")
.HasMaxLength(2000);
.HasMaxLength(200);
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.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\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.HttpApi\Volo.Abp.PermissionManagement.HttpApi.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.HttpApi;
using Volo.Abp.PermissionManagement.Identity;
using Volo.Abp.PermissionManagement.IdentityServer;
using Volo.Abp.Security.Claims;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Blogging;
@ -31,7 +32,8 @@ namespace BackendAdminAppGateway.Host
typeof(AbpPermissionManagementHttpApiModule),
typeof(AbpSettingManagementEntityFrameworkCoreModule),
typeof(BloggingApplicationContractsModule),
typeof(AbpPermissionManagementDomainIdentityModule)
typeof(AbpPermissionManagementDomainIdentityModule),
typeof(AbpPermissionManagementDomainIdentityServerModule)
)]
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 Swashbuckle.AspNetCore.Swagger;
using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Autofac;
using Volo.Abp.EntityFrameworkCore;
@ -80,6 +81,12 @@ namespace BloggingService.Host
{
options.Configuration = configuration["Redis:Configuration"];
});
Configure<AbpAuditingOptions>(options =>
{
options.IsEnabledForGetRequests = true;
options.ApplicationName = "BloggingService";
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)

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

@ -9,7 +9,17 @@
},
"RemoteServices": {
"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": {

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

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

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

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

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

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

Loading…
Cancel
Save