diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AspNetCoreCorrelationIdProvider.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AspNetCoreCorrelationIdProvider.cs new file mode 100644 index 0000000000..78383d1252 --- /dev/null +++ b/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 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"); + } + } +} diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs index 94ffc6670b..616190af64 100644 --- a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs +++ b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs @@ -14,6 +14,12 @@ namespace Volo.Abp.Auditing /// public bool IsEnabled { get; set; } + /// + /// The name of the application or service writing audit logs. + /// Default: null. + /// + public string ApplicationName { get; set; } + /// /// Default: true. /// diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs index 5c7deb3d63..79becb4ea0 100644 --- a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs +++ b/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; } diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingHelper.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingHelper.cs index ae579f4293..c584d322a0 100644 --- a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingHelper.cs +++ b/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 options, ICurrentUser currentUser, ICurrentTenant currentTenant, + ICurrentClient currentClient, IClock clock, IAuditingStore auditingStore, ILogger 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 diff --git a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationModule.cs b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationModule.cs index fbcf905b0a..57472d7cf1 100644 --- a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationModule.cs +++ b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationModule.cs @@ -28,6 +28,7 @@ namespace Volo.Abp.Authorization { options.ValueProviders.Add(); options.ValueProviders.Add(); + options.ValueProviders.Add(); }); } } diff --git a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/MethodInvocationAuthorizationService.cs b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/MethodInvocationAuthorizationService.cs index 3e5bb45309..1cca959ebe 100644 --- a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/MethodInvocationAuthorizationService.cs +++ b/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."); } diff --git a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/ClientPermissionValueProvider.cs b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/ClientPermissionValueProvider.cs new file mode 100644 index 0000000000..b9eac0bab0 --- /dev/null +++ b/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 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; + } + } +} diff --git a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionChecker.cs b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionChecker.cs index 4f4243ad6f..7113571c16 100644 --- a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionChecker.cs +++ b/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 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) { diff --git a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionDefinition.cs b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionDefinition.cs index d7913f0d2d..66c3c78143 100644 --- a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionDefinition.cs +++ b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/PermissionDefinition.cs @@ -18,6 +18,8 @@ namespace Volo.Abp.Authorization.Permissions /// public PermissionDefinition Parent { get; private set; } + public List Providers { get; } + public ILocalizableString DisplayName { get => _displayName; @@ -53,6 +55,7 @@ namespace Volo.Abp.Authorization.Permissions DisplayName = displayName ?? new FixedLocalizableString(name); Properties = new Dictionary(); + Providers = new List(); _children = new List(); } @@ -68,6 +71,30 @@ namespace Volo.Abp.Authorization.Permissions return child; } + /// + /// Sets a property in the dictionary. + /// This is a shortcut for nested calls on this object. + /// + public virtual PermissionDefinition WithProperty(string key, object value) + { + Properties[key] = value; + return this; + } + + /// + /// Sets a property in the dictionary. + /// This is a shortcut for nested calls on this object. + /// + public virtual PermissionDefinition WithProviders(params string[] providers) + { + if (!providers.IsNullOrEmpty()) + { + Providers.AddRange(providers); + } + + return this; + } + public override string ToString() { return $"[{nameof(PermissionDefinition)} {Name}]"; diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Tracing/CorrelationIdOptions.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Tracing/CorrelationIdOptions.cs new file mode 100644 index 0000000000..f97d240b05 --- /dev/null +++ b/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"; + } +} diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Tracing/DefaultCorrelationIdProvider.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Tracing/DefaultCorrelationIdProvider.cs new file mode 100644 index 0000000000..24102112a7 --- /dev/null +++ b/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"); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Tracing/ICorrelationIdProvider.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Tracing/ICorrelationIdProvider.cs new file mode 100644 index 0000000000..082da95779 --- /dev/null +++ b/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(); + } +} diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Values/ValueObject.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Values/ValueObject.cs index dccd1c0206..ea84b41792 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Values/ValueObject.cs +++ b/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/ - - /// - /// Base class for value objects. - /// - /// The type of the value object. - public abstract class ValueObject : IEquatable - where TValueObject : ValueObject + //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 GetAtomicValues(); + public override bool Equals(object obj) { - if (obj == null) + if (obj == null || obj.GetType() != GetType()) { return false; } - var item = obj as ValueObject; - 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 thisValues = GetAtomicValues().GetEnumerator(); + IEnumerator 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 x, ValueObject 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 x, ValueObject 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 } } diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs index b216b8e94a..e7b41784c7 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs +++ b/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 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) { diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/RemoteServiceConfigurationExtensions.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/RemoteServiceConfigurationExtensions.cs index 9d1c8a71e9..348f920a44 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/RemoteServiceConfigurationExtensions.cs +++ b/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; } } diff --git a/framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj b/framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj index dd9122b666..a93dc4fcb9 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj +++ b/framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj @@ -20,6 +20,7 @@ + \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientModule.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientModule.cs index 0331c51fff..f9240bd4a8 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientModule.cs +++ b/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(configuration); } } diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/RemoteServiceHttpClientAuthenticateContext.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/RemoteServiceHttpClientAuthenticateContext.cs index fff00d5bf8..b81e1a7139 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/RemoteServiceHttpClientAuthenticateContext.cs +++ b/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; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs index 22813d3d2d..b108ca92f6 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs +++ b/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 : 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> Logger { get; set; } @@ -46,14 +51,20 @@ namespace Volo.Abp.Http.Client.DynamicProxying IOptionsSnapshot remoteServiceOptions, IApiDescriptionFinder apiDescriptionFinder, IJsonSerializer jsonSerializer, - IRemoteServiceHttpClientAuthenticator clientAuthenticator) + IRemoteServiceHttpClientAuthenticator clientAuthenticator, + ICancellationTokenProvider cancellationTokenProvider, + ICorrelationIdProvider correlationIdProvider, + IOptions 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>.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 MakeRequestAndGetResultAsync(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(responseAsString); + return JsonSerializer.Deserialize(responseAsString); } - private async Task MakeRequest(IAbpMethodInvocation invocation) + private async Task 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( + var errorResponse = JsonSerializer.Deserialize( 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; + } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/AbpHttpModule.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/AbpHttpModule.cs index 3f53ccbb1c..171f54b85f 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/AbpHttpModule.cs +++ b/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; diff --git a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs index ee1dd28e85..ad956aee1e 100644 --- a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs +++ b/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 Logger { get; set; } - protected IdentityClientOptions ClientOptions { get; } public IdentityModelHttpClientAuthenticator( @@ -84,6 +83,8 @@ namespace Volo.Abp.IdentityModel protected virtual async Task GetTokenResponse(DiscoveryResponse discoveryResponse, IdentityClientConfiguration configuration) { + //TODO: Pass cancellation token + var tokenClient = new TokenClient(discoveryResponse.TokenEndpoint, configuration.ClientId, configuration.ClientSecret); switch (configuration.GrantType) diff --git a/framework/src/Volo.Abp.Security/System/Security/Principal/AbpClaimsIdentityExtensions.cs b/framework/src/Volo.Abp.Security/System/Security/Principal/AbpClaimsIdentityExtensions.cs index 321aa22914..45d363a7a7 100644 --- a/framework/src/Volo.Abp.Security/System/Security/Principal/AbpClaimsIdentityExtensions.cs +++ b/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; } } } diff --git a/framework/src/Volo.Abp.Security/Volo/Abp/Clients/CurrentClient.cs b/framework/src/Volo.Abp.Security/Volo/Abp/Clients/CurrentClient.cs new file mode 100644 index 0000000000..9e7719faed --- /dev/null +++ b/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; + } + } +} diff --git a/framework/src/Volo.Abp.Security/Volo/Abp/Clients/ICurrentClient.cs b/framework/src/Volo.Abp.Security/Volo/Abp/Clients/ICurrentClient.cs new file mode 100644 index 0000000000..a0d0b141c7 --- /dev/null +++ b/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; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/AbpClaimTypes.cs b/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/AbpClaimTypes.cs index 0edabc957d..b4abf97080 100644 --- a/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/AbpClaimTypes.cs +++ b/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/AbpClaimTypes.cs @@ -47,5 +47,10 @@ namespace Volo.Abp.Security.Claims /// Default: "phone_number_verified". /// public static string TenantId { get; set; } = "tenantid"; + + /// + /// Default: "client_id". + /// + public static string ClientId { get; set; } = "client_id"; } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs index cc3a03ee0e..f6a73bb19a 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs +++ b/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; diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs index 744d9e2a20..5640685b2e 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs +++ b/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, 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); diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs index d718e5d911..bc8a8d2e52 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs +++ b/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)); diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs index a88fd46679..69e325f0c7 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs +++ b/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(creatorUser)); + var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value); + if (creatorUser != null) + { + userDictionary[creatorUser.Id] = ObjectMapper.Map(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]; + } } } diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/BloggingEntityFrameworkCoreQueryableExtensions.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/BloggingEntityFrameworkCoreQueryableExtensions.cs new file mode 100644 index 0000000000..2b9caa6c85 --- /dev/null +++ b/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 IncludeDetails(this IQueryable queryable, bool include = true) + { + if (!include) + { + return queryable; + } + + return queryable + .Include(x => x.Tags); + } + } +} diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs index 58a3c83413..3605550ac4 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs +++ b/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 WithDetails() + { + return GetQueryable().IncludeDetails(); + } } } diff --git a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs index ec4210446c..260304d6ba 100644 --- a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs +++ b/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); diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo.Abp.Identity.Application.Contracts.csproj b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo.Abp.Identity.Application.Contracts.csproj index 8550b20c3e..8d113899a9 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo.Abp.Identity.Application.Contracts.csproj +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo.Abp.Identity.Application.Contracts.csproj @@ -19,9 +19,8 @@ - - + diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/AbpIdentityApplicationContractsModule.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/AbpIdentityApplicationContractsModule.cs index 88fdbcfec3..9a45258f4f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/AbpIdentityApplicationContractsModule.cs +++ b/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) diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserLookupAppService.cs new file mode 100644 index 0000000000..1ab79f400e --- /dev/null +++ b/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 FindByIdAsync(Guid id); + + Task FindByUserNameAsync(string userName); + } +} diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityPermissionDefinitionProvider.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityPermissionDefinitionProvider.cs index 5315b9248c..1c8a8df8d0 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityPermissionDefinitionProvider.cs +++ b/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) diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityPermissions.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityPermissions.cs index 3004cc81df..339122c2a8 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityPermissions.cs +++ b/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 }; } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/en.json b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/en.json index 5b1f6305c3..4a302c8057 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/en.json +++ b/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" } } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/pt-BR.json b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/pt-BR.json index f4c1627252..bef013c26a 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/pt-BR.json +++ b/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" } } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/tr.json b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/tr.json index c185fc1b9e..25760c354b 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/tr.json +++ b/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" } } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserLookupAppService.cs new file mode 100644 index 0000000000..48d42c4579 --- /dev/null +++ b/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 FindByIdAsync(Guid id) + { + var userData = await UserLookupServiceProvider.FindByIdAsync(id); + if (userData == null) + { + return null; + } + + return new UserData(userData); + } + + public virtual async Task FindByUserNameAsync(string userName) + { + var userData = await UserLookupServiceProvider.FindByUserNameAsync(userName); + if (userData == null) + { + return null; + } + + return new UserData(userData); + } + } +} diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs index 30611a4a53..684eec938f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs +++ b/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 FindByUserNameAsync( @@ -43,7 +43,7 @@ namespace Volo.Abp.Identity includeDetails: false, cancellationToken: cancellationToken ) - ).ToAbpUserData(); + )?.ToAbpUserData(); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj index 6c168dbbf2..b7e8a18755 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj @@ -15,9 +15,6 @@ - - - diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/AbpIdentityHttpApiClientModule.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/AbpIdentityHttpApiClientModule.cs index 4ee0b06ff1..ed830a1212 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/AbpIdentityHttpApiClientModule.cs +++ b/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 { diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs index b6f58277d6..53eb6a1af1 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs +++ b/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 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 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); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs new file mode 100644 index 0000000000..ba663858fb --- /dev/null +++ b/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 FindByIdAsync(Guid id) + { + return LookupAppService.FindByIdAsync(id); + } + + [HttpGet] + [Route("by-username/{userName}")] + public Task FindByUserNameAsync(string userName) + { + return LookupAppService.FindByUserNameAsync(userName); + } + } +} diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/pt-BR.json b/modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/pt-BR.json index 98e8c538e9..153b821b47 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/pt-BR.json +++ b/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", diff --git a/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RolePermissionManagementProvider.cs b/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RolePermissionManagementProvider.cs index 483bc656a1..09fb389163 100644 --- a/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RolePermissionManagementProvider.cs +++ b/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); diff --git a/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/UserPermissionManagementProvider.cs b/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/UserPermissionManagementProvider.cs index 43e9644f37..db9a0cbadd 100644 --- a/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/UserPermissionManagementProvider.cs +++ b/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( diff --git a/modules/identityserver/Volo.Abp.IdentityServer.sln b/modules/identityserver/Volo.Abp.IdentityServer.sln index 81cf037e27..93dd971d47 100644 --- a/modules/identityserver/Volo.Abp.IdentityServer.sln +++ b/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} diff --git a/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo.Abp.PermissionManagement.Domain.IdentityServer.csproj b/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo.Abp.PermissionManagement.Domain.IdentityServer.csproj new file mode 100644 index 0000000000..a1579f3f31 --- /dev/null +++ b/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo.Abp.PermissionManagement.Domain.IdentityServer.csproj @@ -0,0 +1,21 @@ + + + + + + netstandard2.0 + Volo.Abp.PermissionManagement.Domain.IdentityServer + Volo.Abp.PermissionManagement.Domain.IdentityServer + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + diff --git a/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs b/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs new file mode 100644 index 0000000000..f22cce8345 --- /dev/null +++ b/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(options => + { + options.ManagementProviders.Add(); + + options.ProviderPolicies[ClientPermissionValueProvider.ProviderName] = "IdentityServer.Client.ManagePermissions"; + }); + } + } +} diff --git a/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/ClientPermissionManagementProvider.cs b/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/ClientPermissionManagementProvider.cs new file mode 100644 index 0000000000..bb4aa54de6 --- /dev/null +++ b/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) + { + + } + } +} diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Application/Volo/Abp/PermissionManagement/PermissionAppService.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Application/Volo/Abp/PermissionManagement/PermissionAppService.cs index 1fe6c2667c..a1ec3e99fc 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Application/Volo/Abp/PermissionManagement/PermissionAppService.cs +++ b/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); } } diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/Localization/ApplicationContracts/pt-BR.json b/modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/Localization/ApplicationContracts/pt-BR.json index ca967a9bea..e828f7f76b 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Application.Contracts/Volo/Abp/TenantManagement/Localization/ApplicationContracts/pt-BR.json +++ b/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" diff --git a/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserData.cs b/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserData.cs index 391e0ef955..bd979cde11 100644 --- a/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserData.cs +++ b/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, diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index 27c0f7ff02..6ac3b2c3d2 100644 --- a/nupkg/common.ps1 +++ b/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", diff --git a/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerHostModule.cs b/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerHostModule.cs index 3d1112c760..52ec9db6ce 100644 --- a/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerHostModule.cs +++ b/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(options => + { + options.IsEnabledForGetRequests = true; + options.ApplicationName = "AuthServer"; + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190208210234_Added_ClientId_And_CorrelationId_To_AuditLogs.Designer.cs b/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190208210234_Added_ClientId_And_CorrelationId_To_AuditLogs.Designer.cs new file mode 100644 index 0000000000..eafb17ae17 --- /dev/null +++ b/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190208210234_Added_ClientId_And_CorrelationId_To_AuditLogs.Designer.cs @@ -0,0 +1,1150 @@ +// +using System; +using AuthServer.Host.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace AuthServer.Host.Migrations +{ + [DbContext(typeof(AuthServerDbContext))] + [Migration("20190208210234_Added_ClientId_And_CorrelationId_To_AuditLogs")] + partial class Added_ClientId_And_CorrelationId_To_AuditLogs + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Volo.Abp.AuditLogging.AuditLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BrowserInfo") + .HasColumnName("BrowserInfo") + .HasMaxLength(512); + + b.Property("ClientId") + .HasColumnName("ClientId") + .HasMaxLength(64); + + b.Property("ClientIpAddress") + .HasColumnName("ClientIpAddress") + .HasMaxLength(64); + + b.Property("ClientName") + .HasColumnName("ClientName") + .HasMaxLength(128); + + b.Property("Comments") + .HasColumnName("Comments") + .HasMaxLength(256); + + b.Property("ConcurrencyStamp"); + + b.Property("CorrelationId") + .HasColumnName("CorrelationId") + .HasMaxLength(64); + + b.Property("Exceptions") + .HasColumnName("Exceptions") + .HasMaxLength(4000); + + b.Property("ExecutionDuration") + .HasColumnName("ExecutionDuration"); + + b.Property("ExecutionTime"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("HttpMethod") + .HasColumnName("HttpMethod") + .HasMaxLength(16); + + b.Property("HttpStatusCode") + .HasColumnName("HttpStatusCode"); + + b.Property("ImpersonatorTenantId") + .HasColumnName("ImpersonatorTenantId"); + + b.Property("ImpersonatorUserId") + .HasColumnName("ImpersonatorUserId"); + + b.Property("TenantId") + .HasColumnName("TenantId"); + + b.Property("Url") + .HasColumnName("Url") + .HasMaxLength(256); + + b.Property("UserId") + .HasColumnName("UserId"); + + b.Property("UserName") + .HasColumnName("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "ExecutionTime"); + + b.HasIndex("TenantId", "UserId", "ExecutionTime"); + + b.ToTable("AbpAuditLogs"); + }); + + modelBuilder.Entity("Volo.Abp.AuditLogging.AuditLogAction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AuditLogId") + .HasColumnName("AuditLogId"); + + b.Property("ExecutionDuration") + .HasColumnName("ExecutionDuration"); + + b.Property("ExecutionTime") + .HasColumnName("ExecutionTime"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("MethodName") + .HasColumnName("MethodName") + .HasMaxLength(128); + + b.Property("Parameters") + .HasColumnName("Parameters") + .HasMaxLength(2000); + + b.Property("ServiceName") + .HasColumnName("ServiceName") + .HasMaxLength(256); + + b.Property("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("AuditLogId"); + + b.HasIndex("TenantId", "ServiceName", "MethodName", "ExecutionTime"); + + b.ToTable("AbpAuditLogActions"); + }); + + modelBuilder.Entity("Volo.Abp.AuditLogging.EntityChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AuditLogId") + .HasColumnName("AuditLogId"); + + b.Property("ChangeTime") + .HasColumnName("ChangeTime"); + + b.Property("ChangeType") + .HasColumnName("ChangeType"); + + b.Property("EntityId") + .IsRequired() + .HasColumnName("EntityId") + .HasMaxLength(128); + + b.Property("EntityTypeFullName") + .IsRequired() + .HasColumnName("EntityTypeFullName") + .HasMaxLength(128); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("TenantId") + .HasColumnName("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("AuditLogId"); + + b.HasIndex("TenantId", "EntityTypeFullName", "EntityId"); + + b.ToTable("AbpEntityChanges"); + }); + + modelBuilder.Entity("Volo.Abp.AuditLogging.EntityPropertyChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EntityChangeId"); + + b.Property("NewValue") + .HasColumnName("NewValue") + .HasMaxLength(512); + + b.Property("OriginalValue") + .HasColumnName("OriginalValue") + .HasMaxLength(512); + + b.Property("PropertyName") + .IsRequired() + .HasColumnName("PropertyName") + .HasMaxLength(128); + + b.Property("PropertyTypeFullName") + .IsRequired() + .HasColumnName("PropertyTypeFullName") + .HasMaxLength(64); + + b.Property("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("EntityChangeId"); + + b.ToTable("AbpEntityPropertyChanges"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityClaimType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .IsRequired() + .HasColumnName("ConcurrencyStamp") + .HasMaxLength(256); + + b.Property("Description") + .HasMaxLength(256); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("IsStatic"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(256); + + b.Property("Regex") + .HasMaxLength(512); + + b.Property("RegexDescription") + .HasMaxLength(128); + + b.Property("Required"); + + b.Property("ValueType"); + + b.HasKey("Id"); + + b.ToTable("AbpClaimTypes"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .IsRequired() + .HasColumnName("ConcurrencyStamp") + .HasMaxLength(256); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("IsDefault") + .HasColumnName("IsDefault"); + + b.Property("IsPublic") + .HasColumnName("IsPublic"); + + b.Property("IsStatic") + .HasColumnName("IsStatic"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(256); + + b.Property("NormalizedName") + .IsRequired() + .HasMaxLength(256); + + b.Property("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName"); + + b.ToTable("AbpRoles"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(256); + + b.Property("ClaimValue") + .HasMaxLength(1024); + + b.Property("RoleId"); + + b.Property("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AbpRoleClaims"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount") + .ValueGeneratedOnAdd() + .HasColumnName("AccessFailedCount") + .HasDefaultValue(0); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnName("ConcurrencyStamp"); + + b.Property("CreationTime") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnName("CreatorId"); + + b.Property("DeleterId") + .HasColumnName("DeleterId"); + + b.Property("DeletionTime") + .HasColumnName("DeletionTime"); + + b.Property("Email") + .HasColumnName("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed") + .ValueGeneratedOnAdd() + .HasColumnName("EmailConfirmed") + .HasDefaultValue(false); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnName("IsDeleted") + .HasDefaultValue(false); + + b.Property("LastModificationTime") + .HasColumnName("LastModificationTime"); + + b.Property("LastModifierId") + .HasColumnName("LastModifierId"); + + b.Property("LockoutEnabled") + .ValueGeneratedOnAdd() + .HasColumnName("LockoutEnabled") + .HasDefaultValue(false); + + b.Property("LockoutEnd"); + + b.Property("Name") + .HasColumnName("Name") + .HasMaxLength(64); + + b.Property("NormalizedEmail") + .HasColumnName("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .IsRequired() + .HasColumnName("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash") + .HasColumnName("PasswordHash") + .HasMaxLength(256); + + b.Property("PhoneNumber") + .HasColumnName("PhoneNumber") + .HasMaxLength(16); + + b.Property("PhoneNumberConfirmed") + .ValueGeneratedOnAdd() + .HasColumnName("PhoneNumberConfirmed") + .HasDefaultValue(false); + + b.Property("SecurityStamp") + .IsRequired() + .HasColumnName("SecurityStamp") + .HasMaxLength(256); + + b.Property("Surname") + .HasColumnName("Surname") + .HasMaxLength(64); + + b.Property("TenantId") + .HasColumnName("TenantId"); + + b.Property("TwoFactorEnabled") + .ValueGeneratedOnAdd() + .HasColumnName("TwoFactorEnabled") + .HasDefaultValue(false); + + b.Property("UserName") + .IsRequired() + .HasColumnName("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("NormalizedEmail"); + + b.HasIndex("NormalizedUserName"); + + b.HasIndex("UserName"); + + b.ToTable("AbpUsers"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(256); + + b.Property("ClaimValue") + .HasMaxLength(1024); + + b.Property("TenantId"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AbpUserClaims"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserLogin", b => + { + b.Property("UserId"); + + b.Property("LoginProvider") + .HasMaxLength(64); + + b.Property("ProviderDisplayName") + .HasMaxLength(128); + + b.Property("ProviderKey") + .IsRequired() + .HasMaxLength(196); + + b.Property("TenantId"); + + b.HasKey("UserId", "LoginProvider"); + + b.HasIndex("LoginProvider", "ProviderKey"); + + b.ToTable("AbpUserLogins"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.Property("TenantId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId", "UserId"); + + b.ToTable("AbpUserRoles"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider") + .HasMaxLength(64); + + b.Property("Name") + .HasMaxLength(128); + + b.Property("TenantId"); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AbpUserTokens"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiResource", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp"); + + b.Property("Description") + .HasMaxLength(1000); + + b.Property("DisplayName") + .HasMaxLength(200); + + b.Property("Enabled"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200); + + b.HasKey("Id"); + + b.ToTable("IdentityServerApiResources"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiResourceClaim", b => + { + b.Property("ApiResourceId"); + + b.Property("Type") + .HasMaxLength(196); + + b.HasKey("ApiResourceId", "Type"); + + b.ToTable("IdentityServerApiClaims"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiScope", b => + { + b.Property("ApiResourceId"); + + b.Property("Name") + .HasMaxLength(196); + + b.Property("Description") + .HasMaxLength(256); + + b.Property("DisplayName") + .HasMaxLength(128); + + b.Property("Emphasize"); + + b.Property("Required"); + + b.Property("ShowInDiscoveryDocument"); + + b.HasKey("ApiResourceId", "Name"); + + b.ToTable("IdentityServerApiScopes"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiScopeClaim", b => + { + b.Property("ApiResourceId"); + + b.Property("Name") + .HasMaxLength(196); + + b.Property("Type") + .HasMaxLength(196); + + b.HasKey("ApiResourceId", "Name", "Type"); + + b.ToTable("IdentityServerApiScopeClaims"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiSecret", b => + { + b.Property("ApiResourceId"); + + b.Property("Type") + .HasMaxLength(32); + + b.Property("Value") + .HasMaxLength(196); + + b.Property("Description") + .HasMaxLength(256); + + b.Property("Expiration"); + + b.HasKey("ApiResourceId", "Type", "Value"); + + b.ToTable("IdentityServerApiSecrets"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AbsoluteRefreshTokenLifetime"); + + b.Property("AccessTokenLifetime"); + + b.Property("AccessTokenType"); + + b.Property("AllowAccessTokensViaBrowser"); + + b.Property("AllowOfflineAccess"); + + b.Property("AllowPlainTextPkce"); + + b.Property("AllowRememberConsent"); + + b.Property("AlwaysIncludeUserClaimsInIdToken"); + + b.Property("AlwaysSendClientClaims"); + + b.Property("AuthorizationCodeLifetime"); + + b.Property("BackChannelLogoutSessionRequired"); + + b.Property("BackChannelLogoutUri") + .HasMaxLength(2000); + + b.Property("ClientClaimsPrefix") + .HasMaxLength(200); + + b.Property("ClientId") + .IsRequired() + .HasMaxLength(200); + + b.Property("ClientName") + .HasMaxLength(200); + + b.Property("ClientUri") + .HasMaxLength(2000); + + b.Property("ConcurrencyStamp"); + + b.Property("ConsentLifetime"); + + b.Property("Description") + .HasMaxLength(1000); + + b.Property("EnableLocalLogin"); + + b.Property("Enabled"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("FrontChannelLogoutSessionRequired"); + + b.Property("FrontChannelLogoutUri") + .HasMaxLength(2000); + + b.Property("IdentityTokenLifetime"); + + b.Property("IncludeJwtId"); + + b.Property("LogoUri") + .HasMaxLength(2000); + + b.Property("PairWiseSubjectSalt") + .HasMaxLength(200); + + b.Property("ProtocolType") + .IsRequired() + .HasMaxLength(200); + + b.Property("RefreshTokenExpiration"); + + b.Property("RefreshTokenUsage"); + + b.Property("RequireClientSecret"); + + b.Property("RequireConsent"); + + b.Property("RequirePkce"); + + b.Property("SlidingRefreshTokenLifetime"); + + b.Property("UpdateAccessTokenClaimsOnRefresh"); + + b.HasKey("Id"); + + b.HasIndex("ClientId") + .IsUnique(); + + b.ToTable("IdentityServerClients"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientClaim", b => + { + b.Property("ClientId"); + + b.Property("Type") + .HasMaxLength(250); + + b.Property("Value") + .HasMaxLength(250); + + b.HasKey("ClientId", "Type", "Value"); + + b.ToTable("IdentityServerClientClaims"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientCorsOrigin", b => + { + b.Property("ClientId"); + + b.Property("Origin") + .HasMaxLength(150); + + b.HasKey("ClientId", "Origin"); + + b.ToTable("IdentityServerClientCorsOrigins"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientGrantType", b => + { + b.Property("ClientId"); + + b.Property("GrantType") + .HasMaxLength(196); + + b.HasKey("ClientId", "GrantType"); + + b.ToTable("IdentityServerClientGrantTypes"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientIdPRestriction", b => + { + b.Property("ClientId"); + + b.Property("Provider") + .HasMaxLength(64); + + b.HasKey("ClientId", "Provider"); + + b.ToTable("IdentityServerClientIdPRestrictions"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientPostLogoutRedirectUri", b => + { + b.Property("ClientId"); + + b.Property("PostLogoutRedirectUri") + .HasMaxLength(200); + + b.HasKey("ClientId", "PostLogoutRedirectUri"); + + b.ToTable("IdentityServerClientPostLogoutRedirectUris"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientProperty", b => + { + b.Property("ClientId"); + + b.Property("Key") + .HasMaxLength(250); + + b.Property("Value") + .IsRequired() + .HasMaxLength(2000); + + b.HasKey("ClientId", "Key"); + + b.ToTable("IdentityServerClientProperties"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientRedirectUri", b => + { + b.Property("ClientId"); + + b.Property("RedirectUri") + .HasMaxLength(2000); + + b.HasKey("ClientId", "RedirectUri"); + + b.ToTable("IdentityServerClientRedirectUris"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientScope", b => + { + b.Property("ClientId"); + + b.Property("Scope") + .HasMaxLength(196); + + b.HasKey("ClientId", "Scope"); + + b.ToTable("IdentityServerClientScopes"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientSecret", b => + { + b.Property("ClientId"); + + b.Property("Type") + .HasMaxLength(32); + + b.Property("Value") + .HasMaxLength(196); + + b.Property("Description") + .HasMaxLength(256); + + b.Property("Expiration"); + + b.HasKey("ClientId", "Type", "Value"); + + b.ToTable("IdentityServerClientSecrets"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Grants.PersistedGrant", b => + { + b.Property("Key") + .HasMaxLength(200); + + b.Property("ClientId") + .IsRequired() + .HasMaxLength(200); + + b.Property("ConcurrencyStamp"); + + b.Property("CreationTime"); + + b.Property("Data") + .IsRequired(); + + b.Property("Expiration"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("Id"); + + b.Property("SubjectId") + .HasMaxLength(200); + + b.Property("Type") + .IsRequired() + .HasMaxLength(50); + + b.HasKey("Key"); + + b.HasIndex("SubjectId", "ClientId", "Type"); + + b.ToTable("IdentityServerPersistedGrants"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.IdentityResources.IdentityClaim", b => + { + b.Property("IdentityResourceId"); + + b.Property("Type") + .HasMaxLength(196); + + b.HasKey("IdentityResourceId", "Type"); + + b.ToTable("IdentityServerIdentityClaims"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.IdentityResources.IdentityResource", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp"); + + b.Property("Description") + .HasMaxLength(1000); + + b.Property("DisplayName") + .HasMaxLength(200); + + b.Property("Emphasize"); + + b.Property("Enabled"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200); + + b.Property("Required"); + + b.Property("ShowInDiscoveryDocument"); + + b.HasKey("Id"); + + b.ToTable("IdentityServerIdentityResources"); + }); + + modelBuilder.Entity("Volo.Abp.PermissionManagement.PermissionGrant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128); + + b.Property("ProviderKey") + .IsRequired() + .HasMaxLength(64); + + b.Property("ProviderName") + .IsRequired() + .HasMaxLength(64); + + b.Property("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("Name", "ProviderName", "ProviderKey"); + + b.ToTable("AbpPermissionGrants"); + }); + + modelBuilder.Entity("Volo.Abp.SettingManagement.Setting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128); + + b.Property("ProviderKey") + .HasMaxLength(64); + + b.Property("ProviderName") + .HasMaxLength(64); + + b.Property("Value") + .IsRequired() + .HasMaxLength(2048); + + b.HasKey("Id"); + + b.HasIndex("Name", "ProviderName", "ProviderKey"); + + b.ToTable("AbpSettings"); + }); + + modelBuilder.Entity("Volo.Abp.AuditLogging.AuditLogAction", b => + { + b.HasOne("Volo.Abp.AuditLogging.AuditLog") + .WithMany("Actions") + .HasForeignKey("AuditLogId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.AuditLogging.EntityChange", b => + { + b.HasOne("Volo.Abp.AuditLogging.AuditLog") + .WithMany("EntityChanges") + .HasForeignKey("AuditLogId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.AuditLogging.EntityPropertyChange", b => + { + b.HasOne("Volo.Abp.AuditLogging.EntityChange") + .WithMany("PropertyChanges") + .HasForeignKey("EntityChangeId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => + { + b.HasOne("Volo.Abp.Identity.IdentityRole") + .WithMany("Claims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserClaim", b => + { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Claims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserLogin", b => + { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Logins") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserRole", b => + { + b.HasOne("Volo.Abp.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserToken", b => + { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Tokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiResourceClaim", b => + { + b.HasOne("Volo.Abp.IdentityServer.ApiResources.ApiResource") + .WithMany("UserClaims") + .HasForeignKey("ApiResourceId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiScope", b => + { + b.HasOne("Volo.Abp.IdentityServer.ApiResources.ApiResource") + .WithMany("Scopes") + .HasForeignKey("ApiResourceId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiScopeClaim", b => + { + b.HasOne("Volo.Abp.IdentityServer.ApiResources.ApiScope") + .WithMany("UserClaims") + .HasForeignKey("ApiResourceId", "Name") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiSecret", b => + { + b.HasOne("Volo.Abp.IdentityServer.ApiResources.ApiResource") + .WithMany("Secrets") + .HasForeignKey("ApiResourceId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientClaim", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("Claims") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientCorsOrigin", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("AllowedCorsOrigins") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientGrantType", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("AllowedGrantTypes") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientIdPRestriction", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("IdentityProviderRestrictions") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientPostLogoutRedirectUri", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("PostLogoutRedirectUris") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientProperty", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("Properties") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientRedirectUri", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("RedirectUris") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientScope", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("AllowedScopes") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientSecret", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("ClientSecrets") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.IdentityResources.IdentityClaim", b => + { + b.HasOne("Volo.Abp.IdentityServer.IdentityResources.IdentityResource") + .WithMany("UserClaims") + .HasForeignKey("IdentityResourceId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190208210234_Added_ClientId_And_CorrelationId_To_AuditLogs.cs b/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190208210234_Added_ClientId_And_CorrelationId_To_AuditLogs.cs new file mode 100644 index 0000000000..38d3168029 --- /dev/null +++ b/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( + name: "PostLogoutRedirectUri", + table: "IdentityServerClientPostLogoutRedirectUris", + maxLength: 200, + nullable: false, + oldClrType: typeof(string), + oldMaxLength: 2000); + + migrationBuilder.AddPrimaryKey( + "PK_IdentityServerClientPostLogoutRedirectUris", + "IdentityServerClientPostLogoutRedirectUris", + new[] {"ClientId", "PostLogoutRedirectUri"} + ); + + migrationBuilder.AddColumn( + name: "ClientId", + table: "AbpAuditLogs", + maxLength: 64, + nullable: true); + + migrationBuilder.AddColumn( + 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( + name: "PostLogoutRedirectUri", + table: "IdentityServerClientPostLogoutRedirectUris", + maxLength: 2000, + nullable: false, + oldClrType: typeof(string), + oldMaxLength: 200); + + migrationBuilder.AddPrimaryKey( + "PK_IdentityServerClientPostLogoutRedirectUris", + "IdentityServerClientPostLogoutRedirectUris", + new[] { "ClientId", "PostLogoutRedirectUri" } + ); + } + } +} diff --git a/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190209193341_Added_ApplicationName_To_AuditLogs.Designer.cs b/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190209193341_Added_ApplicationName_To_AuditLogs.Designer.cs new file mode 100644 index 0000000000..c40fb65f22 --- /dev/null +++ b/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190209193341_Added_ApplicationName_To_AuditLogs.Designer.cs @@ -0,0 +1,1154 @@ +// +using System; +using AuthServer.Host.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace AuthServer.Host.Migrations +{ + [DbContext(typeof(AuthServerDbContext))] + [Migration("20190209193341_Added_ApplicationName_To_AuditLogs")] + partial class Added_ApplicationName_To_AuditLogs + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Volo.Abp.AuditLogging.AuditLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ApplicationName") + .HasColumnName("ApplicationName") + .HasMaxLength(96); + + b.Property("BrowserInfo") + .HasColumnName("BrowserInfo") + .HasMaxLength(512); + + b.Property("ClientId") + .HasColumnName("ClientId") + .HasMaxLength(64); + + b.Property("ClientIpAddress") + .HasColumnName("ClientIpAddress") + .HasMaxLength(64); + + b.Property("ClientName") + .HasColumnName("ClientName") + .HasMaxLength(128); + + b.Property("Comments") + .HasColumnName("Comments") + .HasMaxLength(256); + + b.Property("ConcurrencyStamp"); + + b.Property("CorrelationId") + .HasColumnName("CorrelationId") + .HasMaxLength(64); + + b.Property("Exceptions") + .HasColumnName("Exceptions") + .HasMaxLength(4000); + + b.Property("ExecutionDuration") + .HasColumnName("ExecutionDuration"); + + b.Property("ExecutionTime"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("HttpMethod") + .HasColumnName("HttpMethod") + .HasMaxLength(16); + + b.Property("HttpStatusCode") + .HasColumnName("HttpStatusCode"); + + b.Property("ImpersonatorTenantId") + .HasColumnName("ImpersonatorTenantId"); + + b.Property("ImpersonatorUserId") + .HasColumnName("ImpersonatorUserId"); + + b.Property("TenantId") + .HasColumnName("TenantId"); + + b.Property("Url") + .HasColumnName("Url") + .HasMaxLength(256); + + b.Property("UserId") + .HasColumnName("UserId"); + + b.Property("UserName") + .HasColumnName("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "ExecutionTime"); + + b.HasIndex("TenantId", "UserId", "ExecutionTime"); + + b.ToTable("AbpAuditLogs"); + }); + + modelBuilder.Entity("Volo.Abp.AuditLogging.AuditLogAction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AuditLogId") + .HasColumnName("AuditLogId"); + + b.Property("ExecutionDuration") + .HasColumnName("ExecutionDuration"); + + b.Property("ExecutionTime") + .HasColumnName("ExecutionTime"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("MethodName") + .HasColumnName("MethodName") + .HasMaxLength(128); + + b.Property("Parameters") + .HasColumnName("Parameters") + .HasMaxLength(2000); + + b.Property("ServiceName") + .HasColumnName("ServiceName") + .HasMaxLength(256); + + b.Property("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("AuditLogId"); + + b.HasIndex("TenantId", "ServiceName", "MethodName", "ExecutionTime"); + + b.ToTable("AbpAuditLogActions"); + }); + + modelBuilder.Entity("Volo.Abp.AuditLogging.EntityChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AuditLogId") + .HasColumnName("AuditLogId"); + + b.Property("ChangeTime") + .HasColumnName("ChangeTime"); + + b.Property("ChangeType") + .HasColumnName("ChangeType"); + + b.Property("EntityId") + .IsRequired() + .HasColumnName("EntityId") + .HasMaxLength(128); + + b.Property("EntityTypeFullName") + .IsRequired() + .HasColumnName("EntityTypeFullName") + .HasMaxLength(128); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("TenantId") + .HasColumnName("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("AuditLogId"); + + b.HasIndex("TenantId", "EntityTypeFullName", "EntityId"); + + b.ToTable("AbpEntityChanges"); + }); + + modelBuilder.Entity("Volo.Abp.AuditLogging.EntityPropertyChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EntityChangeId"); + + b.Property("NewValue") + .HasColumnName("NewValue") + .HasMaxLength(512); + + b.Property("OriginalValue") + .HasColumnName("OriginalValue") + .HasMaxLength(512); + + b.Property("PropertyName") + .IsRequired() + .HasColumnName("PropertyName") + .HasMaxLength(128); + + b.Property("PropertyTypeFullName") + .IsRequired() + .HasColumnName("PropertyTypeFullName") + .HasMaxLength(64); + + b.Property("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("EntityChangeId"); + + b.ToTable("AbpEntityPropertyChanges"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityClaimType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .IsRequired() + .HasColumnName("ConcurrencyStamp") + .HasMaxLength(256); + + b.Property("Description") + .HasMaxLength(256); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("IsStatic"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(256); + + b.Property("Regex") + .HasMaxLength(512); + + b.Property("RegexDescription") + .HasMaxLength(128); + + b.Property("Required"); + + b.Property("ValueType"); + + b.HasKey("Id"); + + b.ToTable("AbpClaimTypes"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .IsRequired() + .HasColumnName("ConcurrencyStamp") + .HasMaxLength(256); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("IsDefault") + .HasColumnName("IsDefault"); + + b.Property("IsPublic") + .HasColumnName("IsPublic"); + + b.Property("IsStatic") + .HasColumnName("IsStatic"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(256); + + b.Property("NormalizedName") + .IsRequired() + .HasMaxLength(256); + + b.Property("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName"); + + b.ToTable("AbpRoles"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(256); + + b.Property("ClaimValue") + .HasMaxLength(1024); + + b.Property("RoleId"); + + b.Property("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AbpRoleClaims"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount") + .ValueGeneratedOnAdd() + .HasColumnName("AccessFailedCount") + .HasDefaultValue(0); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnName("ConcurrencyStamp"); + + b.Property("CreationTime") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnName("CreatorId"); + + b.Property("DeleterId") + .HasColumnName("DeleterId"); + + b.Property("DeletionTime") + .HasColumnName("DeletionTime"); + + b.Property("Email") + .HasColumnName("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed") + .ValueGeneratedOnAdd() + .HasColumnName("EmailConfirmed") + .HasDefaultValue(false); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnName("IsDeleted") + .HasDefaultValue(false); + + b.Property("LastModificationTime") + .HasColumnName("LastModificationTime"); + + b.Property("LastModifierId") + .HasColumnName("LastModifierId"); + + b.Property("LockoutEnabled") + .ValueGeneratedOnAdd() + .HasColumnName("LockoutEnabled") + .HasDefaultValue(false); + + b.Property("LockoutEnd"); + + b.Property("Name") + .HasColumnName("Name") + .HasMaxLength(64); + + b.Property("NormalizedEmail") + .HasColumnName("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .IsRequired() + .HasColumnName("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash") + .HasColumnName("PasswordHash") + .HasMaxLength(256); + + b.Property("PhoneNumber") + .HasColumnName("PhoneNumber") + .HasMaxLength(16); + + b.Property("PhoneNumberConfirmed") + .ValueGeneratedOnAdd() + .HasColumnName("PhoneNumberConfirmed") + .HasDefaultValue(false); + + b.Property("SecurityStamp") + .IsRequired() + .HasColumnName("SecurityStamp") + .HasMaxLength(256); + + b.Property("Surname") + .HasColumnName("Surname") + .HasMaxLength(64); + + b.Property("TenantId") + .HasColumnName("TenantId"); + + b.Property("TwoFactorEnabled") + .ValueGeneratedOnAdd() + .HasColumnName("TwoFactorEnabled") + .HasDefaultValue(false); + + b.Property("UserName") + .IsRequired() + .HasColumnName("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("NormalizedEmail"); + + b.HasIndex("NormalizedUserName"); + + b.HasIndex("UserName"); + + b.ToTable("AbpUsers"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(256); + + b.Property("ClaimValue") + .HasMaxLength(1024); + + b.Property("TenantId"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AbpUserClaims"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserLogin", b => + { + b.Property("UserId"); + + b.Property("LoginProvider") + .HasMaxLength(64); + + b.Property("ProviderDisplayName") + .HasMaxLength(128); + + b.Property("ProviderKey") + .IsRequired() + .HasMaxLength(196); + + b.Property("TenantId"); + + b.HasKey("UserId", "LoginProvider"); + + b.HasIndex("LoginProvider", "ProviderKey"); + + b.ToTable("AbpUserLogins"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.Property("TenantId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId", "UserId"); + + b.ToTable("AbpUserRoles"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider") + .HasMaxLength(64); + + b.Property("Name") + .HasMaxLength(128); + + b.Property("TenantId"); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AbpUserTokens"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiResource", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp"); + + b.Property("Description") + .HasMaxLength(1000); + + b.Property("DisplayName") + .HasMaxLength(200); + + b.Property("Enabled"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200); + + b.HasKey("Id"); + + b.ToTable("IdentityServerApiResources"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiResourceClaim", b => + { + b.Property("ApiResourceId"); + + b.Property("Type") + .HasMaxLength(196); + + b.HasKey("ApiResourceId", "Type"); + + b.ToTable("IdentityServerApiClaims"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiScope", b => + { + b.Property("ApiResourceId"); + + b.Property("Name") + .HasMaxLength(196); + + b.Property("Description") + .HasMaxLength(256); + + b.Property("DisplayName") + .HasMaxLength(128); + + b.Property("Emphasize"); + + b.Property("Required"); + + b.Property("ShowInDiscoveryDocument"); + + b.HasKey("ApiResourceId", "Name"); + + b.ToTable("IdentityServerApiScopes"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiScopeClaim", b => + { + b.Property("ApiResourceId"); + + b.Property("Name") + .HasMaxLength(196); + + b.Property("Type") + .HasMaxLength(196); + + b.HasKey("ApiResourceId", "Name", "Type"); + + b.ToTable("IdentityServerApiScopeClaims"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiSecret", b => + { + b.Property("ApiResourceId"); + + b.Property("Type") + .HasMaxLength(32); + + b.Property("Value") + .HasMaxLength(196); + + b.Property("Description") + .HasMaxLength(256); + + b.Property("Expiration"); + + b.HasKey("ApiResourceId", "Type", "Value"); + + b.ToTable("IdentityServerApiSecrets"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AbsoluteRefreshTokenLifetime"); + + b.Property("AccessTokenLifetime"); + + b.Property("AccessTokenType"); + + b.Property("AllowAccessTokensViaBrowser"); + + b.Property("AllowOfflineAccess"); + + b.Property("AllowPlainTextPkce"); + + b.Property("AllowRememberConsent"); + + b.Property("AlwaysIncludeUserClaimsInIdToken"); + + b.Property("AlwaysSendClientClaims"); + + b.Property("AuthorizationCodeLifetime"); + + b.Property("BackChannelLogoutSessionRequired"); + + b.Property("BackChannelLogoutUri") + .HasMaxLength(2000); + + b.Property("ClientClaimsPrefix") + .HasMaxLength(200); + + b.Property("ClientId") + .IsRequired() + .HasMaxLength(200); + + b.Property("ClientName") + .HasMaxLength(200); + + b.Property("ClientUri") + .HasMaxLength(2000); + + b.Property("ConcurrencyStamp"); + + b.Property("ConsentLifetime"); + + b.Property("Description") + .HasMaxLength(1000); + + b.Property("EnableLocalLogin"); + + b.Property("Enabled"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("FrontChannelLogoutSessionRequired"); + + b.Property("FrontChannelLogoutUri") + .HasMaxLength(2000); + + b.Property("IdentityTokenLifetime"); + + b.Property("IncludeJwtId"); + + b.Property("LogoUri") + .HasMaxLength(2000); + + b.Property("PairWiseSubjectSalt") + .HasMaxLength(200); + + b.Property("ProtocolType") + .IsRequired() + .HasMaxLength(200); + + b.Property("RefreshTokenExpiration"); + + b.Property("RefreshTokenUsage"); + + b.Property("RequireClientSecret"); + + b.Property("RequireConsent"); + + b.Property("RequirePkce"); + + b.Property("SlidingRefreshTokenLifetime"); + + b.Property("UpdateAccessTokenClaimsOnRefresh"); + + b.HasKey("Id"); + + b.HasIndex("ClientId") + .IsUnique(); + + b.ToTable("IdentityServerClients"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientClaim", b => + { + b.Property("ClientId"); + + b.Property("Type") + .HasMaxLength(250); + + b.Property("Value") + .HasMaxLength(250); + + b.HasKey("ClientId", "Type", "Value"); + + b.ToTable("IdentityServerClientClaims"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientCorsOrigin", b => + { + b.Property("ClientId"); + + b.Property("Origin") + .HasMaxLength(150); + + b.HasKey("ClientId", "Origin"); + + b.ToTable("IdentityServerClientCorsOrigins"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientGrantType", b => + { + b.Property("ClientId"); + + b.Property("GrantType") + .HasMaxLength(196); + + b.HasKey("ClientId", "GrantType"); + + b.ToTable("IdentityServerClientGrantTypes"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientIdPRestriction", b => + { + b.Property("ClientId"); + + b.Property("Provider") + .HasMaxLength(64); + + b.HasKey("ClientId", "Provider"); + + b.ToTable("IdentityServerClientIdPRestrictions"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientPostLogoutRedirectUri", b => + { + b.Property("ClientId"); + + b.Property("PostLogoutRedirectUri") + .HasMaxLength(200); + + b.HasKey("ClientId", "PostLogoutRedirectUri"); + + b.ToTable("IdentityServerClientPostLogoutRedirectUris"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientProperty", b => + { + b.Property("ClientId"); + + b.Property("Key") + .HasMaxLength(250); + + b.Property("Value") + .IsRequired() + .HasMaxLength(2000); + + b.HasKey("ClientId", "Key"); + + b.ToTable("IdentityServerClientProperties"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientRedirectUri", b => + { + b.Property("ClientId"); + + b.Property("RedirectUri") + .HasMaxLength(2000); + + b.HasKey("ClientId", "RedirectUri"); + + b.ToTable("IdentityServerClientRedirectUris"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientScope", b => + { + b.Property("ClientId"); + + b.Property("Scope") + .HasMaxLength(196); + + b.HasKey("ClientId", "Scope"); + + b.ToTable("IdentityServerClientScopes"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientSecret", b => + { + b.Property("ClientId"); + + b.Property("Type") + .HasMaxLength(32); + + b.Property("Value") + .HasMaxLength(196); + + b.Property("Description") + .HasMaxLength(256); + + b.Property("Expiration"); + + b.HasKey("ClientId", "Type", "Value"); + + b.ToTable("IdentityServerClientSecrets"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Grants.PersistedGrant", b => + { + b.Property("Key") + .HasMaxLength(200); + + b.Property("ClientId") + .IsRequired() + .HasMaxLength(200); + + b.Property("ConcurrencyStamp"); + + b.Property("CreationTime"); + + b.Property("Data") + .IsRequired(); + + b.Property("Expiration"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("Id"); + + b.Property("SubjectId") + .HasMaxLength(200); + + b.Property("Type") + .IsRequired() + .HasMaxLength(50); + + b.HasKey("Key"); + + b.HasIndex("SubjectId", "ClientId", "Type"); + + b.ToTable("IdentityServerPersistedGrants"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.IdentityResources.IdentityClaim", b => + { + b.Property("IdentityResourceId"); + + b.Property("Type") + .HasMaxLength(196); + + b.HasKey("IdentityResourceId", "Type"); + + b.ToTable("IdentityServerIdentityClaims"); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.IdentityResources.IdentityResource", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp"); + + b.Property("Description") + .HasMaxLength(1000); + + b.Property("DisplayName") + .HasMaxLength(200); + + b.Property("Emphasize"); + + b.Property("Enabled"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200); + + b.Property("Required"); + + b.Property("ShowInDiscoveryDocument"); + + b.HasKey("Id"); + + b.ToTable("IdentityServerIdentityResources"); + }); + + modelBuilder.Entity("Volo.Abp.PermissionManagement.PermissionGrant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128); + + b.Property("ProviderKey") + .IsRequired() + .HasMaxLength(64); + + b.Property("ProviderName") + .IsRequired() + .HasMaxLength(64); + + b.Property("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("Name", "ProviderName", "ProviderKey"); + + b.ToTable("AbpPermissionGrants"); + }); + + modelBuilder.Entity("Volo.Abp.SettingManagement.Setting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128); + + b.Property("ProviderKey") + .HasMaxLength(64); + + b.Property("ProviderName") + .HasMaxLength(64); + + b.Property("Value") + .IsRequired() + .HasMaxLength(2048); + + b.HasKey("Id"); + + b.HasIndex("Name", "ProviderName", "ProviderKey"); + + b.ToTable("AbpSettings"); + }); + + modelBuilder.Entity("Volo.Abp.AuditLogging.AuditLogAction", b => + { + b.HasOne("Volo.Abp.AuditLogging.AuditLog") + .WithMany("Actions") + .HasForeignKey("AuditLogId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.AuditLogging.EntityChange", b => + { + b.HasOne("Volo.Abp.AuditLogging.AuditLog") + .WithMany("EntityChanges") + .HasForeignKey("AuditLogId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.AuditLogging.EntityPropertyChange", b => + { + b.HasOne("Volo.Abp.AuditLogging.EntityChange") + .WithMany("PropertyChanges") + .HasForeignKey("EntityChangeId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => + { + b.HasOne("Volo.Abp.Identity.IdentityRole") + .WithMany("Claims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserClaim", b => + { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Claims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserLogin", b => + { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Logins") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserRole", b => + { + b.HasOne("Volo.Abp.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserToken", b => + { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Tokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiResourceClaim", b => + { + b.HasOne("Volo.Abp.IdentityServer.ApiResources.ApiResource") + .WithMany("UserClaims") + .HasForeignKey("ApiResourceId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiScope", b => + { + b.HasOne("Volo.Abp.IdentityServer.ApiResources.ApiResource") + .WithMany("Scopes") + .HasForeignKey("ApiResourceId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiScopeClaim", b => + { + b.HasOne("Volo.Abp.IdentityServer.ApiResources.ApiScope") + .WithMany("UserClaims") + .HasForeignKey("ApiResourceId", "Name") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.ApiResources.ApiSecret", b => + { + b.HasOne("Volo.Abp.IdentityServer.ApiResources.ApiResource") + .WithMany("Secrets") + .HasForeignKey("ApiResourceId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientClaim", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("Claims") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientCorsOrigin", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("AllowedCorsOrigins") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientGrantType", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("AllowedGrantTypes") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientIdPRestriction", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("IdentityProviderRestrictions") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientPostLogoutRedirectUri", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("PostLogoutRedirectUris") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientProperty", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("Properties") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientRedirectUri", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("RedirectUris") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientScope", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("AllowedScopes") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.Clients.ClientSecret", b => + { + b.HasOne("Volo.Abp.IdentityServer.Clients.Client") + .WithMany("ClientSecrets") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.IdentityServer.IdentityResources.IdentityClaim", b => + { + b.HasOne("Volo.Abp.IdentityServer.IdentityResources.IdentityResource") + .WithMany("UserClaims") + .HasForeignKey("IdentityResourceId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190209193341_Added_ApplicationName_To_AuditLogs.cs b/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/20190209193341_Added_ApplicationName_To_AuditLogs.cs new file mode 100644 index 0000000000..91ed4a25a1 --- /dev/null +++ b/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( + name: "ApplicationName", + table: "AbpAuditLogs", + maxLength: 96, + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ApplicationName", + table: "AbpAuditLogs"); + } + } +} diff --git a/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/AuthServerDbContextModelSnapshot.cs b/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/AuthServerDbContextModelSnapshot.cs index d889730472..ee3cf09fd3 100644 --- a/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/AuthServerDbContextModelSnapshot.cs +++ b/samples/MicroserviceDemo/applications/AuthServer.Host/Migrations/AuthServerDbContextModelSnapshot.cs @@ -24,10 +24,18 @@ namespace AuthServer.Host.Migrations b.Property("Id") .ValueGeneratedOnAdd(); + b.Property("ApplicationName") + .HasColumnName("ApplicationName") + .HasMaxLength(96); + b.Property("BrowserInfo") .HasColumnName("BrowserInfo") .HasMaxLength(512); + b.Property("ClientId") + .HasColumnName("ClientId") + .HasMaxLength(64); + b.Property("ClientIpAddress") .HasColumnName("ClientIpAddress") .HasMaxLength(64); @@ -42,6 +50,10 @@ namespace AuthServer.Host.Migrations b.Property("ConcurrencyStamp"); + b.Property("CorrelationId") + .HasColumnName("CorrelationId") + .HasMaxLength(64); + b.Property("Exceptions") .HasColumnName("Exceptions") .HasMaxLength(4000); @@ -753,7 +765,7 @@ namespace AuthServer.Host.Migrations b.Property("ClientId"); b.Property("PostLogoutRedirectUri") - .HasMaxLength(2000); + .HasMaxLength(200); b.HasKey("ClientId", "PostLogoutRedirectUri"); diff --git a/samples/MicroserviceDemo/databases/MsDemo_Identity.zip b/samples/MicroserviceDemo/databases/MsDemo_Identity.zip index d4157d1200..18c8dc12ab 100644 Binary files a/samples/MicroserviceDemo/databases/MsDemo_Identity.zip and b/samples/MicroserviceDemo/databases/MsDemo_Identity.zip differ diff --git a/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGateway.Host.csproj b/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGateway.Host.csproj index a51d66c588..03f9b51d65 100644 --- a/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGateway.Host.csproj +++ b/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGateway.Host.csproj @@ -27,6 +27,7 @@ + diff --git a/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGatewayHostModule.cs b/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGatewayHostModule.cs index c849932e9c..d0549dcfc1 100644 --- a/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGatewayHostModule.cs +++ b/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 { diff --git a/samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingServiceHostModule.cs b/samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingServiceHostModule.cs index 8ff7c47b24..2855fbf099 100644 --- a/samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingServiceHostModule.cs +++ b/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(options => + { + options.IsEnabledForGetRequests = true; + options.ApplicationName = "BloggingService"; + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/samples/MicroserviceDemo/microservices/BloggingService.Host/appsettings.json b/samples/MicroserviceDemo/microservices/BloggingService.Host/appsettings.json index f9c91ffc6b..f5e5e31282 100644 --- a/samples/MicroserviceDemo/microservices/BloggingService.Host/appsettings.json +++ b/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": { diff --git a/samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityServiceHostModule.cs b/samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityServiceHostModule.cs index 2456bb53ce..b802be19b4 100644 --- a/samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityServiceHostModule.cs +++ b/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(options => + { + options.IsEnabledForGetRequests = true; + options.ApplicationName = "IdentityService"; + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/samples/MicroserviceDemo/microservices/ProductService.Host/ProductService.Host.csproj b/samples/MicroserviceDemo/microservices/ProductService.Host/ProductService.Host.csproj index cdeb484825..5965ff3ed3 100644 --- a/samples/MicroserviceDemo/microservices/ProductService.Host/ProductService.Host.csproj +++ b/samples/MicroserviceDemo/microservices/ProductService.Host/ProductService.Host.csproj @@ -41,6 +41,7 @@ + diff --git a/samples/MicroserviceDemo/microservices/ProductService.Host/ProductServiceHostModule.cs b/samples/MicroserviceDemo/microservices/ProductService.Host/ProductServiceHostModule.cs index 545b4dde24..683b11803c 100644 --- a/samples/MicroserviceDemo/microservices/ProductService.Host/ProductServiceHostModule.cs +++ b/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(options => + { + options.IsEnabledForGetRequests = true; + options.ApplicationName = "ProductService"; + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context)