From 90aeb6cba831cb375c37a6f6751a4d3a80709dea Mon Sep 17 00:00:00 2001 From: Nokecy Date: Thu, 3 Jan 2019 14:43:59 +0800 Subject: [PATCH 01/36] Fix AbpEntityPropertyChanges table duplicate Column "EntityChangeId" and "EntityChangeId1" --- .../AbpAuditLoggingtDbContextModelBuilderExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9a39a06dc2..d718e5d911 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 @@ -76,7 +76,7 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore b.Property(x => x.ChangeType).IsRequired().HasColumnName(nameof(EntityChange.ChangeType)); b.Property(x => x.TenantId).HasColumnName(nameof(EntityChange.TenantId)); - b.HasMany().WithOne().HasForeignKey(x => x.EntityChangeId); + b.HasMany(a => a.PropertyChanges).WithOne().HasForeignKey(x => x.EntityChangeId); b.HasIndex(x => new { x.AuditLogId }); b.HasIndex(x => new { x.TenantId, x.EntityTypeFullName, x.EntityId }); From 0c49f8d3b75d24f53c91f6dc2df4b3abe6010a96 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 3 Jan 2019 15:04:50 +0300 Subject: [PATCH 02/36] Resolved #708: Create a separated module for Identity AspNetCore integration. --- modules/identity/Volo.Abp.Identity.sln | 7 ++++ .../Volo.Abp.Identity.AspNetCore.csproj | 21 ++++++++++ .../AspNetCore/AbpIdentityAspNetCoreModule.cs | 38 +++++++++++++++++++ .../AbpIdentityAspNetCoreOptions.cs | 10 +++++ .../AspNetCore}/AbpSecurityStampValidator.cs | 0 .../AbpIdentityServiceCollectionExtensions.cs | 11 ++---- .../Volo.Abp.Identity.Domain.csproj | 2 +- .../Abp/Identity/AbpIdentityDomainModule.cs | 1 + .../Abp/Identity/ProfileAppService_Tests.cs | 5 --- nupkg/common.ps1 | 1 + 10 files changed, 82 insertions(+), 14 deletions(-) create mode 100644 modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo.Abp.Identity.AspNetCore.csproj create mode 100644 modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreModule.cs create mode 100644 modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreOptions.cs rename modules/identity/src/{Volo.Abp.Identity.Domain/Volo/Abp/Identity => Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore}/AbpSecurityStampValidator.cs (100%) diff --git a/modules/identity/Volo.Abp.Identity.sln b/modules/identity/Volo.Abp.Identity.sln index b6973a36ba..f84a829907 100644 --- a/modules/identity/Volo.Abp.Identity.sln +++ b/modules/identity/Volo.Abp.Identity.sln @@ -35,6 +35,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Identity.TestBase" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Identity.Domain.Tests", "test\Volo.Abp.Identity.Domain.Tests\Volo.Abp.Identity.Domain.Tests.csproj", "{588B6E38-323B-4251-AC21-5F67C815A44E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Identity.AspNetCore", "src\Volo.Abp.Identity.AspNetCore\Volo.Abp.Identity.AspNetCore.csproj", "{D5EFC912-75A0-4856-9B8D-DFDD4CD66BAB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -97,6 +99,10 @@ Global {588B6E38-323B-4251-AC21-5F67C815A44E}.Debug|Any CPU.Build.0 = Debug|Any CPU {588B6E38-323B-4251-AC21-5F67C815A44E}.Release|Any CPU.ActiveCfg = Release|Any CPU {588B6E38-323B-4251-AC21-5F67C815A44E}.Release|Any CPU.Build.0 = Release|Any CPU + {D5EFC912-75A0-4856-9B8D-DFDD4CD66BAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D5EFC912-75A0-4856-9B8D-DFDD4CD66BAB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D5EFC912-75A0-4856-9B8D-DFDD4CD66BAB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D5EFC912-75A0-4856-9B8D-DFDD4CD66BAB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -116,6 +122,7 @@ Global {7291DCF0-7AA2-41A6-9AA7-98C2E9D13222} = {9FACAF96-A681-4B36-A938-A37DCA0B7EC1} {D7F61598-E7CE-4DAB-99EA-C266F0423606} = {9FACAF96-A681-4B36-A938-A37DCA0B7EC1} {588B6E38-323B-4251-AC21-5F67C815A44E} = {9FACAF96-A681-4B36-A938-A37DCA0B7EC1} + {D5EFC912-75A0-4856-9B8D-DFDD4CD66BAB} = {AADC5A0A-F100-4511-87DE-B74E55F5B69B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {05740D37-83CF-4041-9C2A-D89F1B3DB5A4} diff --git a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo.Abp.Identity.AspNetCore.csproj b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo.Abp.Identity.AspNetCore.csproj new file mode 100644 index 0000000000..12b84640c0 --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo.Abp.Identity.AspNetCore.csproj @@ -0,0 +1,21 @@ + + + + + + netstandard2.0 + Volo.Abp.Identity.AspNetCore + Volo.Abp.Identity.AspNetCore + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + diff --git a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreModule.cs b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreModule.cs new file mode 100644 index 0000000000..388c0849b7 --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreModule.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Identity.AspNetCore +{ + [DependsOn( + typeof(AbpIdentityDomainModule) + )] + public class AbpIdentityAspNetCoreModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services + .GetObject() + .AddDefaultTokenProviders() + .AddSignInManager(); + + //(TODO: Extract an extension method like IdentityBuilder.AddAbpSecurityStampValidator()) + context.Services.AddScoped(); + context.Services.AddScoped(typeof(SecurityStampValidator), provider => provider.GetService(typeof(AbpSecurityStampValidator))); + context.Services.AddScoped(typeof(ISecurityStampValidator), provider => provider.GetService(typeof(AbpSecurityStampValidator))); + + var options = context.Services.ExecutePreConfiguredActions(new AbpIdentityAspNetCoreOptions()); + + if (options.ConfigureAuthentication) + { + context.Services + .AddAuthentication(o => + { + o.DefaultScheme = IdentityConstants.ApplicationScheme; + o.DefaultSignInScheme = IdentityConstants.ExternalScheme; + }) + .AddIdentityCookies(); + } + } + } +} diff --git a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreOptions.cs b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreOptions.cs new file mode 100644 index 0000000000..ad42a23f9a --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreOptions.cs @@ -0,0 +1,10 @@ +namespace Volo.Abp.Identity.AspNetCore +{ + public class AbpIdentityAspNetCoreOptions + { + /// + /// Default: true. + /// + public bool ConfigureAuthentication { get; set; } = true; + } +} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpSecurityStampValidator.cs b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSecurityStampValidator.cs similarity index 100% rename from modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpSecurityStampValidator.cs rename to modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSecurityStampValidator.cs diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Microsoft/Extensions/DependencyInjection/AbpIdentityServiceCollectionExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Microsoft/Extensions/DependencyInjection/AbpIdentityServiceCollectionExtensions.cs index 5a59253205..c2d91eafd7 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Microsoft/Extensions/DependencyInjection/AbpIdentityServiceCollectionExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Microsoft/Extensions/DependencyInjection/AbpIdentityServiceCollectionExtensions.cs @@ -22,11 +22,6 @@ namespace Microsoft.Extensions.DependencyInjection services.TryAddScoped(); services.TryAddScoped(typeof(UserManager), provider => provider.GetService(typeof(IdentityUserManager))); - //AbpSecurityStampValidator - services.TryAddScoped(); - services.TryAddScoped(typeof(SecurityStampValidator), provider => provider.GetService(typeof(AbpSecurityStampValidator))); - services.TryAddScoped(typeof(ISecurityStampValidator), provider => provider.GetService(typeof(AbpSecurityStampValidator))); - //AbpUserStore services.TryAddScoped(); services.TryAddScoped(typeof(IUserStore), provider => provider.GetService(typeof(IdentityUserStore))); @@ -35,10 +30,10 @@ namespace Microsoft.Extensions.DependencyInjection services.TryAddScoped(); services.TryAddScoped(typeof(IRoleStore), provider => provider.GetService(typeof(IdentityRoleStore))); - return services.AddIdentity(setupAction) - .AddDefaultTokenProviders() + return services + .AddIdentityCore(setupAction) + .AddRoles() .AddClaimsPrincipalFactory(); - //return services.AddIdentityCore(setupAction); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo.Abp.Identity.Domain.csproj b/modules/identity/src/Volo.Abp.Identity.Domain/Volo.Abp.Identity.Domain.csproj index a151c385b9..bdf9c1edd0 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo.Abp.Identity.Domain.csproj +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo.Abp.Identity.Domain.csproj @@ -27,7 +27,7 @@ - + diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs index 9b639f4b34..6465fe692f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs @@ -55,6 +55,7 @@ namespace Volo.Abp.Identity options.User.RequireUniqueEmail = true; }); + context.Services.AddObjectAccessor(identityBuilder); context.Services.ExecutePreConfiguredActions(identityBuilder); AddAbpIdentityOptionsFactory(context.Services); diff --git a/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/ProfileAppService_Tests.cs b/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/ProfileAppService_Tests.cs index c1f0518b49..fc0334ce05 100644 --- a/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/ProfileAppService_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/ProfileAppService_Tests.cs @@ -1,6 +1,5 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Shouldly; @@ -12,16 +11,12 @@ namespace Volo.Abp.Identity public class ProfileAppService_Tests : AbpIdentityApplicationTestBase { private readonly IProfileAppService _profileAppService; - private readonly IIdentityUserRepository _userRepository; - private readonly SignInManager _signInManager; private readonly IdentityTestData _testData; private ICurrentUser _currentUser; public ProfileAppService_Tests() { _profileAppService = GetRequiredService(); - _userRepository = GetRequiredService(); - _signInManager = GetRequiredService>(); _testData = GetRequiredService(); } diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index 3871b73a1e..ba244db63c 100644 --- a/nupkg/common.ps1 +++ b/nupkg/common.ps1 @@ -119,6 +119,7 @@ $projects = ( "modules/tenant-management/src/Volo.Abp.TenantManagement.Web", # modules/identity + "modules/identity/src/Volo.Abp.Identity.AspNetCore", "modules/identity/src/Volo.Abp.Identity.Application", "modules/identity/src/Volo.Abp.Identity.Application.Contracts", "modules/identity/src/Volo.Abp.Identity.Domain", From 215b0d8726518172fefda6ed2e3c7cc1a24436b9 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 3 Jan 2019 16:17:01 +0300 Subject: [PATCH 03/36] Resolved #709 --- .../blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs | 2 ++ .../app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj | 1 + modules/docs/app/Volo.DocsTestApp/DocsTestAppModule.cs | 2 ++ modules/docs/app/Volo.DocsTestApp/Volo.DocsTestApp.csproj | 1 + .../MyCompanyName.MyProjectName.Web.csproj | 1 + .../MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs | 2 ++ 6 files changed, 9 insertions(+) diff --git a/modules/blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs b/modules/blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs index b6c69741b7..06cd067576 100644 --- a/modules/blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs +++ b/modules/blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs @@ -24,6 +24,7 @@ using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Identity; using Volo.Abp.Identity.Web; +using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Modularity; using Volo.Abp.Threading; using Volo.Abp.UI; @@ -44,6 +45,7 @@ namespace Volo.BloggingTestApp #endif typeof(AbpAccountWebModule), typeof(AbpIdentityWebModule), + typeof(AbpIdentityAspNetCoreModule), typeof(AbpIdentityApplicationModule), typeof(AbpAutofacModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule) diff --git a/modules/blogging/app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj b/modules/blogging/app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj index 06fd56c1a2..28a011148f 100644 --- a/modules/blogging/app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj +++ b/modules/blogging/app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj @@ -31,6 +31,7 @@ + diff --git a/modules/docs/app/Volo.DocsTestApp/DocsTestAppModule.cs b/modules/docs/app/Volo.DocsTestApp/DocsTestAppModule.cs index ff5589e192..6d1d2e4201 100644 --- a/modules/docs/app/Volo.DocsTestApp/DocsTestAppModule.cs +++ b/modules/docs/app/Volo.DocsTestApp/DocsTestAppModule.cs @@ -22,6 +22,7 @@ using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Identity; using Volo.Abp.Identity.Web; +using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Modularity; using Volo.Abp.Threading; using Volo.Abp.UI; @@ -41,6 +42,7 @@ namespace Volo.DocsTestApp typeof(AbpAutofacModule), typeof(AbpAccountWebModule), typeof(AbpIdentityWebModule), + typeof(AbpIdentityAspNetCoreModule), typeof(AbpIdentityApplicationModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule) )] diff --git a/modules/docs/app/Volo.DocsTestApp/Volo.DocsTestApp.csproj b/modules/docs/app/Volo.DocsTestApp/Volo.DocsTestApp.csproj index 9a46ccbb8e..31de3a51ad 100644 --- a/modules/docs/app/Volo.DocsTestApp/Volo.DocsTestApp.csproj +++ b/modules/docs/app/Volo.DocsTestApp/Volo.DocsTestApp.csproj @@ -26,6 +26,7 @@ + diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj b/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj index 37f3fceff8..217eeab92b 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj +++ b/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj @@ -32,6 +32,7 @@ + diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs b/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs index 82813d892d..128db80676 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs +++ b/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs @@ -24,6 +24,7 @@ using Volo.Abp.AutoMapper; using Volo.Abp.Data; using Volo.Abp.Identity; using Volo.Abp.Identity.Web; +using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Localization; using Volo.Abp.Localization.Resources.AbpValidation; using Volo.Abp.Modularity; @@ -43,6 +44,7 @@ namespace MyCompanyName.MyProjectName typeof(MyProjectNameEntityFrameworkCoreModule), typeof(AbpAutofacModule), typeof(AbpIdentityWebModule), + typeof(AbpIdentityAspNetCoreModule), typeof(AbpAccountWebModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule) )] From 672d25c45c70469c131e15514e5972f72e379373 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 3 Jan 2019 16:21:40 +0300 Subject: [PATCH 04/36] IAccessTokenProvider.GetOrNullAsync can get the related DynamicHttpClientProxyConfig. --- .../Client/Authentication/HttpContextAccessTokenProvider.cs | 3 ++- .../Abp/Http/Client/Authentication/IAccessTokenProvider.cs | 5 +++-- .../Client/DynamicProxying/DynamicHttpProxyInterceptor.cs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpContextAccessTokenProvider.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpContextAccessTokenProvider.cs index 7a4855fe04..03049f46c6 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpContextAccessTokenProvider.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpContextAccessTokenProvider.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Client.DynamicProxying; namespace Volo.Abp.Http.Client.Authentication { @@ -9,7 +10,7 @@ namespace Volo.Abp.Http.Client.Authentication { public IHttpContextAccessor HttpContextAccessor { get; set; } - public async Task GetOrNullAsync() + public async Task GetOrNullAsync(DynamicHttpClientProxyConfig config) { var httpContext = HttpContextAccessor?.HttpContext; if (httpContext == null) diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IAccessTokenProvider.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IAccessTokenProvider.cs index 5cb1aa92bc..386a5cb416 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IAccessTokenProvider.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IAccessTokenProvider.cs @@ -1,9 +1,10 @@ using System.Threading.Tasks; +using Volo.Abp.Http.Client.DynamicProxying; namespace Volo.Abp.Http.Client.Authentication { - public interface IAccessTokenProvider //TODO: Not sure if this class should be here + public interface IAccessTokenProvider { - Task GetOrNullAsync(); + Task GetOrNullAsync(DynamicHttpClientProxyConfig config); } } 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 f6be5ac630..f70c5f40c3 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 @@ -123,7 +123,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying AddHeaders(invocation, action, requestMessage, apiVersion); - var accessToken = await _accessTokenProvider.GetOrNullAsync(); + var accessToken = await _accessTokenProvider.GetOrNullAsync(clientConfig); if (accessToken != null) { //TODO: "Bearer" should not be static. From 09b4a5b0daeb50b8838430f6651b07977cdcfd65 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 3 Jan 2019 16:24:29 +0300 Subject: [PATCH 05/36] Add mime type: application/x-www-form-urlencoded and use constants. --- .../Client/DynamicProxying/DynamicHttpProxyInterceptor.cs | 4 ++-- .../Http/Client/DynamicProxying/RequestPayloadBuilder.cs | 4 ++-- framework/src/Volo.Abp.Http/Volo/Abp/Http/MimeTypes.cs | 1 + .../Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs | 7 ++++--- 4 files changed, 9 insertions(+), 7 deletions(-) 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 f70c5f40c3..b84c8c087c 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 @@ -174,8 +174,8 @@ namespace Volo.Abp.Http.Client.DynamicProxying if (!apiVersion.Version.IsNullOrEmpty()) { //TODO: What about other media types? - requestMessage.Headers.Add("accept", $"text/plain; v={apiVersion.Version}"); - requestMessage.Headers.Add("accept", $"application/json; v={apiVersion.Version}"); + requestMessage.Headers.Add("accept", $"{MimeTypes.Text.Plain}; v={apiVersion.Version}"); + requestMessage.Headers.Add("accept", $"{MimeTypes.Application.Json}; v={apiVersion.Version}"); requestMessage.Headers.Add("api-version", apiVersion.Version); } diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/RequestPayloadBuilder.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/RequestPayloadBuilder.cs index 8f5fbd0c39..afc5f9e4f0 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/RequestPayloadBuilder.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/RequestPayloadBuilder.cs @@ -17,13 +17,13 @@ namespace Volo.Abp.Http.Client.DynamicProxying var body = GenerateBody(action, methodArguments, jsonSerializer); if (body != null) { - return new StringContent(body, Encoding.UTF8, "application/json"); //TODO: application/json to a constant + return new StringContent(body, Encoding.UTF8, MimeTypes.Application.Json); } body = GenerateFormPostData(action, methodArguments); if (body != null) { - return new StringContent(body, Encoding.UTF8, "application/x-www-form-urlencoded"); //TODO: application/x-www-form-urlencoded to a constant + return new StringContent(body, Encoding.UTF8, MimeTypes.Application.XWwwFormUrlencoded); } return null; diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/MimeTypes.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/MimeTypes.cs index 850a070c8f..a4768a6af1 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/MimeTypes.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/MimeTypes.cs @@ -32,6 +32,7 @@ namespace Volo.Abp.Http public const string XPkcs12 = "application/x-pkcs12"; public const string XShockwaveFlash = "application/x-shockwave-flash"; public const string XSilverlightApp = "application/x-silverlight-app"; + public const string XWwwFormUrlencoded = "application/x-www-form-urlencoded"; public const string XhtmlXml = "application/xhtml+xml"; public const string Xml = "application/xml"; public const string XmlDtd = "application/xml-dtd"; diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs index 031a6d6c89..8bf86a3ace 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Text; +using Volo.Abp.Http; using Volo.Abp.ObjectMapping; using Volo.Abp.Json; using Volo.Abp.TestApp.Application.Dto; @@ -66,7 +67,7 @@ namespace Volo.Abp.AspNetCore.Mvc var response = await Client.PostAsync( "/api/app/people", - new StringContent(postData, Encoding.UTF8, "application/json") + new StringContent(postData, Encoding.UTF8, MimeTypes.Application.Json) ); response.StatusCode.ShouldBe(HttpStatusCode.OK); @@ -98,7 +99,7 @@ namespace Volo.Abp.AspNetCore.Mvc var response = await Client.PutAsync( $"/api/app/people/{updateDto.Id}", - new StringContent(putData, Encoding.UTF8, "application/json") + new StringContent(putData, Encoding.UTF8, MimeTypes.Application.Json) ); response.StatusCode.ShouldBe(HttpStatusCode.OK); @@ -131,7 +132,7 @@ namespace Volo.Abp.AspNetCore.Mvc var response = await Client.PostAsync( $"/api/app/people/{personToAddNewPhone.Id}/phones", - new StringContent(postData, Encoding.UTF8, "application/json") + new StringContent(postData, Encoding.UTF8, MimeTypes.Application.Json) ); response.StatusCode.ShouldBe(HttpStatusCode.OK); From 33ad12f89de8892f69f57976159c23fe17814e72 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 3 Jan 2019 16:47:08 +0300 Subject: [PATCH 06/36] Resolved #710: Introduce Volo.Abp.Http.Client.IdentityModel package. --- framework/Volo.Abp.sln | 11 ++++- .../AbpHttpClientIdentityModelModule.cs | 12 +++++ .../IdentityModelHttpClientAuthenticator.cs | 44 +++++++++++++++++++ .../Volo.Abp.Http.Client.IdentityModel.csproj | 20 +++++++++ .../HttpClientAuthenticateContext.cs | 23 ++++++++++ .../HttpContextAccessTokenProvider.cs | 24 ---------- .../Authentication/IAccessTokenProvider.cs | 10 ----- .../IHttpClientAuthenticator.cs | 9 ++++ .../NullHttpClientAuthenticator.cs | 14 ++++++ .../DynamicHttpProxyInterceptor.cs | 20 ++++----- nupkg/common.ps1 | 3 +- 11 files changed, 143 insertions(+), 47 deletions(-) create mode 100644 framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs create mode 100644 framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs create mode 100644 framework/src/Volo.Abp.Http.Client.IdentityModel/Volo.Abp.Http.Client.IdentityModel.csproj create mode 100644 framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpClientAuthenticateContext.cs delete mode 100644 framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpContextAccessTokenProvider.cs delete mode 100644 framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IAccessTokenProvider.cs create mode 100644 framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IHttpClientAuthenticator.cs create mode 100644 framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/NullHttpClientAuthenticator.cs diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index 92c46299f4..36aef8acce 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -214,9 +214,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.EntityFrameworkCor EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Localization.Abstractions", "src\Volo.Abp.Localization.Abstractions\Volo.Abp.Localization.Abstractions.csproj", "{20513A4E-FAC7-4106-8976-5D79A3BDFED1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Security.Tests", "test\Volo.Abp.Security.Tests\Volo.Abp.Security.Tests.csproj", "{7CE07034-7E02-4C78-B981-F1039412CA5E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Security.Tests", "test\Volo.Abp.Security.Tests\Volo.Abp.Security.Tests.csproj", "{7CE07034-7E02-4C78-B981-F1039412CA5E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Settings.Tests", "test\Volo.Abp.Settings.Tests\Volo.Abp.Settings.Tests.csproj", "{5F3A2D1E-EA89-40A7-8D2F-FB4EB2092403}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Settings.Tests", "test\Volo.Abp.Settings.Tests\Volo.Abp.Settings.Tests.csproj", "{5F3A2D1E-EA89-40A7-8D2F-FB4EB2092403}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Http.Client.IdentityModel", "src\Volo.Abp.Http.Client.IdentityModel\Volo.Abp.Http.Client.IdentityModel.csproj", "{D211A446-38FA-4F97-9A95-1F004A0FFF69}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -616,6 +618,10 @@ Global {5F3A2D1E-EA89-40A7-8D2F-FB4EB2092403}.Debug|Any CPU.Build.0 = Debug|Any CPU {5F3A2D1E-EA89-40A7-8D2F-FB4EB2092403}.Release|Any CPU.ActiveCfg = Release|Any CPU {5F3A2D1E-EA89-40A7-8D2F-FB4EB2092403}.Release|Any CPU.Build.0 = Release|Any CPU + {D211A446-38FA-4F97-9A95-1F004A0FFF69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D211A446-38FA-4F97-9A95-1F004A0FFF69}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D211A446-38FA-4F97-9A95-1F004A0FFF69}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D211A446-38FA-4F97-9A95-1F004A0FFF69}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -721,6 +727,7 @@ Global {20513A4E-FAC7-4106-8976-5D79A3BDFED1} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {7CE07034-7E02-4C78-B981-F1039412CA5E} = {447C8A77-E5F0-4538-8687-7383196D04EA} {5F3A2D1E-EA89-40A7-8D2F-FB4EB2092403} = {447C8A77-E5F0-4538-8687-7383196D04EA} + {D211A446-38FA-4F97-9A95-1F004A0FFF69} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs new file mode 100644 index 0000000000..d6128e68d3 --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs @@ -0,0 +1,12 @@ +using Volo.Abp.Modularity; + +namespace Volo.Abp.Http.Client.IdentityModel +{ + [DependsOn( + typeof(AbpHttpClientModule) + )] + public class AbpHttpClientIdentityModelModule : AbpModule + { + + } +} diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs new file mode 100644 index 0000000000..e45cfbfae3 --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs @@ -0,0 +1,44 @@ +using System.Net.Http.Headers; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Http; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Client.Authentication; + +namespace NewFolder.Abp.Http.Client.IdentityModel +{ + [Dependency(ReplaceServices = true)] + public class IdentityModelHttpClientAuthenticator : IHttpClientAuthenticator, ITransientDependency + { + public IHttpContextAccessor HttpContextAccessor { get; set; } + + public async Task Authenticate(HttpClientAuthenticateContext context) + { + var accessToken = await GetAccessTokenFromHttpContextOrNullAsync() ?? + await GetAccessTokenFromServerOrNullAsync(context); + + if (accessToken != null) + { + //TODO: "Bearer" should be configurable + context.Client.DefaultRequestHeaders.Authorization + = new AuthenticationHeaderValue("Bearer", accessToken); + } + } + + protected virtual Task GetAccessTokenFromServerOrNullAsync(HttpClientAuthenticateContext context) + { + return Task.FromResult((string) null); + } + + protected virtual async Task GetAccessTokenFromHttpContextOrNullAsync() + { + var httpContext = HttpContextAccessor?.HttpContext; + if (httpContext == null) + { + return null; + } + + return await httpContext.GetTokenAsync("access_token"); + } + } +} diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo.Abp.Http.Client.IdentityModel.csproj b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo.Abp.Http.Client.IdentityModel.csproj new file mode 100644 index 0000000000..fe60970058 --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo.Abp.Http.Client.IdentityModel.csproj @@ -0,0 +1,20 @@ + + + + + + netstandard2.0 + Volo.Abp.Http.Client.IdentityModel + Volo.Abp.Http.Client.IdentityModel + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpClientAuthenticateContext.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpClientAuthenticateContext.cs new file mode 100644 index 0000000000..4bf660ff42 --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpClientAuthenticateContext.cs @@ -0,0 +1,23 @@ +using System.Net.Http; + +namespace Volo.Abp.Http.Client.Authentication +{ + public class HttpClientAuthenticateContext + { + public HttpClient Client { get; } + + public HttpRequestMessage Request { get; } + + public string RemoteServiceName { get; } + + public HttpClientAuthenticateContext( + HttpClient client, + HttpRequestMessage request, + string remoteServiceName) + { + Client = client; + Request = request; + RemoteServiceName = remoteServiceName; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpContextAccessTokenProvider.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpContextAccessTokenProvider.cs deleted file mode 100644 index 03049f46c6..0000000000 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpContextAccessTokenProvider.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Http; -using Volo.Abp.DependencyInjection; -using Volo.Abp.Http.Client.DynamicProxying; - -namespace Volo.Abp.Http.Client.Authentication -{ - public class HttpContextAccessTokenProvider : IAccessTokenProvider, ISingletonDependency - { - public IHttpContextAccessor HttpContextAccessor { get; set; } - - public async Task GetOrNullAsync(DynamicHttpClientProxyConfig config) - { - var httpContext = HttpContextAccessor?.HttpContext; - if (httpContext == null) - { - return null; - } - - return await httpContext.GetTokenAsync("access_token"); - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IAccessTokenProvider.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IAccessTokenProvider.cs deleted file mode 100644 index 386a5cb416..0000000000 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IAccessTokenProvider.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Threading.Tasks; -using Volo.Abp.Http.Client.DynamicProxying; - -namespace Volo.Abp.Http.Client.Authentication -{ - public interface IAccessTokenProvider - { - Task GetOrNullAsync(DynamicHttpClientProxyConfig config); - } -} diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IHttpClientAuthenticator.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IHttpClientAuthenticator.cs new file mode 100644 index 0000000000..83d6f9dd31 --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IHttpClientAuthenticator.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.Http.Client.Authentication +{ + public interface IHttpClientAuthenticator + { + Task Authenticate(HttpClientAuthenticateContext context); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/NullHttpClientAuthenticator.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/NullHttpClientAuthenticator.cs new file mode 100644 index 0000000000..a22ebd3674 --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/NullHttpClientAuthenticator.cs @@ -0,0 +1,14 @@ +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Http.Client.Authentication +{ + [Dependency(TryRegister = true)] + public class NullHttpClientAuthenticator : IHttpClientAuthenticator, ISingletonDependency + { + public Task Authenticate(HttpClientAuthenticateContext context) + { + return Task.CompletedTask; + } + } +} \ 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 b84c8c087c..f265f5c3c8 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 @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http; -using System.Net.Http.Headers; using System.Reflection; using System.Threading.Tasks; using Microsoft.Extensions.Options; @@ -28,7 +27,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying private readonly RemoteServiceOptions _remoteServiceOptions; private readonly AbpHttpClientOptions _clientOptions; private readonly IJsonSerializer _jsonSerializer; - private readonly IAccessTokenProvider _accessTokenProvider; + private readonly IHttpClientAuthenticator _clientAuthenticator; static DynamicHttpProxyInterceptor() { @@ -43,12 +42,12 @@ namespace Volo.Abp.Http.Client.DynamicProxying IOptionsSnapshot remoteServiceOptions, IApiDescriptionFinder apiDescriptionFinder, IJsonSerializer jsonSerializer, - IAccessTokenProvider accessTokenProvider) + IHttpClientAuthenticator clientAuthenticator) { _httpClientFactory = httpClientFactory; _apiDescriptionFinder = apiDescriptionFinder; _jsonSerializer = jsonSerializer; - _accessTokenProvider = accessTokenProvider; + _clientAuthenticator = clientAuthenticator; _clientOptions = clientOptions.Value; _remoteServiceOptions = remoteServiceOptions.Value; } @@ -123,12 +122,13 @@ namespace Volo.Abp.Http.Client.DynamicProxying AddHeaders(invocation, action, requestMessage, apiVersion); - var accessToken = await _accessTokenProvider.GetOrNullAsync(clientConfig); - if (accessToken != null) - { - //TODO: "Bearer" should not be static. - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); - } + await _clientAuthenticator.Authenticate( + new HttpClientAuthenticateContext( + client, + requestMessage, + clientConfig.RemoteServiceName + ) + ); var response = await client.SendAsync(requestMessage); diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index ba244db63c..ba084c1175 100644 --- a/nupkg/common.ps1 +++ b/nupkg/common.ps1 @@ -62,7 +62,8 @@ $projects = ( "framework/src/Volo.Abp.HangFire", "framework/src/Volo.Abp.Http", "framework/src/Volo.Abp.Http.Abstractions", - "framework/src/Volo.Abp.Http.Client", + "framework/src/Volo.Abp.Http.Client", + "framework/src/Volo.Abp.Http.Client.IdentityModel", "framework/src/Volo.Abp.Json", "framework/src/Volo.Abp.Localization", "framework/src/Volo.Abp.Localization.Abstractions", From b153028743cdb7051d37193d1baff1f2939ee300 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 3 Jan 2019 20:06:43 +0300 Subject: [PATCH 07/36] Completed first working version of Volo.Abp.Http.Client.IdentityModel --- .../AbpHttpClientIdentityModelModule.cs | 12 -- .../IdentityModelHttpClientAuthenticator.cs | 44 ------- .../Volo.Abp.Http.Client.IdentityModel.csproj | 1 + .../AbpHttpClientIdentityModelModule.cs | 18 +++ .../IdentityClientConfiguration.cs | 93 ++++++++++++++ .../IdentityClientConfigurationDictionary.cs | 15 +++ .../IdentityModel/IdentityClientOptions.cs | 12 ++ .../IdentityModelHttpClientAuthenticator.cs | 116 ++++++++++++++++++ .../RemoteServiceConfigurationExtensions.cs | 22 ++++ .../HttpClientAuthenticateContext.cs | 8 +- .../DynamicHttpProxyInterceptor.cs | 15 +-- .../Http/Client/RemoteServiceConfiguration.cs | 28 ++++- .../RemoteServiceConfigurationDictionary.cs | 11 +- 13 files changed, 316 insertions(+), 79 deletions(-) delete mode 100644 framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs delete mode 100644 framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs create mode 100644 framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs create mode 100644 framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfiguration.cs create mode 100644 framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfigurationDictionary.cs create mode 100644 framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientOptions.cs create mode 100644 framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs create mode 100644 framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/RemoteServiceConfigurationExtensions.cs diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs deleted file mode 100644 index d6128e68d3..0000000000 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Volo.Abp.Modularity; - -namespace Volo.Abp.Http.Client.IdentityModel -{ - [DependsOn( - typeof(AbpHttpClientModule) - )] - public class AbpHttpClientIdentityModelModule : AbpModule - { - - } -} diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs deleted file mode 100644 index e45cfbfae3..0000000000 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/NewFolder/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Net.Http.Headers; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Http; -using Volo.Abp.DependencyInjection; -using Volo.Abp.Http.Client.Authentication; - -namespace NewFolder.Abp.Http.Client.IdentityModel -{ - [Dependency(ReplaceServices = true)] - public class IdentityModelHttpClientAuthenticator : IHttpClientAuthenticator, ITransientDependency - { - public IHttpContextAccessor HttpContextAccessor { get; set; } - - public async Task Authenticate(HttpClientAuthenticateContext context) - { - var accessToken = await GetAccessTokenFromHttpContextOrNullAsync() ?? - await GetAccessTokenFromServerOrNullAsync(context); - - if (accessToken != null) - { - //TODO: "Bearer" should be configurable - context.Client.DefaultRequestHeaders.Authorization - = new AuthenticationHeaderValue("Bearer", accessToken); - } - } - - protected virtual Task GetAccessTokenFromServerOrNullAsync(HttpClientAuthenticateContext context) - { - return Task.FromResult((string) null); - } - - protected virtual async Task GetAccessTokenFromHttpContextOrNullAsync() - { - var httpContext = HttpContextAccessor?.HttpContext; - if (httpContext == null) - { - return null; - } - - return await httpContext.GetTokenAsync("access_token"); - } - } -} diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo.Abp.Http.Client.IdentityModel.csproj b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo.Abp.Http.Client.IdentityModel.csproj index fe60970058..c19bd29eb4 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo.Abp.Http.Client.IdentityModel.csproj +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo.Abp.Http.Client.IdentityModel.csproj @@ -14,6 +14,7 @@ + diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs new file mode 100644 index 0000000000..9946083fb8 --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs @@ -0,0 +1,18 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Http.Client.IdentityModel +{ + [DependsOn( + typeof(AbpHttpClientModule) + )] + public class AbpHttpClientIdentityModelModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + + Configure(configuration); + } + } +} diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfiguration.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfiguration.cs new file mode 100644 index 0000000000..9512328222 --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfiguration.cs @@ -0,0 +1,93 @@ +using System.Collections.Generic; +using IdentityModel; + +namespace Volo.Abp.Http.Client.IdentityModel +{ + public class IdentityClientConfiguration : Dictionary + { + /// + /// Possible values: "client_credentials" or "password". + /// Default value: "client_credentials". + /// + public string GrantType + { + get => this.GetOrDefault(nameof(GrantType)); + set => this[GrantType] = value; + } + + /// + /// Client Id. + /// + public string ClientId + { + get => this.GetOrDefault(nameof(ClientId)); + set => this[ClientId] = value; + } + + /// + /// Client secret (as plain text - without hashed). + /// + public string ClientSecret + { + get => this.GetOrDefault(nameof(ClientSecret)); + set => this[ClientSecret] = value; + } + + /// + /// User name. + /// Valid only if is "password". + /// + public string UserName + { + get => this.GetOrDefault(nameof(UserName)); + set => this[UserName] = value; + } + + /// + /// Password of the . + /// Valid only if is "password". + /// + public string UserPassword + { + get => this.GetOrDefault(nameof(UserPassword)); + set => this[UserPassword] = value; + } + + /// + /// Authority. + /// + public string Authority + { + get => this.GetOrDefault(nameof(Authority)); + set => this[Authority] = value; + } + + /// + /// Scope. + /// + public string Scope + { + get => this.GetOrDefault(nameof(Scope)); + set => this[Scope] = value; + } + + public IdentityClientConfiguration() + { + + } + + public IdentityClientConfiguration( + string clientId, + string clientSecret, + string grantType = OidcConstants.GrantTypes.ClientCredentials, + string userName = null, + string userPassword = null) + { + this[nameof(ClientId)] = clientId; + this[nameof(ClientSecret)] = clientSecret; + this[nameof(GrantType)] = grantType; + this[nameof(UserName)] = userName; + this[nameof(UserPassword)] = userPassword; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfigurationDictionary.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfigurationDictionary.cs new file mode 100644 index 0000000000..7f79df0b37 --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfigurationDictionary.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace Volo.Abp.Http.Client.IdentityModel +{ + public class IdentityClientConfigurationDictionary : Dictionary + { + public const string DefaultName = "Default"; + + public IdentityClientConfiguration Default + { + get => this.GetOrDefault(DefaultName); + set => this[DefaultName] = value; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientOptions.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientOptions.cs new file mode 100644 index 0000000000..e9b1175bcb --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientOptions.cs @@ -0,0 +1,12 @@ +namespace Volo.Abp.Http.Client.IdentityModel +{ + public class IdentityClientOptions + { + public IdentityClientConfigurationDictionary IdentityClients { get; set; } + + public IdentityClientOptions() + { + IdentityClients = new IdentityClientConfigurationDictionary(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs new file mode 100644 index 0000000000..c3aaf4d93c --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using IdentityModel; +using IdentityModel.Client; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Client.Authentication; + +namespace Volo.Abp.Http.Client.IdentityModel +{ + //TODO: This class should be optimized and improved: + + [Dependency(ReplaceServices = true)] + public class IdentityModelHttpClientAuthenticator : IHttpClientAuthenticator, ITransientDependency + { + public IHttpContextAccessor HttpContextAccessor { get; set; } + + protected IdentityClientOptions ClientOptions { get; } + + public IdentityModelHttpClientAuthenticator( + IOptions options) + { + ClientOptions = options.Value; + } + + public async Task Authenticate(HttpClientAuthenticateContext context) + { + var accessToken = await GetAccessTokenFromHttpContextOrNullAsync() ?? + await GetAccessTokenFromServerOrNullAsync(context); + + if (accessToken != null) + { + //TODO: "Bearer" should be configurable + context.Client.DefaultRequestHeaders.Authorization + = new AuthenticationHeaderValue("Bearer", accessToken); + } + } + + protected virtual async Task GetAccessTokenFromHttpContextOrNullAsync() + { + var httpContext = HttpContextAccessor?.HttpContext; + if (httpContext == null) + { + return null; + } + + return await httpContext.GetTokenAsync("access_token"); + } + + protected virtual async Task GetAccessTokenFromServerOrNullAsync(HttpClientAuthenticateContext context) + { + var configuration = GetClientConfiguration(context); + + if (configuration == null) + { + return null; + } + + var discoveryResponse = await GetDiscoveryResponse(configuration); + if (discoveryResponse.IsError) + { + return null; + } + + var tokenResponse = await GetTokenResponse(discoveryResponse, configuration); + if (tokenResponse.IsError) + { + return null; + } + + return tokenResponse.AccessToken; + } + + private IdentityClientConfiguration GetClientConfiguration(HttpClientAuthenticateContext context) + { + var identityClientName = context.RemoteService.GetIdentityClient(); + if (identityClientName.IsNullOrEmpty()) + { + return ClientOptions.IdentityClients.Default; + } + + return ClientOptions.IdentityClients.GetOrDefault(identityClientName) ?? + ClientOptions.IdentityClients.Default; + } + + protected virtual async Task GetDiscoveryResponse(IdentityClientConfiguration configuration) + { + return await DiscoveryClient.GetAsync(configuration.Authority); + } + + protected virtual async Task GetTokenResponse(DiscoveryResponse discoveryResponse, IdentityClientConfiguration configuration) + { + var tokenClient = new TokenClient(discoveryResponse.TokenEndpoint, configuration.ClientId, configuration.ClientSecret); + + switch (configuration.GrantType) + { + case OidcConstants.GrantTypes.ClientCredentials: + return await tokenClient.RequestClientCredentialsAsync( + configuration.Scope + ); + case OidcConstants.GrantTypes.Password: + return await tokenClient.RequestResourceOwnerPasswordAsync( + configuration.UserName, + configuration.UserPassword, + configuration.Scope + ); + default: + throw new AbpException("Grant type was not implemented: " + configuration.GrantType); + } + } + } +} 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 new file mode 100644 index 0000000000..b42920442f --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/RemoteServiceConfigurationExtensions.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using JetBrains.Annotations; + +namespace Volo.Abp.Http.Client +{ + public static class RemoteServiceConfigurationExtensions + { + [CanBeNull] + public static string GetIdentityClient([NotNull] this RemoteServiceConfiguration configuration) + { + Check.NotNullOrEmpty(configuration, nameof(configuration)); + + return configuration.GetOrDefault("IdentityClient"); + } + + public static RemoteServiceConfiguration SetIdentityClient([NotNull] this RemoteServiceConfiguration configuration, [CanBeNull] string value) + { + configuration["IdentityClient"] = value; + return configuration; + } + } +} diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpClientAuthenticateContext.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpClientAuthenticateContext.cs index 4bf660ff42..7374b79694 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpClientAuthenticateContext.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpClientAuthenticateContext.cs @@ -8,16 +8,16 @@ namespace Volo.Abp.Http.Client.Authentication public HttpRequestMessage Request { get; } - public string RemoteServiceName { get; } + public RemoteServiceConfiguration RemoteService { get; } public HttpClientAuthenticateContext( HttpClient client, - HttpRequestMessage request, - string remoteServiceName) + HttpRequestMessage request, + RemoteServiceConfiguration remoteService) { Client = client; Request = request; - RemoteServiceName = remoteServiceName; + RemoteService = remoteService; } } } \ 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 f265f5c3c8..f3f6e8eae6 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 @@ -109,11 +109,11 @@ namespace Volo.Abp.Http.Client.DynamicProxying 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 baseUrl = GetBaseUrl(clientConfig); - var action = await _apiDescriptionFinder.FindActionAsync(baseUrl, typeof(TService), invocation.Method); + var action = await _apiDescriptionFinder.FindActionAsync(remoteServiceConfig.BaseUrl, typeof(TService), invocation.Method); var apiVersion = GetApiVersionInfo(action); - var url = baseUrl + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary, apiVersion); + var url = remoteServiceConfig.BaseUrl + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary, apiVersion); var requestMessage = new HttpRequestMessage(action.GetHttpMethod(), url) { @@ -126,7 +126,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying new HttpClientAuthenticateContext( client, requestMessage, - clientConfig.RemoteServiceName + remoteServiceConfig ) ); @@ -191,13 +191,6 @@ namespace Volo.Abp.Http.Client.DynamicProxying } } - private string GetBaseUrl(DynamicHttpClientProxyConfig config) - { - return _remoteServiceOptions.RemoteServices.GetOrDefault(config.RemoteServiceName)?.BaseUrl - ?? _remoteServiceOptions.RemoteServices.Default?.BaseUrl - ?? throw new AbpException($"Could not find Base URL for {typeof(TService).FullName}."); - } - private string GetConfiguredApiVersion() { var clientConfig = _clientOptions.HttpClientProxies.GetOrDefault(typeof(TService)) diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs index 200e549c3e..d6e5021f78 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs @@ -1,10 +1,26 @@ -namespace Volo.Abp.Http.Client +using System.Collections.Generic; + +namespace Volo.Abp.Http.Client { - public class RemoteServiceConfiguration + public class RemoteServiceConfiguration : Dictionary { - public string BaseUrl { get; set; } + /// + /// Base Url. + /// + public string BaseUrl + { + get => this.GetOrDefault(nameof(BaseUrl)); + set => this[BaseUrl] = value; + } - public string Version { get; set; } + /// + /// Version. + /// + public string Version + { + get => this.GetOrDefault(nameof(Version)); + set => this[Version] = value; + } public RemoteServiceConfiguration() { @@ -13,8 +29,8 @@ public RemoteServiceConfiguration(string baseUrl, string version = null) { - BaseUrl = baseUrl; - Version = version; + this[nameof(BaseUrl)] = baseUrl; + this[nameof(Version)] = version; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationDictionary.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationDictionary.cs index d59470fa57..248285d748 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationDictionary.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationDictionary.cs @@ -8,8 +8,15 @@ namespace Volo.Abp.Http.Client public RemoteServiceConfiguration Default { - get { return this.GetOrDefault(DefaultName); } - set { this[DefaultName] = value; } + get => this.GetOrDefault(DefaultName); + set => this[DefaultName] = value; + } + + public RemoteServiceConfiguration GetConfigurationOrDefault(string name) + { + return this.GetOrDefault(name) + ?? Default + ?? throw new AbpException($"Remote service '{name}' was not found and there is no default configuration."); } } } \ No newline at end of file From 6689ce5a0b6d68531c556537a46c5a6d676eedb6 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 4 Jan 2019 13:27:47 +0800 Subject: [PATCH 08/36] Apply #708 for Account Module. --- modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs | 2 ++ .../src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj | 1 + 2 files changed, 3 insertions(+) diff --git a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs index a6c597aa3e..7a3a980a3b 100644 --- a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs +++ b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs @@ -6,6 +6,7 @@ using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars; using Volo.Abp.Identity; +using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Localization; using Volo.Abp.Localization.Resources.AbpValidation; using Volo.Abp.Modularity; @@ -16,6 +17,7 @@ using Volo.Abp.VirtualFileSystem; namespace Volo.Abp.Account.Web { [DependsOn(typeof(AbpIdentityDomainModule))] + [DependsOn(typeof(AbpIdentityAspNetCoreModule))] [DependsOn(typeof(AbpAspNetCoreMvcUiThemeSharedModule))] public class AbpAccountWebModule : AbpModule { diff --git a/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj b/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj index b1d622de86..a4f1e06ec3 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj +++ b/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj @@ -30,6 +30,7 @@ + From a75d48767c7ef9a2bc6480995dd549c703f23f42 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 4 Jan 2019 09:59:44 +0300 Subject: [PATCH 09/36] Update Client.cs --- .../Volo/Abp/IdentityServer/Clients/Client.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs index cc2fae9900..8c4846102b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs @@ -168,11 +168,6 @@ namespace Volo.Abp.IdentityServer.Clients ClientSecrets.RemoveAll(s => s.Value == value && s.Type == type); } - public virtual void RemoveAllSecrets() - { - ClientSecrets.Clear(); - } - public virtual ClientSecret FindSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) { return ClientSecrets.FirstOrDefault(s => s.Type == type && s.Value == value); From 2c242c6544ba821fb6edfc851bd997e51dbd5ca0 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Fri, 4 Jan 2019 14:12:22 +0300 Subject: [PATCH 10/36] No need to Volo.Abp.Identity.Domain reference --- modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs | 2 -- .../src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj | 1 - 2 files changed, 3 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs index 7a3a980a3b..13d83b8231 100644 --- a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs +++ b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs @@ -5,7 +5,6 @@ using Volo.Abp.Account.Web.Settings; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars; -using Volo.Abp.Identity; using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Localization; using Volo.Abp.Localization.Resources.AbpValidation; @@ -16,7 +15,6 @@ using Volo.Abp.VirtualFileSystem; namespace Volo.Abp.Account.Web { - [DependsOn(typeof(AbpIdentityDomainModule))] [DependsOn(typeof(AbpIdentityAspNetCoreModule))] [DependsOn(typeof(AbpAspNetCoreMvcUiThemeSharedModule))] public class AbpAccountWebModule : AbpModule diff --git a/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj b/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj index a4f1e06ec3..50be3cbf0d 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj +++ b/modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj @@ -31,7 +31,6 @@ - From 19e745e7623d2239a6a79888425c2092d3435fb5 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Fri, 4 Jan 2019 14:57:40 +0300 Subject: [PATCH 11/36] Remove unnecessary AbpIdentityAspNetCoreModule references. --- .../app/Volo.BloggingTestApp/BloggingTestAppModule.cs | 2 -- .../app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj | 1 - modules/docs/app/Volo.DocsTestApp/DocsTestAppModule.cs | 2 -- modules/docs/app/Volo.DocsTestApp/Volo.DocsTestApp.csproj | 1 - .../MyCompanyName.MyProjectName.DemoApp.csproj | 4 ---- .../MyCompanyName.MyProjectName.Web.csproj | 1 - .../MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs | 2 -- 7 files changed, 13 deletions(-) diff --git a/modules/blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs b/modules/blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs index 06cd067576..b6c69741b7 100644 --- a/modules/blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs +++ b/modules/blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs @@ -24,7 +24,6 @@ using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Identity; using Volo.Abp.Identity.Web; -using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Modularity; using Volo.Abp.Threading; using Volo.Abp.UI; @@ -45,7 +44,6 @@ namespace Volo.BloggingTestApp #endif typeof(AbpAccountWebModule), typeof(AbpIdentityWebModule), - typeof(AbpIdentityAspNetCoreModule), typeof(AbpIdentityApplicationModule), typeof(AbpAutofacModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule) diff --git a/modules/blogging/app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj b/modules/blogging/app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj index 28a011148f..06fd56c1a2 100644 --- a/modules/blogging/app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj +++ b/modules/blogging/app/Volo.BloggingTestApp/Volo.BloggingTestApp.csproj @@ -31,7 +31,6 @@ - diff --git a/modules/docs/app/Volo.DocsTestApp/DocsTestAppModule.cs b/modules/docs/app/Volo.DocsTestApp/DocsTestAppModule.cs index 6d1d2e4201..ff5589e192 100644 --- a/modules/docs/app/Volo.DocsTestApp/DocsTestAppModule.cs +++ b/modules/docs/app/Volo.DocsTestApp/DocsTestAppModule.cs @@ -22,7 +22,6 @@ using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Identity; using Volo.Abp.Identity.Web; -using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Modularity; using Volo.Abp.Threading; using Volo.Abp.UI; @@ -42,7 +41,6 @@ namespace Volo.DocsTestApp typeof(AbpAutofacModule), typeof(AbpAccountWebModule), typeof(AbpIdentityWebModule), - typeof(AbpIdentityAspNetCoreModule), typeof(AbpIdentityApplicationModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule) )] diff --git a/modules/docs/app/Volo.DocsTestApp/Volo.DocsTestApp.csproj b/modules/docs/app/Volo.DocsTestApp/Volo.DocsTestApp.csproj index 31de3a51ad..9a46ccbb8e 100644 --- a/modules/docs/app/Volo.DocsTestApp/Volo.DocsTestApp.csproj +++ b/modules/docs/app/Volo.DocsTestApp/Volo.DocsTestApp.csproj @@ -26,7 +26,6 @@ - diff --git a/templates/module/app/MyCompanyName.MyProjectName.DemoApp/MyCompanyName.MyProjectName.DemoApp.csproj b/templates/module/app/MyCompanyName.MyProjectName.DemoApp/MyCompanyName.MyProjectName.DemoApp.csproj index f6ff852ca7..fd3184ee42 100644 --- a/templates/module/app/MyCompanyName.MyProjectName.DemoApp/MyCompanyName.MyProjectName.DemoApp.csproj +++ b/templates/module/app/MyCompanyName.MyProjectName.DemoApp/MyCompanyName.MyProjectName.DemoApp.csproj @@ -33,8 +33,4 @@ - - - - diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj b/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj index 217eeab92b..37f3fceff8 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj +++ b/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyCompanyName.MyProjectName.Web.csproj @@ -32,7 +32,6 @@ - diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs b/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs index 128db80676..82813d892d 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs +++ b/templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs @@ -24,7 +24,6 @@ using Volo.Abp.AutoMapper; using Volo.Abp.Data; using Volo.Abp.Identity; using Volo.Abp.Identity.Web; -using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Localization; using Volo.Abp.Localization.Resources.AbpValidation; using Volo.Abp.Modularity; @@ -44,7 +43,6 @@ namespace MyCompanyName.MyProjectName typeof(MyProjectNameEntityFrameworkCoreModule), typeof(AbpAutofacModule), typeof(AbpIdentityWebModule), - typeof(AbpIdentityAspNetCoreModule), typeof(AbpAccountWebModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule) )] From 3abf90fc7ec77eec1007c9f0cbbad803d38aa750 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 7 Jan 2019 09:45:05 +0300 Subject: [PATCH 12/36] Update Create.cshtml.cs --- .../Pages/Docs/Admin/Projects/Create.cshtml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs index c537473691..3b8f8836f2 100644 --- a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs @@ -31,7 +31,7 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects public async Task OnGetAsync(string source) { - if (source == "GitHub") + if (source != null && source.ToLowerInvariant() == "github") { GithubProject = new CreateGithubProjectViewModel(); return Page(); From eb39490e6a98ed0b419bbdff876f84033d3e8dc5 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 7 Jan 2019 09:51:07 +0300 Subject: [PATCH 13/36] Update Index.cshtml --- .../Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Index.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Index.cshtml b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Index.cshtml index 6ed3eeda25..cc7137ad75 100644 --- a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Index.cshtml +++ b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Index.cshtml @@ -34,7 +34,7 @@ - Github + Github } From 8f7a05616321231b7de4f51356ea1f914cb2e193 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 7 Jan 2019 10:07:01 +0300 Subject: [PATCH 14/36] docs module: update localization --- .../Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Index.cshtml | 2 +- .../src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/en.json | 1 + .../src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/tr.json | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Index.cshtml b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Index.cshtml index cc7137ad75..3d730caec4 100644 --- a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Index.cshtml +++ b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Index.cshtml @@ -34,7 +34,7 @@ - Github + Github } diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/en.json b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/en.json index d84b737cf3..31d3835a3a 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/en.json +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/en.json @@ -7,6 +7,7 @@ "ShareOn": "Share on", "Version": "Version", "Edit": "Edit", + "Delete": "Delete", "InThisDocument": "In this document", "GoToTop": "Go to top", "Projects": "Project(s)", diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/tr.json b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/tr.json index 2c10c4f25d..da39c6cce3 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/tr.json +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/tr.json @@ -7,6 +7,7 @@ "ShareOn": "Paylaş", "Version": "Versiyon", "Edit": "Düzenle", + "Delete": "Sil", "InThisDocument": "Bu dökümanda", "GoToTop": "En üste çık", "Projects": "Proje(ler)", From 95dcc1fc6efe7374cbb06c91ada5766d8cca28b3 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 7 Jan 2019 13:50:41 +0300 Subject: [PATCH 15/36] mvc template migration --- ...51_AuditLogging_Module_Changes.Designer.cs | 673 ++++++++++++++++++ ...90107104851_AuditLogging_Module_Changes.cs | 73 ++ .../MyProjectNameDbContextModelSnapshot.cs | 40 +- 3 files changed, 765 insertions(+), 21 deletions(-) create mode 100644 templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.Designer.cs create mode 100644 templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.cs diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.Designer.cs b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.Designer.cs new file mode 100644 index 0000000000..cebc8eb7ba --- /dev/null +++ b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.Designer.cs @@ -0,0 +1,673 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MyCompanyName.MyProjectName.EntityFrameworkCore; + +namespace MyCompanyName.MyProjectName.Migrations +{ + [DbContext(typeof(MyProjectNameDbContext))] + [Migration("20190107104851_AuditLogging_Module_Changes")] + partial class AuditLogging_Module_Changes + { + 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("ClientIpAddress") + .HasColumnName("ClientIpAddress") + .HasMaxLength(64); + + b.Property("ClientName") + .HasColumnName("ClientName") + .HasMaxLength(128); + + b.Property("Comments") + .HasColumnName("Comments") + .HasMaxLength(256); + + b.Property("ConcurrencyStamp"); + + 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.BackgroundJobs.BackgroundJobRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp"); + + b.Property("CreationTime") + .HasColumnName("CreationTime"); + + b.Property("ExtraProperties") + .HasColumnName("ExtraProperties"); + + b.Property("IsAbandoned") + .ValueGeneratedOnAdd() + .HasDefaultValue(false); + + b.Property("JobArgs") + .IsRequired() + .HasMaxLength(1048576); + + b.Property("JobName") + .IsRequired() + .HasMaxLength(128); + + b.Property("LastTryTime"); + + b.Property("NextTryTime"); + + b.Property("Priority") + .ValueGeneratedOnAdd() + .HasDefaultValue((byte)15); + + b.Property("TryCount") + .ValueGeneratedOnAdd() + .HasDefaultValue((short)0); + + b.HasKey("Id"); + + b.HasIndex("IsAbandoned", "NextTryTime"); + + b.ToTable("AbpBackgroundJobs"); + }); + + 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.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); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.cs b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.cs new file mode 100644 index 0000000000..3725705c27 --- /dev/null +++ b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.cs @@ -0,0 +1,73 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyCompanyName.MyProjectName.Migrations +{ + public partial class AuditLogging_Module_Changes : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_AbpEntityPropertyChanges_AbpEntityChanges_EntityChangeId1", + table: "AbpEntityPropertyChanges"); + + migrationBuilder.DropIndex( + name: "IX_AbpEntityPropertyChanges_EntityChangeId1", + table: "AbpEntityPropertyChanges"); + + migrationBuilder.DropColumn( + name: "EntityChangeId1", + table: "AbpEntityPropertyChanges"); + + migrationBuilder.AlterColumn( + name: "IsDeleted", + table: "AbpUsers", + nullable: false, + defaultValue: false, + oldClrType: typeof(bool)); + + migrationBuilder.AlterColumn( + name: "ConcurrencyStamp", + table: "AbpUsers", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 256); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "IsDeleted", + table: "AbpUsers", + nullable: false, + oldClrType: typeof(bool), + oldDefaultValue: false); + + migrationBuilder.AlterColumn( + name: "ConcurrencyStamp", + table: "AbpUsers", + maxLength: 256, + nullable: false, + oldClrType: typeof(string), + oldNullable: true); + + migrationBuilder.AddColumn( + name: "EntityChangeId1", + table: "AbpEntityPropertyChanges", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_AbpEntityPropertyChanges_EntityChangeId1", + table: "AbpEntityPropertyChanges", + column: "EntityChangeId1"); + + migrationBuilder.AddForeignKey( + name: "FK_AbpEntityPropertyChanges_AbpEntityChanges_EntityChangeId1", + table: "AbpEntityPropertyChanges", + column: "EntityChangeId1", + principalTable: "AbpEntityChanges", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + } +} diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/MyProjectNameDbContextModelSnapshot.cs b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/MyProjectNameDbContextModelSnapshot.cs index 2ff93f8fde..b09d2a1f9f 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/MyProjectNameDbContextModelSnapshot.cs +++ b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/MyProjectNameDbContextModelSnapshot.cs @@ -5,7 +5,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using MyCompanyName.MyProjectName.EntityFrameworkCore; -using Volo.Abp.BackgroundJobs; namespace MyCompanyName.MyProjectName.Migrations { @@ -16,7 +15,7 @@ namespace MyCompanyName.MyProjectName.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.1.1-rtm-30846") + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); @@ -177,8 +176,6 @@ namespace MyCompanyName.MyProjectName.Migrations b.Property("EntityChangeId"); - b.Property("EntityChangeId1"); - b.Property("NewValue") .HasColumnName("NewValue") .HasMaxLength(512); @@ -203,8 +200,6 @@ namespace MyCompanyName.MyProjectName.Migrations b.HasIndex("EntityChangeId"); - b.HasIndex("EntityChangeId1"); - b.ToTable("AbpEntityPropertyChanges"); }); @@ -365,17 +360,19 @@ namespace MyCompanyName.MyProjectName.Migrations b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .IsRequired() - .HasColumnName("ConcurrencyStamp") - .HasMaxLength(256); + .HasColumnName("ConcurrencyStamp"); - b.Property("CreationTime"); + b.Property("CreationTime") + .HasColumnName("CreationTime"); - b.Property("CreatorId"); + b.Property("CreatorId") + .HasColumnName("CreatorId"); - b.Property("DeleterId"); + b.Property("DeleterId") + .HasColumnName("DeleterId"); - b.Property("DeletionTime"); + b.Property("DeletionTime") + .HasColumnName("DeletionTime"); b.Property("Email") .HasColumnName("Email") @@ -389,11 +386,16 @@ namespace MyCompanyName.MyProjectName.Migrations b.Property("ExtraProperties") .HasColumnName("ExtraProperties"); - b.Property("IsDeleted"); + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnName("IsDeleted") + .HasDefaultValue(false); - b.Property("LastModificationTime"); + b.Property("LastModificationTime") + .HasColumnName("LastModificationTime"); - b.Property("LastModifierId"); + b.Property("LastModifierId") + .HasColumnName("LastModifierId"); b.Property("LockoutEnabled") .ValueGeneratedOnAdd() @@ -614,13 +616,9 @@ namespace MyCompanyName.MyProjectName.Migrations modelBuilder.Entity("Volo.Abp.AuditLogging.EntityPropertyChange", b => { b.HasOne("Volo.Abp.AuditLogging.EntityChange") - .WithMany() + .WithMany("PropertyChanges") .HasForeignKey("EntityChangeId") .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("Volo.Abp.AuditLogging.EntityChange") - .WithMany("PropertyChanges") - .HasForeignKey("EntityChangeId1"); }); modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => From dff0c101bc03be412928a42e9da6d97296672288 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Mon, 7 Jan 2019 14:02:27 +0300 Subject: [PATCH 16/36] Fixed #716: Tenant and Use setting issue. --- .../TenantSettingValueProvider.cs | 26 +++++++++---------- .../Abp/Users/UserSettingValueProvider.cs | 26 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/framework/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/TenantSettingValueProvider.cs b/framework/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/TenantSettingValueProvider.cs index 2f5ff72a6d..542af56fe2 100644 --- a/framework/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/TenantSettingValueProvider.cs +++ b/framework/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/TenantSettingValueProvider.cs @@ -19,27 +19,27 @@ namespace Volo.Abp.MultiTenancy public override async Task GetOrNullAsync(SettingDefinition setting, string providerKey) { - if (providerKey == null) - { - if (CurrentTenant.Id == null) - { - return null; - } - - providerKey = CurrentTenant.Id.ToString(); - } - - return await SettingStore.GetOrNullAsync(setting.Name, Name, providerKey); + return await SettingStore.GetOrNullAsync(setting.Name, Name, NormalizeProviderKey(providerKey)); } public override Task SetAsync(SettingDefinition setting, string value, string providerKey) { - return SettingStore.SetAsync(setting.Name, value, Name, providerKey); + return SettingStore.SetAsync(setting.Name, value, Name, NormalizeProviderKey(providerKey)); } public override Task ClearAsync(SettingDefinition setting, string providerKey) { - return SettingStore.DeleteAsync(setting.Name, Name, providerKey); + return SettingStore.DeleteAsync(setting.Name, Name, NormalizeProviderKey(providerKey)); + } + + private string NormalizeProviderKey(string providerKey) + { + if (providerKey == null && CurrentTenant.Id.HasValue) + { + return CurrentTenant.Id.Value.ToString(); + } + + return providerKey; } } } \ No newline at end of file diff --git a/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserSettingValueProvider.cs b/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserSettingValueProvider.cs index 8beba5d31e..345b0e6929 100644 --- a/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserSettingValueProvider.cs +++ b/modules/users/src/Volo.Abp.Users.Abstractions/Volo/Abp/Users/UserSettingValueProvider.cs @@ -22,27 +22,27 @@ namespace Volo.Abp.Users public override async Task GetOrNullAsync(SettingDefinition setting, string providerKey) { - if (providerKey == null) - { - if (CurrentUser.Id == null) - { - return null; - } - - providerKey = CurrentUser.Id.ToString(); - } - - return await SettingStore.GetOrNullAsync(setting.Name, Name, providerKey); + return await SettingStore.GetOrNullAsync(setting.Name, Name, NormalizeProviderKey(providerKey)); } public override Task SetAsync(SettingDefinition setting, string value, string providerKey) { - return SettingStore.SetAsync(setting.Name, value, Name, providerKey); + return SettingStore.SetAsync(setting.Name, value, Name, NormalizeProviderKey(providerKey)); } public override Task ClearAsync(SettingDefinition setting, string providerKey) { - return SettingStore.DeleteAsync(setting.Name, Name, providerKey); + return SettingStore.DeleteAsync(setting.Name, Name, NormalizeProviderKey(providerKey)); + } + + private string NormalizeProviderKey(string providerKey) + { + if (providerKey == null && CurrentUser.Id.HasValue) + { + return CurrentUser.Id.Value.ToString(); + } + + return providerKey; } } } \ No newline at end of file From f0fc787fa18d2b83e09145f26bafc3cb4b39aa15 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 7 Jan 2019 14:45:47 +0300 Subject: [PATCH 17/36] Tag helpers localization refactor --- .../TagHelpers/AbpTagHelperLocalizer.cs | 46 +++++++++++++++++++ .../Form/AbpInputTagHelperService.cs | 30 ++++-------- .../Form/AbpRadioInputTagHelperService.cs | 16 ++----- .../Form/AbpSelectTagHelperService.cs | 39 ++++------------ .../TagHelpers/IAbpTagHelperLocalizer.cs | 13 ++++++ 5 files changed, 83 insertions(+), 61 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperLocalizer.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/IAbpTagHelperLocalizer.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperLocalizer.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperLocalizer.cs new file mode 100644 index 0000000000..35ad5a894d --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperLocalizer.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; +using Volo.Abp.AspNetCore.Mvc.Localization; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers +{ + public class AbpTagHelperLocalizer : IAbpTagHelperLocalizer + { + private readonly IStringLocalizerFactory _stringLocalizerFactory; + private readonly AbpMvcDataAnnotationsLocalizationOptions _options; + + public AbpTagHelperLocalizer(IOptions options, IStringLocalizerFactory stringLocalizerFactory) + { + _stringLocalizerFactory = stringLocalizerFactory; + _options = options.Value; + } + + public string GetLocalizedText(string text, ModelExplorer explorer) + { + var localizer = GetLocalizer(explorer); + + return localizer == null ? text : localizer[text].Value; + } + + public IStringLocalizer GetLocalizer(ModelExplorer explorer) + { + return GetLocalizer(explorer); + } + + private IStringLocalizer GetStringLocalizer(ModelExplorer explorer) + { + IStringLocalizer localizer = null; + var resourceType = _options.AssemblyResources.GetOrDefault(explorer.Container.ModelType.Assembly); + + if (resourceType != null) + { + localizer = _stringLocalizerFactory.Create(resourceType); + } + + return localizer; + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs index e96346a6e5..043ba623fe 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs @@ -17,15 +17,13 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form { private readonly IHtmlGenerator _generator; private readonly HtmlEncoder _encoder; - private readonly IStringLocalizerFactory _stringLocalizerFactory; - private readonly AbpMvcDataAnnotationsLocalizationOptions _options; + private readonly IAbpTagHelperLocalizer _tagHelperLocalizer; - public AbpInputTagHelperService(IHtmlGenerator generator, HtmlEncoder encoder, IOptions options, IStringLocalizerFactory stringLocalizerFactory) + public AbpInputTagHelperService(IHtmlGenerator generator, HtmlEncoder encoder, IAbpTagHelperLocalizer tagHelperLocalizer) { _generator = generator; _encoder = encoder; - _stringLocalizerFactory = stringLocalizerFactory; - _options = options.Value; + _tagHelperLocalizer = tagHelperLocalizer; } public override void Process(TagHelperContext context, TagHelperOutput output) @@ -189,7 +187,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form if (attribute != null) { - inputTagHelperOutput.Attributes.Add("placeholder", LocalizeText(attribute.Value)); + var placeholderLocalized = _tagHelperLocalizer.GetLocalizedText(attribute.Value, TagHelper.AspFor.ModelExplorer); + + inputTagHelperOutput.Attributes.Add("placeholder", placeholderLocalized); } } @@ -207,20 +207,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form return; } - inputTagHelperOutput.Attributes.Add("aria-describedby", LocalizeText(idAttr.Value + "InfoText")); - } - - protected virtual string LocalizeText(string text) - { - IStringLocalizer localizer = null; - var resourceType = _options.AssemblyResources.GetOrDefault(TagHelper.AspFor.ModelExplorer.Container.ModelType.Assembly); - - if (resourceType != null) - { - localizer = _stringLocalizerFactory.Create(resourceType); - } + var infoText = _tagHelperLocalizer.GetLocalizedText(idAttr.Value + "InfoText", TagHelper.AspFor.ModelExplorer); - return localizer == null? text: localizer[text].Value; + inputTagHelperOutput.Attributes.Add("aria-describedby", infoText); } protected virtual bool IsInputCheckbox(TagHelperContext context, TagHelperOutput output, TagHelperAttributeList attributes) @@ -289,9 +278,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form } var idAttr = inputTag.Attributes.FirstOrDefault(a => a.Name == "id"); + var localizedText = _tagHelperLocalizer.GetLocalizedText(text, TagHelper.AspFor.ModelExplorer); return "" + - LocalizeText(text) + + localizedText + ""; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpRadioInputTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpRadioInputTagHelperService.cs index 3644f322eb..f67eafe791 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpRadioInputTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpRadioInputTagHelperService.cs @@ -14,13 +14,11 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form { public class AbpRadioInputTagHelperService : AbpTagHelperService { - private readonly AbpMvcDataAnnotationsLocalizationOptions _options; - private readonly IStringLocalizerFactory _stringLocalizerFactory; + private readonly IAbpTagHelperLocalizer _tagHelperLocalizer; - public AbpRadioInputTagHelperService(IOptions options, IStringLocalizerFactory stringLocalizerFactory) + public AbpRadioInputTagHelperService(IAbpTagHelperLocalizer tagHelperLocalizer) { - _options = options.Value; - _stringLocalizerFactory = stringLocalizerFactory; + _tagHelperLocalizer = tagHelperLocalizer; } public override void Process(TagHelperContext context, TagHelperOutput output) @@ -93,13 +91,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form protected virtual List GetSelectItemsFromEnum(TagHelperContext context, TagHelperOutput output, ModelExplorer explorer) { - IStringLocalizer localizer = null; - var resourceType = _options.AssemblyResources.GetOrDefault(explorer.Container.ModelType.Assembly); - - if (resourceType != null) - { - localizer = _stringLocalizerFactory.Create(resourceType); - } + var localizer = _tagHelperLocalizer.GetLocalizer(explorer); var selectItems = explorer.Metadata.IsEnum ? explorer.ModelType.GetTypeInfo().GetMembers(BindingFlags.Public | BindingFlags.Static) .Select((t, i) => new SelectListItem { Value = i.ToString(), Text = GetLocalizedPropertyName(localizer, explorer.ModelType, t.Name) }).ToList() : null; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs index 1b81374274..6176472406 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs @@ -20,15 +20,13 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form { private readonly IHtmlGenerator _generator; private readonly HtmlEncoder _encoder; - private readonly IStringLocalizerFactory _stringLocalizerFactory; - private readonly AbpMvcDataAnnotationsLocalizationOptions _options; + private readonly IAbpTagHelperLocalizer _tagHelperLocalizer; - public AbpSelectTagHelperService(IHtmlGenerator generator, HtmlEncoder encoder, IOptions options, IStringLocalizerFactory stringLocalizerFactory) + public AbpSelectTagHelperService(IHtmlGenerator generator, HtmlEncoder encoder, IAbpTagHelperLocalizer tagHelperLocalizer) { _generator = generator; _encoder = encoder; - _stringLocalizerFactory = stringLocalizerFactory; - _options = options.Value; + _tagHelperLocalizer = tagHelperLocalizer; } public override void Process(TagHelperContext context, TagHelperOutput output) @@ -154,12 +152,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form return; } - inputTagHelperOutput.Attributes.Add("aria-describedby", LocalizeText(idAttr.Value + "InfoText")); + var infoText = _tagHelperLocalizer.GetLocalizedText(idAttr.Value + "InfoText", TagHelper.AspFor.ModelExplorer); + + inputTagHelperOutput.Attributes.Add("aria-describedby", infoText); } protected virtual string GetInfoAsHtml(TagHelperContext context, TagHelperOutput output, TagHelperOutput inputTag) { - string text = ""; + var text = ""; if (!string.IsNullOrEmpty(TagHelper.InfoText)) { @@ -179,35 +179,16 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form } var idAttr = inputTag.Attributes.FirstOrDefault(a => a.Name == "id"); + var localizedText = _tagHelperLocalizer.GetLocalizedText(text, TagHelper.AspFor.ModelExplorer); return "" + - LocalizeText(text) + + localizedText + ""; } - protected virtual string LocalizeText(string text) - { - var localizer = GetLocalizer(); - - return localizer == null ? text : localizer[text].Value; - } - - protected virtual IStringLocalizer GetLocalizer() - { - IStringLocalizer localizer = null; - var resourceType = _options.AssemblyResources.GetOrDefault(TagHelper.AspFor.ModelExplorer.Container.ModelType.Assembly); - - if (resourceType != null) - { - localizer = _stringLocalizerFactory.Create(resourceType); - } - - return localizer; - } - protected virtual List GetSelectItemsFromEnum(TagHelperContext context, TagHelperOutput output, ModelExplorer explorer) { - var localizer = GetLocalizer(); + var localizer = _tagHelperLocalizer.GetLocalizer(explorer); var selectItems = explorer.Metadata.IsEnum ? explorer.ModelType.GetTypeInfo().GetMembers(BindingFlags.Public | BindingFlags.Static) .Select((t, i) => new SelectListItem { Value = i.ToString(), Text = GetLocalizedPropertyName(localizer, explorer.ModelType, t.Name) }).ToList() : null; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/IAbpTagHelperLocalizer.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/IAbpTagHelperLocalizer.cs new file mode 100644 index 0000000000..8107f58d23 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/IAbpTagHelperLocalizer.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.Extensions.Localization; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers +{ + public interface IAbpTagHelperLocalizer : ITransientDependency + { + string GetLocalizedText(string text, ModelExplorer explorer); + + IStringLocalizer GetLocalizer(ModelExplorer explorer); + } +} From 675f075822702c8ea8b19c3bc8b68259066280ea Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Mon, 7 Jan 2019 14:48:38 +0300 Subject: [PATCH 18/36] Regenerate migrations. --- ....cs => 20190107113413_Initial.Designer.cs} | 31 +- ...6_Initial.cs => 20190107113413_Initial.cs} | 12 +- .../DemoAppDbContextModelSnapshot.cs | 29 +- ...MyCompanyName.MyProjectName.DemoApp.csproj | 4 + .../20181218134025_Initial.Designer.cs | 675 ------------------ ...90107104851_AuditLogging_Module_Changes.cs | 73 -- ....cs => 20190107113038_Initial.Designer.cs} | 14 +- ...5_Initial.cs => 20190107113038_Initial.cs} | 12 +- .../MyProjectNameDbContextModelSnapshot.cs | 10 +- ...e.MyProjectName.EntityFrameworkCore.csproj | 2 + .../IdentityServerHost.csproj | 1 + ....cs => 20190107114341_Initial.Designer.cs} | 31 +- ...4_Initial.cs => 20190107114341_Initial.cs} | 22 +- .../DemoAppDbContextModelSnapshot.cs | 29 +- .../DemoAppDbContext.cs | 2 +- .../Logs/logs.txt | 206 ++++++ ....cs => 20190107114531_Initial.Designer.cs} | 4 +- ...0_Initial.cs => 20190107114531_Initial.cs} | 0 .../DemoAppDbContextModelSnapshot.cs | 2 +- .../MyCompanyName.MyProjectName.Host.csproj | 1 + 20 files changed, 335 insertions(+), 825 deletions(-) rename templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/{20181218134206_Initial.Designer.cs => 20190107113413_Initial.Designer.cs} (93%) rename templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/{20181218134206_Initial.cs => 20190107113413_Initial.cs} (99%) delete mode 100644 templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20181218134025_Initial.Designer.cs delete mode 100644 templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.cs rename templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/{20190107104851_AuditLogging_Module_Changes.Designer.cs => 20190107113038_Initial.Designer.cs} (98%) rename templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/{20181218134025_Initial.cs => 20190107113038_Initial.cs} (99%) rename templates/service/host/IdentityServerHost/Migrations/{20181218135354_Initial.Designer.cs => 20190107114341_Initial.Designer.cs} (96%) rename templates/service/host/IdentityServerHost/Migrations/{20181218135354_Initial.cs => 20190107114341_Initial.cs} (99%) rename templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/{20181218135310_Initial.Designer.cs => 20190107114531_Initial.Designer.cs} (98%) rename templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/{20181218135310_Initial.cs => 20190107114531_Initial.cs} (100%) diff --git a/templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/20181218134206_Initial.Designer.cs b/templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/20190107113413_Initial.Designer.cs similarity index 93% rename from templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/20181218134206_Initial.Designer.cs rename to templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/20190107113413_Initial.Designer.cs index 3ab0c0721f..8d0c81b5f8 100644 --- a/templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/20181218134206_Initial.Designer.cs +++ b/templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/20190107113413_Initial.Designer.cs @@ -10,14 +10,14 @@ using MyCompanyName.MyProjectName.DemoApp; namespace MyCompanyName.MyProjectName.DemoApp.Migrations { [DbContext(typeof(DemoAppDbContext))] - [Migration("20181218134206_Initial")] + [Migration("20190107113413_Initial")] partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.1.1-rtm-30846") + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); @@ -134,17 +134,19 @@ namespace MyCompanyName.MyProjectName.DemoApp.Migrations b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .IsRequired() - .HasColumnName("ConcurrencyStamp") - .HasMaxLength(256); + .HasColumnName("ConcurrencyStamp"); - b.Property("CreationTime"); + b.Property("CreationTime") + .HasColumnName("CreationTime"); - b.Property("CreatorId"); + b.Property("CreatorId") + .HasColumnName("CreatorId"); - b.Property("DeleterId"); + b.Property("DeleterId") + .HasColumnName("DeleterId"); - b.Property("DeletionTime"); + b.Property("DeletionTime") + .HasColumnName("DeletionTime"); b.Property("Email") .HasColumnName("Email") @@ -158,11 +160,16 @@ namespace MyCompanyName.MyProjectName.DemoApp.Migrations b.Property("ExtraProperties") .HasColumnName("ExtraProperties"); - b.Property("IsDeleted"); + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnName("IsDeleted") + .HasDefaultValue(false); - b.Property("LastModificationTime"); + b.Property("LastModificationTime") + .HasColumnName("LastModificationTime"); - b.Property("LastModifierId"); + b.Property("LastModifierId") + .HasColumnName("LastModifierId"); b.Property("LockoutEnabled") .ValueGeneratedOnAdd() diff --git a/templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/20181218134206_Initial.cs b/templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/20190107113413_Initial.cs similarity index 99% rename from templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/20181218134206_Initial.cs rename to templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/20190107113413_Initial.cs index cefa12dfaf..53361cc99e 100644 --- a/templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/20181218134206_Initial.cs +++ b/templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/20190107113413_Initial.cs @@ -82,12 +82,12 @@ namespace MyCompanyName.MyProjectName.DemoApp.Migrations { Id = table.Column(nullable: false), ExtraProperties = table.Column(nullable: true), - ConcurrencyStamp = table.Column(maxLength: 256, nullable: false), + ConcurrencyStamp = table.Column(nullable: true), CreationTime = table.Column(nullable: false), CreatorId = table.Column(nullable: true), LastModificationTime = table.Column(nullable: true), LastModifierId = table.Column(nullable: true), - IsDeleted = table.Column(nullable: false), + IsDeleted = table.Column(nullable: false, defaultValue: false), DeleterId = table.Column(nullable: true), DeletionTime = table.Column(nullable: true), TenantId = table.Column(nullable: true), @@ -158,9 +158,9 @@ namespace MyCompanyName.MyProjectName.DemoApp.Migrations name: "AbpUserLogins", columns: table => new { - TenantId = table.Column(nullable: true), UserId = table.Column(nullable: false), LoginProvider = table.Column(maxLength: 64, nullable: false), + TenantId = table.Column(nullable: true), ProviderKey = table.Column(maxLength: 196, nullable: false), ProviderDisplayName = table.Column(maxLength: 128, nullable: true) }, @@ -179,9 +179,9 @@ namespace MyCompanyName.MyProjectName.DemoApp.Migrations name: "AbpUserRoles", columns: table => new { - TenantId = table.Column(nullable: true), UserId = table.Column(nullable: false), - RoleId = table.Column(nullable: false) + RoleId = table.Column(nullable: false), + TenantId = table.Column(nullable: true) }, constraints: table => { @@ -204,10 +204,10 @@ namespace MyCompanyName.MyProjectName.DemoApp.Migrations name: "AbpUserTokens", columns: table => new { - TenantId = table.Column(nullable: true), UserId = table.Column(nullable: false), LoginProvider = table.Column(maxLength: 64, nullable: false), Name = table.Column(maxLength: 128, nullable: false), + TenantId = table.Column(nullable: true), Value = table.Column(nullable: true) }, constraints: table => diff --git a/templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/DemoAppDbContextModelSnapshot.cs b/templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/DemoAppDbContextModelSnapshot.cs index b64a132e07..b3474a1d80 100644 --- a/templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/DemoAppDbContextModelSnapshot.cs +++ b/templates/module/app/MyCompanyName.MyProjectName.DemoApp/Migrations/DemoAppDbContextModelSnapshot.cs @@ -15,7 +15,7 @@ namespace MyCompanyName.MyProjectName.DemoApp.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.1.1-rtm-30846") + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); @@ -132,17 +132,19 @@ namespace MyCompanyName.MyProjectName.DemoApp.Migrations b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .IsRequired() - .HasColumnName("ConcurrencyStamp") - .HasMaxLength(256); + .HasColumnName("ConcurrencyStamp"); - b.Property("CreationTime"); + b.Property("CreationTime") + .HasColumnName("CreationTime"); - b.Property("CreatorId"); + b.Property("CreatorId") + .HasColumnName("CreatorId"); - b.Property("DeleterId"); + b.Property("DeleterId") + .HasColumnName("DeleterId"); - b.Property("DeletionTime"); + b.Property("DeletionTime") + .HasColumnName("DeletionTime"); b.Property("Email") .HasColumnName("Email") @@ -156,11 +158,16 @@ namespace MyCompanyName.MyProjectName.DemoApp.Migrations b.Property("ExtraProperties") .HasColumnName("ExtraProperties"); - b.Property("IsDeleted"); + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnName("IsDeleted") + .HasDefaultValue(false); - b.Property("LastModificationTime"); + b.Property("LastModificationTime") + .HasColumnName("LastModificationTime"); - b.Property("LastModifierId"); + b.Property("LastModifierId") + .HasColumnName("LastModifierId"); b.Property("LockoutEnabled") .ValueGeneratedOnAdd() diff --git a/templates/module/app/MyCompanyName.MyProjectName.DemoApp/MyCompanyName.MyProjectName.DemoApp.csproj b/templates/module/app/MyCompanyName.MyProjectName.DemoApp/MyCompanyName.MyProjectName.DemoApp.csproj index fd3184ee42..668f12ad1b 100644 --- a/templates/module/app/MyCompanyName.MyProjectName.DemoApp/MyCompanyName.MyProjectName.DemoApp.csproj +++ b/templates/module/app/MyCompanyName.MyProjectName.DemoApp/MyCompanyName.MyProjectName.DemoApp.csproj @@ -33,4 +33,8 @@ + + + + diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20181218134025_Initial.Designer.cs b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20181218134025_Initial.Designer.cs deleted file mode 100644 index 7821feff86..0000000000 --- a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20181218134025_Initial.Designer.cs +++ /dev/null @@ -1,675 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using MyCompanyName.MyProjectName.EntityFrameworkCore; -using Volo.Abp.BackgroundJobs; - -namespace MyCompanyName.MyProjectName.Migrations -{ - [DbContext(typeof(MyProjectNameDbContext))] - [Migration("20181218134025_Initial")] - partial class Initial - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "2.1.1-rtm-30846") - .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("ClientIpAddress") - .HasColumnName("ClientIpAddress") - .HasMaxLength(64); - - b.Property("ClientName") - .HasColumnName("ClientName") - .HasMaxLength(128); - - b.Property("Comments") - .HasColumnName("Comments") - .HasMaxLength(256); - - b.Property("ConcurrencyStamp"); - - 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("EntityChangeId1"); - - 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.HasIndex("EntityChangeId1"); - - b.ToTable("AbpEntityPropertyChanges"); - }); - - modelBuilder.Entity("Volo.Abp.BackgroundJobs.BackgroundJobRecord", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("ConcurrencyStamp"); - - b.Property("CreationTime") - .HasColumnName("CreationTime"); - - b.Property("ExtraProperties") - .HasColumnName("ExtraProperties"); - - b.Property("IsAbandoned") - .ValueGeneratedOnAdd() - .HasDefaultValue(false); - - b.Property("JobArgs") - .IsRequired() - .HasMaxLength(1048576); - - b.Property("JobName") - .IsRequired() - .HasMaxLength(128); - - b.Property("LastTryTime"); - - b.Property("NextTryTime"); - - b.Property("Priority") - .ValueGeneratedOnAdd() - .HasDefaultValue((byte)15); - - b.Property("TryCount") - .ValueGeneratedOnAdd() - .HasDefaultValue((short)0); - - b.HasKey("Id"); - - b.HasIndex("IsAbandoned", "NextTryTime"); - - b.ToTable("AbpBackgroundJobs"); - }); - - 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() - .IsRequired() - .HasColumnName("ConcurrencyStamp") - .HasMaxLength(256); - - b.Property("CreationTime"); - - b.Property("CreatorId"); - - b.Property("DeleterId"); - - b.Property("DeletionTime"); - - b.Property("Email") - .HasColumnName("Email") - .HasMaxLength(256); - - b.Property("EmailConfirmed") - .ValueGeneratedOnAdd() - .HasColumnName("EmailConfirmed") - .HasDefaultValue(false); - - b.Property("ExtraProperties") - .HasColumnName("ExtraProperties"); - - b.Property("IsDeleted"); - - b.Property("LastModificationTime"); - - b.Property("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.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() - .HasForeignKey("EntityChangeId") - .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("Volo.Abp.AuditLogging.EntityChange") - .WithMany("PropertyChanges") - .HasForeignKey("EntityChangeId1"); - }); - - 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); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.cs b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.cs deleted file mode 100644 index 3725705c27..0000000000 --- a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace MyCompanyName.MyProjectName.Migrations -{ - public partial class AuditLogging_Module_Changes : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_AbpEntityPropertyChanges_AbpEntityChanges_EntityChangeId1", - table: "AbpEntityPropertyChanges"); - - migrationBuilder.DropIndex( - name: "IX_AbpEntityPropertyChanges_EntityChangeId1", - table: "AbpEntityPropertyChanges"); - - migrationBuilder.DropColumn( - name: "EntityChangeId1", - table: "AbpEntityPropertyChanges"); - - migrationBuilder.AlterColumn( - name: "IsDeleted", - table: "AbpUsers", - nullable: false, - defaultValue: false, - oldClrType: typeof(bool)); - - migrationBuilder.AlterColumn( - name: "ConcurrencyStamp", - table: "AbpUsers", - nullable: true, - oldClrType: typeof(string), - oldMaxLength: 256); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "IsDeleted", - table: "AbpUsers", - nullable: false, - oldClrType: typeof(bool), - oldDefaultValue: false); - - migrationBuilder.AlterColumn( - name: "ConcurrencyStamp", - table: "AbpUsers", - maxLength: 256, - nullable: false, - oldClrType: typeof(string), - oldNullable: true); - - migrationBuilder.AddColumn( - name: "EntityChangeId1", - table: "AbpEntityPropertyChanges", - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_AbpEntityPropertyChanges_EntityChangeId1", - table: "AbpEntityPropertyChanges", - column: "EntityChangeId1"); - - migrationBuilder.AddForeignKey( - name: "FK_AbpEntityPropertyChanges_AbpEntityChanges_EntityChangeId1", - table: "AbpEntityPropertyChanges", - column: "EntityChangeId1", - principalTable: "AbpEntityChanges", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - } - } -} diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.Designer.cs b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107113038_Initial.Designer.cs similarity index 98% rename from templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.Designer.cs rename to templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107113038_Initial.Designer.cs index cebc8eb7ba..f39ddf1cc7 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107104851_AuditLogging_Module_Changes.Designer.cs +++ b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107113038_Initial.Designer.cs @@ -10,8 +10,8 @@ using MyCompanyName.MyProjectName.EntityFrameworkCore; namespace MyCompanyName.MyProjectName.Migrations { [DbContext(typeof(MyProjectNameDbContext))] - [Migration("20190107104851_AuditLogging_Module_Changes")] - partial class AuditLogging_Module_Changes + [Migration("20190107113038_Initial")] + partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -178,6 +178,8 @@ namespace MyCompanyName.MyProjectName.Migrations b.Property("EntityChangeId"); + b.Property("EntityChangeId1"); + b.Property("NewValue") .HasColumnName("NewValue") .HasMaxLength(512); @@ -202,6 +204,8 @@ namespace MyCompanyName.MyProjectName.Migrations b.HasIndex("EntityChangeId"); + b.HasIndex("EntityChangeId1"); + b.ToTable("AbpEntityPropertyChanges"); }); @@ -618,9 +622,13 @@ namespace MyCompanyName.MyProjectName.Migrations modelBuilder.Entity("Volo.Abp.AuditLogging.EntityPropertyChange", b => { b.HasOne("Volo.Abp.AuditLogging.EntityChange") - .WithMany("PropertyChanges") + .WithMany() .HasForeignKey("EntityChangeId") .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Volo.Abp.AuditLogging.EntityChange") + .WithMany("PropertyChanges") + .HasForeignKey("EntityChangeId1"); }); modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20181218134025_Initial.cs b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107113038_Initial.cs similarity index 99% rename from templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20181218134025_Initial.cs rename to templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107113038_Initial.cs index 1f76a505a8..72aba4d129 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20181218134025_Initial.cs +++ b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/20190107113038_Initial.cs @@ -131,12 +131,12 @@ namespace MyCompanyName.MyProjectName.Migrations { Id = table.Column(nullable: false), ExtraProperties = table.Column(nullable: true), - ConcurrencyStamp = table.Column(maxLength: 256, nullable: false), + ConcurrencyStamp = table.Column(nullable: true), CreationTime = table.Column(nullable: false), CreatorId = table.Column(nullable: true), LastModificationTime = table.Column(nullable: true), LastModifierId = table.Column(nullable: true), - IsDeleted = table.Column(nullable: false), + IsDeleted = table.Column(nullable: false, defaultValue: false), DeleterId = table.Column(nullable: true), DeletionTime = table.Column(nullable: true), TenantId = table.Column(nullable: true), @@ -256,9 +256,9 @@ namespace MyCompanyName.MyProjectName.Migrations name: "AbpUserLogins", columns: table => new { - TenantId = table.Column(nullable: true), UserId = table.Column(nullable: false), LoginProvider = table.Column(maxLength: 64, nullable: false), + TenantId = table.Column(nullable: true), ProviderKey = table.Column(maxLength: 196, nullable: false), ProviderDisplayName = table.Column(maxLength: 128, nullable: true) }, @@ -277,9 +277,9 @@ namespace MyCompanyName.MyProjectName.Migrations name: "AbpUserRoles", columns: table => new { - TenantId = table.Column(nullable: true), UserId = table.Column(nullable: false), - RoleId = table.Column(nullable: false) + RoleId = table.Column(nullable: false), + TenantId = table.Column(nullable: true) }, constraints: table => { @@ -302,10 +302,10 @@ namespace MyCompanyName.MyProjectName.Migrations name: "AbpUserTokens", columns: table => new { - TenantId = table.Column(nullable: true), UserId = table.Column(nullable: false), LoginProvider = table.Column(maxLength: 64, nullable: false), Name = table.Column(maxLength: 128, nullable: false), + TenantId = table.Column(nullable: true), Value = table.Column(nullable: true) }, constraints: table => diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/MyProjectNameDbContextModelSnapshot.cs b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/MyProjectNameDbContextModelSnapshot.cs index b09d2a1f9f..a1e702f708 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/MyProjectNameDbContextModelSnapshot.cs +++ b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/Migrations/MyProjectNameDbContextModelSnapshot.cs @@ -176,6 +176,8 @@ namespace MyCompanyName.MyProjectName.Migrations b.Property("EntityChangeId"); + b.Property("EntityChangeId1"); + b.Property("NewValue") .HasColumnName("NewValue") .HasMaxLength(512); @@ -200,6 +202,8 @@ namespace MyCompanyName.MyProjectName.Migrations b.HasIndex("EntityChangeId"); + b.HasIndex("EntityChangeId1"); + b.ToTable("AbpEntityPropertyChanges"); }); @@ -616,9 +620,13 @@ namespace MyCompanyName.MyProjectName.Migrations modelBuilder.Entity("Volo.Abp.AuditLogging.EntityPropertyChange", b => { b.HasOne("Volo.Abp.AuditLogging.EntityChange") - .WithMany("PropertyChanges") + .WithMany() .HasForeignKey("EntityChangeId") .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Volo.Abp.AuditLogging.EntityChange") + .WithMany("PropertyChanges") + .HasForeignKey("EntityChangeId1"); }); modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => diff --git a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/MyCompanyName.MyProjectName.EntityFrameworkCore.csproj b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/MyCompanyName.MyProjectName.EntityFrameworkCore.csproj index 4fa814320c..7788dcfdea 100644 --- a/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/MyCompanyName.MyProjectName.EntityFrameworkCore.csproj +++ b/templates/mvc/src/MyCompanyName.MyProjectName.EntityFrameworkCore/MyCompanyName.MyProjectName.EntityFrameworkCore.csproj @@ -9,6 +9,8 @@ + + diff --git a/templates/service/host/IdentityServerHost/IdentityServerHost.csproj b/templates/service/host/IdentityServerHost/IdentityServerHost.csproj index 56c6a75b51..a41a8ffac5 100644 --- a/templates/service/host/IdentityServerHost/IdentityServerHost.csproj +++ b/templates/service/host/IdentityServerHost/IdentityServerHost.csproj @@ -27,6 +27,7 @@ + diff --git a/templates/service/host/IdentityServerHost/Migrations/20181218135354_Initial.Designer.cs b/templates/service/host/IdentityServerHost/Migrations/20190107114341_Initial.Designer.cs similarity index 96% rename from templates/service/host/IdentityServerHost/Migrations/20181218135354_Initial.Designer.cs rename to templates/service/host/IdentityServerHost/Migrations/20190107114341_Initial.Designer.cs index 757aa9d169..1dd595dfd1 100644 --- a/templates/service/host/IdentityServerHost/Migrations/20181218135354_Initial.Designer.cs +++ b/templates/service/host/IdentityServerHost/Migrations/20190107114341_Initial.Designer.cs @@ -10,14 +10,14 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace IdentityServerHost.Migrations { [DbContext(typeof(DemoAppDbContext))] - [Migration("20181218135354_Initial")] + [Migration("20190107114341_Initial")] partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.1.1-rtm-30846") + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); @@ -134,17 +134,19 @@ namespace IdentityServerHost.Migrations b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .IsRequired() - .HasColumnName("ConcurrencyStamp") - .HasMaxLength(256); + .HasColumnName("ConcurrencyStamp"); - b.Property("CreationTime"); + b.Property("CreationTime") + .HasColumnName("CreationTime"); - b.Property("CreatorId"); + b.Property("CreatorId") + .HasColumnName("CreatorId"); - b.Property("DeleterId"); + b.Property("DeleterId") + .HasColumnName("DeleterId"); - b.Property("DeletionTime"); + b.Property("DeletionTime") + .HasColumnName("DeletionTime"); b.Property("Email") .HasColumnName("Email") @@ -158,11 +160,16 @@ namespace IdentityServerHost.Migrations b.Property("ExtraProperties") .HasColumnName("ExtraProperties"); - b.Property("IsDeleted"); + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnName("IsDeleted") + .HasDefaultValue(false); - b.Property("LastModificationTime"); + b.Property("LastModificationTime") + .HasColumnName("LastModificationTime"); - b.Property("LastModifierId"); + b.Property("LastModifierId") + .HasColumnName("LastModifierId"); b.Property("LockoutEnabled") .ValueGeneratedOnAdd() diff --git a/templates/service/host/IdentityServerHost/Migrations/20181218135354_Initial.cs b/templates/service/host/IdentityServerHost/Migrations/20190107114341_Initial.cs similarity index 99% rename from templates/service/host/IdentityServerHost/Migrations/20181218135354_Initial.cs rename to templates/service/host/IdentityServerHost/Migrations/20190107114341_Initial.cs index cab668b256..ddb2f14c1c 100644 --- a/templates/service/host/IdentityServerHost/Migrations/20181218135354_Initial.cs +++ b/templates/service/host/IdentityServerHost/Migrations/20190107114341_Initial.cs @@ -52,12 +52,12 @@ namespace IdentityServerHost.Migrations { Id = table.Column(nullable: false), ExtraProperties = table.Column(nullable: true), - ConcurrencyStamp = table.Column(maxLength: 256, nullable: false), + ConcurrencyStamp = table.Column(nullable: true), CreationTime = table.Column(nullable: false), CreatorId = table.Column(nullable: true), LastModificationTime = table.Column(nullable: true), LastModifierId = table.Column(nullable: true), - IsDeleted = table.Column(nullable: false), + IsDeleted = table.Column(nullable: false, defaultValue: false), DeleterId = table.Column(nullable: true), DeletionTime = table.Column(nullable: true), TenantId = table.Column(nullable: true), @@ -170,10 +170,10 @@ namespace IdentityServerHost.Migrations name: "IdentityServerPersistedGrants", columns: table => new { + Key = table.Column(maxLength: 200, nullable: false), Id = table.Column(nullable: false), ExtraProperties = table.Column(nullable: true), ConcurrencyStamp = table.Column(nullable: true), - Key = table.Column(maxLength: 200, nullable: false), Type = table.Column(maxLength: 50, nullable: false), SubjectId = table.Column(maxLength: 200, nullable: true), ClientId = table.Column(maxLength: 200, nullable: false), @@ -232,9 +232,9 @@ namespace IdentityServerHost.Migrations name: "AbpUserLogins", columns: table => new { - TenantId = table.Column(nullable: true), UserId = table.Column(nullable: false), LoginProvider = table.Column(maxLength: 64, nullable: false), + TenantId = table.Column(nullable: true), ProviderKey = table.Column(maxLength: 196, nullable: false), ProviderDisplayName = table.Column(maxLength: 128, nullable: true) }, @@ -253,9 +253,9 @@ namespace IdentityServerHost.Migrations name: "AbpUserRoles", columns: table => new { - TenantId = table.Column(nullable: true), UserId = table.Column(nullable: false), - RoleId = table.Column(nullable: false) + RoleId = table.Column(nullable: false), + TenantId = table.Column(nullable: true) }, constraints: table => { @@ -278,10 +278,10 @@ namespace IdentityServerHost.Migrations name: "AbpUserTokens", columns: table => new { - TenantId = table.Column(nullable: true), UserId = table.Column(nullable: false), LoginProvider = table.Column(maxLength: 64, nullable: false), Name = table.Column(maxLength: 128, nullable: false), + TenantId = table.Column(nullable: true), Value = table.Column(nullable: true) }, constraints: table => @@ -340,11 +340,11 @@ namespace IdentityServerHost.Migrations name: "IdentityServerApiSecrets", columns: table => new { - Expiration = table.Column(nullable: true), Type = table.Column(maxLength: 32, nullable: false), Value = table.Column(maxLength: 196, nullable: false), + ApiResourceId = table.Column(nullable: false), Description = table.Column(maxLength: 256, nullable: true), - ApiResourceId = table.Column(nullable: false) + Expiration = table.Column(nullable: true) }, constraints: table => { @@ -508,11 +508,11 @@ namespace IdentityServerHost.Migrations name: "IdentityServerClientSecrets", columns: table => new { - Expiration = table.Column(nullable: true), Type = table.Column(maxLength: 32, nullable: false), Value = table.Column(maxLength: 196, nullable: false), + ClientId = table.Column(nullable: false), Description = table.Column(maxLength: 256, nullable: true), - ClientId = table.Column(nullable: false) + Expiration = table.Column(nullable: true) }, constraints: table => { diff --git a/templates/service/host/IdentityServerHost/Migrations/DemoAppDbContextModelSnapshot.cs b/templates/service/host/IdentityServerHost/Migrations/DemoAppDbContextModelSnapshot.cs index 8961166967..2a102778ee 100644 --- a/templates/service/host/IdentityServerHost/Migrations/DemoAppDbContextModelSnapshot.cs +++ b/templates/service/host/IdentityServerHost/Migrations/DemoAppDbContextModelSnapshot.cs @@ -15,7 +15,7 @@ namespace IdentityServerHost.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.1.1-rtm-30846") + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); @@ -132,17 +132,19 @@ namespace IdentityServerHost.Migrations b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .IsRequired() - .HasColumnName("ConcurrencyStamp") - .HasMaxLength(256); + .HasColumnName("ConcurrencyStamp"); - b.Property("CreationTime"); + b.Property("CreationTime") + .HasColumnName("CreationTime"); - b.Property("CreatorId"); + b.Property("CreatorId") + .HasColumnName("CreatorId"); - b.Property("DeleterId"); + b.Property("DeleterId") + .HasColumnName("DeleterId"); - b.Property("DeletionTime"); + b.Property("DeletionTime") + .HasColumnName("DeletionTime"); b.Property("Email") .HasColumnName("Email") @@ -156,11 +158,16 @@ namespace IdentityServerHost.Migrations b.Property("ExtraProperties") .HasColumnName("ExtraProperties"); - b.Property("IsDeleted"); + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnName("IsDeleted") + .HasDefaultValue(false); - b.Property("LastModificationTime"); + b.Property("LastModificationTime") + .HasColumnName("LastModificationTime"); - b.Property("LastModifierId"); + b.Property("LastModifierId") + .HasColumnName("LastModifierId"); b.Property("LockoutEnabled") .ValueGeneratedOnAdd() diff --git a/templates/service/host/MyCompanyName.MyProjectName.Host/DemoAppDbContext.cs b/templates/service/host/MyCompanyName.MyProjectName.Host/DemoAppDbContext.cs index 80740f67f6..1b3540e00b 100644 --- a/templates/service/host/MyCompanyName.MyProjectName.Host/DemoAppDbContext.cs +++ b/templates/service/host/MyCompanyName.MyProjectName.Host/DemoAppDbContext.cs @@ -12,7 +12,7 @@ namespace MyCompanyName.MyProjectName.Host public DemoAppDbContext(DbContextOptions options) : base(options) { - + } protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/templates/service/host/MyCompanyName.MyProjectName.Host/Logs/logs.txt b/templates/service/host/MyCompanyName.MyProjectName.Host/Logs/logs.txt index 9e865a4b7d..7cef254f44 100644 --- a/templates/service/host/MyCompanyName.MyProjectName.Host/Logs/logs.txt +++ b/templates/service/host/MyCompanyName.MyProjectName.Host/Logs/logs.txt @@ -135,3 +135,209 @@ 2018-10-30 18:17:38.171 +03:00 [INF] Request finished in 8.1569ms 200 text/html 2018-10-30 18:17:38.401 +03:00 [INF] Request starting HTTP/1.1 GET http://localhost:57992/swagger/v1/swagger.json 2018-10-30 18:17:38.581 +03:00 [INF] Request finished in 179.8033ms 200 application/json +2019-01-07 14:46:19.756 +03:00 [INF] Starting web host. +2019-01-07 14:46:21.104 +03:00 [INF] User profile is available. Using 'C:\Users\halil\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. +2019-01-07 14:46:21.168 +03:00 [INF] Loaded modules: +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Castle.AbpCastleCoreModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Autofac.AbpAutofacModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.VirtualFileSystem.AbpVirtualFileSystemModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Localization.AbpLocalizationAbstractionsModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Security.AbpSecurityModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Settings.AbpSettingsModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Localization.AbpLocalizationModule +2019-01-07 14:46:21.168 +03:00 [INF] - MyCompanyName.MyProjectName.MyProjectNameDomainSharedModule +2019-01-07 14:46:21.168 +03:00 [INF] - MyCompanyName.MyProjectName.MyProjectNameDomainModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Data.AbpDataModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Timing.AbpTimingModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Json.AbpJsonModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Threading.AbpThreadingModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.MultiTenancy.AbpMultiTenancyAbstractionsModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Auditing.AbpAuditingModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.EventBus.AbpEventBusModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Guids.AbpGuidsModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Uow.AbpUnitOfWorkModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.ObjectMapping.AbpObjectMappingModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Domain.AbpDddDomainModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Validation.AbpValidationModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Authorization.AbpAuthorizationModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Http.AbpHttpAbstractionsModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.Application.AbpDddApplicationModule +2019-01-07 14:46:21.168 +03:00 [INF] - MyCompanyName.MyProjectName.MyProjectNameApplicationContractsModule +2019-01-07 14:46:21.168 +03:00 [INF] - Volo.Abp.AutoMapper.AbpAutoMapperModule +2019-01-07 14:46:21.168 +03:00 [INF] - MyCompanyName.MyProjectName.MyProjectNameApplicationModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.EntityFrameworkCore.AbpEntityFrameworkCoreModule +2019-01-07 14:46:21.169 +03:00 [INF] - MyCompanyName.MyProjectName.EntityFrameworkCore.MyProjectNameEntityFrameworkCoreModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.Http.AbpHttpModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.UI.AbpUiModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.AspNetCore.AbpAspNetCoreModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.ApiVersioning.AbpApiVersioningAbstractionsModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.AspNetCore.Mvc.AbpAspNetCoreMvcModule +2019-01-07 14:46:21.169 +03:00 [INF] - MyCompanyName.MyProjectName.MyProjectNameHttpApiModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.PermissionManagement.AbpPermissionManagementDomainSharedModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.Serialization.AbpSerializationModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.Caching.AbpCachingModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.PermissionManagement.AbpPermissionManagementDomainModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.PermissionManagement.EntityFrameworkCore.AbpPermissionManagementEntityFrameworkCoreModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.SettingManagement.AbpSettingManagementDomainSharedModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.SettingManagement.AbpSettingManagementDomainModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.SettingManagement.EntityFrameworkCore.AbpSettingManagementEntityFrameworkCoreModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.AuditLogging.AbpAuditLoggingDomainSharedModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.AuditLogging.AbpAuditLoggingDomainModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.AuditLogging.EntityFrameworkCore.AbpAuditLoggingEntityFrameworkCoreModule +2019-01-07 14:46:21.169 +03:00 [INF] - Volo.Abp.EntityFrameworkCore.SqlServer.AbpEntityFrameworkCoreSqlServerModule +2019-01-07 14:46:21.169 +03:00 [INF] - MyCompanyName.MyProjectName.Host.DemoAppModule +2019-01-07 14:46:21.213 +03:00 [DBG] No class found with auto mapping attributes. +2019-01-07 14:46:21.668 +03:00 [FTL] Application startup exception +System.Data.SqlClient.SqlException (0x80131904): Cannot open database "MyProjectNameCache" requested by the login. The login failed. +Login failed for user 'MicrosoftAccount\halilibrahimkalkan@outlook.com'. + at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken) + at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) + at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) + at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) + at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) + at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) + at System.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen() +--- End of stack trace from previous location where exception was thrown --- + at Microsoft.Extensions.Caching.SqlServer.DatabaseOperations.GetCacheItemAsync(String key, Boolean includeValue, CancellationToken token) + at Microsoft.Extensions.Caching.SqlServer.DatabaseOperations.GetCacheItemAsync(String key, CancellationToken token) + at Microsoft.Extensions.Caching.SqlServer.SqlServerCache.GetAsync(String key, CancellationToken token) + at Volo.Abp.Caching.DistributedCache`1.GetAsync(String key, CancellationToken token) in D:\Github\abp\framework\src\Volo.Abp.Caching\Volo\Abp\Caching\DistributedCache.cs:line 57 + at Volo.Abp.SettingManagement.SettingStore.GetCacheItemAsync(String name, String providerName, String providerKey) in D:\Github\abp\modules\setting-management\src\Volo.Abp.SettingManagement.Domain\Volo\Abp\SettingManagement\SettingStore.cs:line 66 + at Volo.Abp.SettingManagement.SettingStore.GetOrNullAsync(String name, String providerName, String providerKey) in D:\Github\abp\modules\setting-management\src\Volo.Abp.SettingManagement.Domain\Volo\Abp\SettingManagement\SettingStore.cs:line 29 + at Volo.Abp.Settings.SettingManager.GetOrNullValueFromProvidersAsync(String providerKey, IEnumerable`1 providers, SettingDefinition setting) in D:\Github\abp\framework\src\Volo.Abp.Settings\Volo\Abp\Settings\SettingManager.cs:line 217 + at Volo.Abp.Settings.SettingManager.GetOrNullInternalAsync(String name, String providerName, String providerKey, Boolean fallback) in D:\Github\abp\framework\src\Volo.Abp.Settings\Volo\Abp\Settings\SettingManager.cs:line 201 + at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task) + at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() + at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) +--- End of stack trace from previous location where exception was thrown --- + at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot) +--- End of stack trace from previous location where exception was thrown --- + at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task) + at Nito.AsyncEx.AsyncContext.Run[TResult](Func`1 action) + at Volo.Abp.Threading.AsyncHelper.RunSync[TResult](Func`1 func) in D:\Github\abp\framework\src\Volo.Abp.Core\Volo\Abp\Threading\AsyncHelper.cs:line 60 + at Volo.Abp.Settings.SettingManagerSyncExtensions.GetOrNull(ISettingManager settingManager, String name) in D:\Github\abp\framework\src\Volo.Abp.Settings\Volo\Abp\Settings\SettingManagerSyncExtensions.cs:line 13 + at Microsoft.AspNetCore.Builder.AbpApplicationBuilderExtensions.UseAbpRequestLocalization(IApplicationBuilder app) in D:\Github\abp\framework\src\Volo.Abp.AspNetCore\Microsoft\AspNetCore\Builder\AbpApplicationBuilderExtensions.cs:line 54 + at MyCompanyName.MyProjectName.Host.DemoAppModule.OnApplicationInitialization(ApplicationInitializationContext context) in D:\Github\abp\templates\service\host\MyCompanyName.MyProjectName.Host\DemoAppModule.cs:line 109 + at Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor.Initialize(ApplicationInitializationContext context, IAbpModule module) in D:\Github\abp\framework\src\Volo.Abp.Core\Volo\Abp\Modularity\DefaultModuleLifecycleContributor.cs:line 7 + at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context) in D:\Github\abp\framework\src\Volo.Abp.Core\Volo\Abp\Modularity\ModuleManager.cs:line 41 + at Volo.Abp.AbpApplicationBase.InitializeModules() in D:\Github\abp\framework\src\Volo.Abp.Core\Volo\Abp\AbpApplicationBase.cs:line 72 + at Volo.Abp.AbpApplicationWithExternalServiceProvider.Initialize(IServiceProvider serviceProvider) in D:\Github\abp\framework\src\Volo.Abp.Core\Volo\Abp\AbpApplicationWithExternalServiceProvider.cs:line 27 + at Microsoft.AspNetCore.Builder.AbpApplicationBuilderExtensions.InitializeApplication(IApplicationBuilder app) in D:\Github\abp\framework\src\Volo.Abp.AspNetCore\Microsoft\AspNetCore\Builder\AbpApplicationBuilderExtensions.cs:line 27 + at MyCompanyName.MyProjectName.Host.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in D:\Github\abp\templates\service\host\MyCompanyName.MyProjectName.Host\Startup.cs:line 24 +--- End of stack trace from previous location where exception was thrown --- + at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app) + at Microsoft.AspNetCore.Mvc.Internal.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.g__MiddlewareFilterBuilder|0(IApplicationBuilder builder) + at Microsoft.AspNetCore.Server.IISIntegration.IISSetupFilter.<>c__DisplayClass4_0.b__0(IApplicationBuilder app) + at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.b__0(IApplicationBuilder builder) + at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() +ClientConnectionId:f4f9905c-c66c-41ee-8497-649f2e111e03 +Error Number:4060,State:1,Class:11 +2019-01-07 14:46:22.022 +03:00 [INF] Request starting HTTP/1.1 GET http://localhost:57992/ +2019-01-07 14:46:22.061 +03:00 [INF] Request finished in 39.0742ms 500 text/html; charset=utf-8 +2019-01-07 14:46:39.070 +03:00 [INF] Request starting HTTP/1.1 GET http://localhost:57992/ +2019-01-07 14:46:39.085 +03:00 [INF] Request finished in 14.9782ms 500 text/html; charset=utf-8 +2019-01-07 14:46:48.817 +03:00 [INF] Request starting HTTP/1.1 GET http://localhost:57992/ +2019-01-07 14:46:48.855 +03:00 [INF] Request finished in 38.2239ms 500 text/html; charset=utf-8 +2019-01-07 14:47:42.990 +03:00 [INF] Starting web host. +2019-01-07 14:47:44.287 +03:00 [INF] User profile is available. Using 'C:\Users\halil\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. +2019-01-07 14:47:44.347 +03:00 [INF] Loaded modules: +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Castle.AbpCastleCoreModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Autofac.AbpAutofacModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.VirtualFileSystem.AbpVirtualFileSystemModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Localization.AbpLocalizationAbstractionsModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Security.AbpSecurityModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Settings.AbpSettingsModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Localization.AbpLocalizationModule +2019-01-07 14:47:44.347 +03:00 [INF] - MyCompanyName.MyProjectName.MyProjectNameDomainSharedModule +2019-01-07 14:47:44.347 +03:00 [INF] - MyCompanyName.MyProjectName.MyProjectNameDomainModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Data.AbpDataModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Timing.AbpTimingModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Json.AbpJsonModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Threading.AbpThreadingModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.MultiTenancy.AbpMultiTenancyAbstractionsModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Auditing.AbpAuditingModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.EventBus.AbpEventBusModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Guids.AbpGuidsModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Uow.AbpUnitOfWorkModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.ObjectMapping.AbpObjectMappingModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Domain.AbpDddDomainModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Validation.AbpValidationModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Authorization.AbpAuthorizationModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Http.AbpHttpAbstractionsModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Application.AbpDddApplicationModule +2019-01-07 14:47:44.347 +03:00 [INF] - MyCompanyName.MyProjectName.MyProjectNameApplicationContractsModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.AutoMapper.AbpAutoMapperModule +2019-01-07 14:47:44.347 +03:00 [INF] - MyCompanyName.MyProjectName.MyProjectNameApplicationModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.EntityFrameworkCore.AbpEntityFrameworkCoreModule +2019-01-07 14:47:44.347 +03:00 [INF] - MyCompanyName.MyProjectName.EntityFrameworkCore.MyProjectNameEntityFrameworkCoreModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Http.AbpHttpModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.UI.AbpUiModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.AspNetCore.AbpAspNetCoreModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.ApiVersioning.AbpApiVersioningAbstractionsModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.AspNetCore.Mvc.AbpAspNetCoreMvcModule +2019-01-07 14:47:44.347 +03:00 [INF] - MyCompanyName.MyProjectName.MyProjectNameHttpApiModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.PermissionManagement.AbpPermissionManagementDomainSharedModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Serialization.AbpSerializationModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.Caching.AbpCachingModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.PermissionManagement.AbpPermissionManagementDomainModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.PermissionManagement.EntityFrameworkCore.AbpPermissionManagementEntityFrameworkCoreModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.SettingManagement.AbpSettingManagementDomainSharedModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.SettingManagement.AbpSettingManagementDomainModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.SettingManagement.EntityFrameworkCore.AbpSettingManagementEntityFrameworkCoreModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.AuditLogging.AbpAuditLoggingDomainSharedModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.AuditLogging.AbpAuditLoggingDomainModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.AuditLogging.EntityFrameworkCore.AbpAuditLoggingEntityFrameworkCoreModule +2019-01-07 14:47:44.347 +03:00 [INF] - Volo.Abp.EntityFrameworkCore.SqlServer.AbpEntityFrameworkCoreSqlServerModule +2019-01-07 14:47:44.347 +03:00 [INF] - MyCompanyName.MyProjectName.Host.DemoAppModule +2019-01-07 14:47:44.390 +03:00 [DBG] No class found with auto mapping attributes. +2019-01-07 14:47:44.806 +03:00 [FTL] Application startup exception +System.Data.SqlClient.SqlException (0x80131904): Invalid object name 'dbo.TestCache'. + at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) + at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) + at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) + at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) + at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() + at System.Data.SqlClient.SqlDataReader.get_MetaData() + at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) + at System.Data.SqlClient.SqlCommand.CompleteAsyncExecuteReader() + at System.Data.SqlClient.SqlCommand.InternalEndExecuteReader(IAsyncResult asyncResult, String endMethod) + at System.Data.SqlClient.SqlCommand.EndExecuteReaderInternal(IAsyncResult asyncResult) + at System.Data.SqlClient.SqlCommand.EndExecuteReader(IAsyncResult asyncResult) + at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization) +--- End of stack trace from previous location where exception was thrown --- + at Microsoft.Extensions.Caching.SqlServer.DatabaseOperations.GetCacheItemAsync(String key, Boolean includeValue, CancellationToken token) + at Microsoft.Extensions.Caching.SqlServer.DatabaseOperations.GetCacheItemAsync(String key, CancellationToken token) + at Microsoft.Extensions.Caching.SqlServer.SqlServerCache.GetAsync(String key, CancellationToken token) + at Volo.Abp.Caching.DistributedCache`1.GetAsync(String key, CancellationToken token) in D:\Github\abp\framework\src\Volo.Abp.Caching\Volo\Abp\Caching\DistributedCache.cs:line 57 + at Volo.Abp.SettingManagement.SettingStore.GetCacheItemAsync(String name, String providerName, String providerKey) in D:\Github\abp\modules\setting-management\src\Volo.Abp.SettingManagement.Domain\Volo\Abp\SettingManagement\SettingStore.cs:line 66 + at Volo.Abp.SettingManagement.SettingStore.GetOrNullAsync(String name, String providerName, String providerKey) in D:\Github\abp\modules\setting-management\src\Volo.Abp.SettingManagement.Domain\Volo\Abp\SettingManagement\SettingStore.cs:line 29 + at Volo.Abp.Settings.SettingManager.GetOrNullValueFromProvidersAsync(String providerKey, IEnumerable`1 providers, SettingDefinition setting) in D:\Github\abp\framework\src\Volo.Abp.Settings\Volo\Abp\Settings\SettingManager.cs:line 217 + at Volo.Abp.Settings.SettingManager.GetOrNullInternalAsync(String name, String providerName, String providerKey, Boolean fallback) in D:\Github\abp\framework\src\Volo.Abp.Settings\Volo\Abp\Settings\SettingManager.cs:line 201 + at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task) + at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() + at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) +--- End of stack trace from previous location where exception was thrown --- + at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot) +--- End of stack trace from previous location where exception was thrown --- + at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task) + at Nito.AsyncEx.AsyncContext.Run[TResult](Func`1 action) + at Volo.Abp.Threading.AsyncHelper.RunSync[TResult](Func`1 func) in D:\Github\abp\framework\src\Volo.Abp.Core\Volo\Abp\Threading\AsyncHelper.cs:line 60 + at Volo.Abp.Settings.SettingManagerSyncExtensions.GetOrNull(ISettingManager settingManager, String name) in D:\Github\abp\framework\src\Volo.Abp.Settings\Volo\Abp\Settings\SettingManagerSyncExtensions.cs:line 13 + at Microsoft.AspNetCore.Builder.AbpApplicationBuilderExtensions.UseAbpRequestLocalization(IApplicationBuilder app) in D:\Github\abp\framework\src\Volo.Abp.AspNetCore\Microsoft\AspNetCore\Builder\AbpApplicationBuilderExtensions.cs:line 54 + at MyCompanyName.MyProjectName.Host.DemoAppModule.OnApplicationInitialization(ApplicationInitializationContext context) in D:\Github\abp\templates\service\host\MyCompanyName.MyProjectName.Host\DemoAppModule.cs:line 109 + at Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor.Initialize(ApplicationInitializationContext context, IAbpModule module) in D:\Github\abp\framework\src\Volo.Abp.Core\Volo\Abp\Modularity\DefaultModuleLifecycleContributor.cs:line 7 + at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context) in D:\Github\abp\framework\src\Volo.Abp.Core\Volo\Abp\Modularity\ModuleManager.cs:line 41 + at Volo.Abp.AbpApplicationBase.InitializeModules() in D:\Github\abp\framework\src\Volo.Abp.Core\Volo\Abp\AbpApplicationBase.cs:line 72 + at Volo.Abp.AbpApplicationWithExternalServiceProvider.Initialize(IServiceProvider serviceProvider) in D:\Github\abp\framework\src\Volo.Abp.Core\Volo\Abp\AbpApplicationWithExternalServiceProvider.cs:line 27 + at Microsoft.AspNetCore.Builder.AbpApplicationBuilderExtensions.InitializeApplication(IApplicationBuilder app) in D:\Github\abp\framework\src\Volo.Abp.AspNetCore\Microsoft\AspNetCore\Builder\AbpApplicationBuilderExtensions.cs:line 27 + at MyCompanyName.MyProjectName.Host.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in D:\Github\abp\templates\service\host\MyCompanyName.MyProjectName.Host\Startup.cs:line 24 +--- End of stack trace from previous location where exception was thrown --- + at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app) + at Microsoft.AspNetCore.Mvc.Internal.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.g__MiddlewareFilterBuilder|0(IApplicationBuilder builder) + at Microsoft.AspNetCore.Server.IISIntegration.IISSetupFilter.<>c__DisplayClass4_0.b__0(IApplicationBuilder app) + at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.b__0(IApplicationBuilder builder) + at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() +ClientConnectionId:d28745af-08b1-4111-a089-3f46c995c65d +Error Number:208,State:1,Class:16 +2019-01-07 14:47:44.964 +03:00 [INF] Request starting HTTP/1.1 GET http://localhost:57992/ +2019-01-07 14:47:44.998 +03:00 [INF] Request finished in 33.8928ms 500 text/html; charset=utf-8 diff --git a/templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/20181218135310_Initial.Designer.cs b/templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/20190107114531_Initial.Designer.cs similarity index 98% rename from templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/20181218135310_Initial.Designer.cs rename to templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/20190107114531_Initial.Designer.cs index 67977b2f6a..600c904f2b 100644 --- a/templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/20181218135310_Initial.Designer.cs +++ b/templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/20190107114531_Initial.Designer.cs @@ -10,14 +10,14 @@ using MyCompanyName.MyProjectName.Host; namespace MyCompanyName.MyProjectName.Host.Migrations { [DbContext(typeof(DemoAppDbContext))] - [Migration("20181218135310_Initial")] + [Migration("20190107114531_Initial")] partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.1.1-rtm-30846") + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); diff --git a/templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/20181218135310_Initial.cs b/templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/20190107114531_Initial.cs similarity index 100% rename from templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/20181218135310_Initial.cs rename to templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/20190107114531_Initial.cs diff --git a/templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/DemoAppDbContextModelSnapshot.cs b/templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/DemoAppDbContextModelSnapshot.cs index c5e59b55fd..70e88b9973 100644 --- a/templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/DemoAppDbContextModelSnapshot.cs +++ b/templates/service/host/MyCompanyName.MyProjectName.Host/Migrations/DemoAppDbContextModelSnapshot.cs @@ -15,7 +15,7 @@ namespace MyCompanyName.MyProjectName.Host.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.1.1-rtm-30846") + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); diff --git a/templates/service/host/MyCompanyName.MyProjectName.Host/MyCompanyName.MyProjectName.Host.csproj b/templates/service/host/MyCompanyName.MyProjectName.Host/MyCompanyName.MyProjectName.Host.csproj index f3e3056f84..b034148995 100644 --- a/templates/service/host/MyCompanyName.MyProjectName.Host/MyCompanyName.MyProjectName.Host.csproj +++ b/templates/service/host/MyCompanyName.MyProjectName.Host/MyCompanyName.MyProjectName.Host.csproj @@ -32,6 +32,7 @@ + From c1ee174bee989be082f3902c64b184cd1dba1666 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Mon, 7 Jan 2019 14:51:58 +0300 Subject: [PATCH 19/36] Incemented version to 0.11. --- common.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.props b/common.props index eb3155d6f4..0c8d443f16 100644 --- a/common.props +++ b/common.props @@ -1,7 +1,7 @@ latest - 0.10.0 + 0.11.0 $(NoWarn);CS1591 https://abp.io/assets/abp_nupkg.png https://abp.io From 49901a76397308e7acbdc9819cd63e33f18b3b4a Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 7 Jan 2019 15:03:23 +0300 Subject: [PATCH 20/36] Resolved #680 : Revert document change done with 680 --- docs/en/Tutorials/AspNetCore-Mvc/Part-I.md | 16 +--------------- .../Acme.BookStore.Application.csproj | 2 +- .../Acme.BookStore.Domain.csproj | 2 +- .../Acme.BookStore.EntityFrameworkCore.csproj | 8 ++++---- .../EntityFrameworkCore/BookStoreDbContext.cs | 4 ---- .../Acme.BookStore.Web/Acme.BookStore.Web.csproj | 8 ++++---- .../Acme.BookStore.Application.Tests.csproj | 4 ++-- .../Acme.BookStore.ConsoleApiClient.csproj | 4 ++-- .../Acme.BookStore.Web.Tests.csproj | 2 +- 9 files changed, 16 insertions(+), 34 deletions(-) diff --git a/docs/en/Tutorials/AspNetCore-Mvc/Part-I.md b/docs/en/Tutorials/AspNetCore-Mvc/Part-I.md index 2afe26e7d2..6db6766c0b 100644 --- a/docs/en/Tutorials/AspNetCore-Mvc/Part-I.md +++ b/docs/en/Tutorials/AspNetCore-Mvc/Part-I.md @@ -85,21 +85,7 @@ EF Core requires you to relate entities with your DbContext. The easiest way to public class BookStoreDbContext : AbpDbContext { public DbSet Book { get; set; } - - public BookStoreDbContext(DbContextOptions options) - : base(options) - { - - } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - - modelBuilder.Entity( - b => b.ConfigureExtraProperties() - ); - } + ... } ```` diff --git a/samples/BookStore/src/Acme.BookStore.Application/Acme.BookStore.Application.csproj b/samples/BookStore/src/Acme.BookStore.Application/Acme.BookStore.Application.csproj index 85ac94b35c..3ee243de7b 100644 --- a/samples/BookStore/src/Acme.BookStore.Application/Acme.BookStore.Application.csproj +++ b/samples/BookStore/src/Acme.BookStore.Application/Acme.BookStore.Application.csproj @@ -7,7 +7,7 @@ - + diff --git a/samples/BookStore/src/Acme.BookStore.Domain/Acme.BookStore.Domain.csproj b/samples/BookStore/src/Acme.BookStore.Domain/Acme.BookStore.Domain.csproj index 3cd414eeec..525f8e7568 100644 --- a/samples/BookStore/src/Acme.BookStore.Domain/Acme.BookStore.Domain.csproj +++ b/samples/BookStore/src/Acme.BookStore.Domain/Acme.BookStore.Domain.csproj @@ -6,7 +6,7 @@ - + diff --git a/samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/Acme.BookStore.EntityFrameworkCore.csproj b/samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/Acme.BookStore.EntityFrameworkCore.csproj index aec9870017..a3bce1956f 100644 --- a/samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/Acme.BookStore.EntityFrameworkCore.csproj +++ b/samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/Acme.BookStore.EntityFrameworkCore.csproj @@ -12,10 +12,10 @@ - - - - + + + + diff --git a/samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContext.cs b/samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContext.cs index 40e8a79dd0..ed7e9862ed 100644 --- a/samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContext.cs +++ b/samples/BookStore/src/Acme.BookStore.EntityFrameworkCore/EntityFrameworkCore/BookStoreDbContext.cs @@ -21,10 +21,6 @@ namespace Acme.BookStore.EntityFrameworkCore { base.OnModelCreating(modelBuilder); - modelBuilder.Entity( - b => b.ConfigureExtraProperties() - ); - modelBuilder.ConfigureIdentity(); modelBuilder.ConfigurePermissionManagement(); modelBuilder.ConfigureSettingManagement(); diff --git a/samples/BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj b/samples/BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj index 21d3bd0ff6..969b152ef4 100644 --- a/samples/BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj +++ b/samples/BookStore/src/Acme.BookStore.Web/Acme.BookStore.Web.csproj @@ -27,10 +27,10 @@ - - - - + + + + diff --git a/samples/BookStore/test/Acme.BookStore.Application.Tests/Acme.BookStore.Application.Tests.csproj b/samples/BookStore/test/Acme.BookStore.Application.Tests/Acme.BookStore.Application.Tests.csproj index d9875549ff..ca55850f68 100644 --- a/samples/BookStore/test/Acme.BookStore.Application.Tests/Acme.BookStore.Application.Tests.csproj +++ b/samples/BookStore/test/Acme.BookStore.Application.Tests/Acme.BookStore.Application.Tests.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/Acme.BookStore.ConsoleApiClient.csproj b/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/Acme.BookStore.ConsoleApiClient.csproj index 84d6d00e79..6df3ffa32d 100644 --- a/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/Acme.BookStore.ConsoleApiClient.csproj +++ b/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/Acme.BookStore.ConsoleApiClient.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/samples/BookStore/test/Acme.BookStore.Web.Tests/Acme.BookStore.Web.Tests.csproj b/samples/BookStore/test/Acme.BookStore.Web.Tests/Acme.BookStore.Web.Tests.csproj index 2db791b6bf..d4e9e1ee74 100644 --- a/samples/BookStore/test/Acme.BookStore.Web.Tests/Acme.BookStore.Web.Tests.csproj +++ b/samples/BookStore/test/Acme.BookStore.Web.Tests/Acme.BookStore.Web.Tests.csproj @@ -15,7 +15,7 @@ - + From 69d6ce4ab2481867fd38f49cccb7fdd43ad413c6 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 7 Jan 2019 17:10:25 +0300 Subject: [PATCH 21/36] Update AbpInputTagHelperService.cs --- .../TagHelpers/Form/AbpInputTagHelperService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs index 043ba623fe..d4cc92deb5 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs @@ -258,7 +258,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form return ""; } - string text = ""; + var text = ""; if (!string.IsNullOrEmpty(TagHelper.InfoText)) { From b4cafbdbee4b4e59f3a5a2883293a6d114a9a369 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Mon, 7 Jan 2019 22:00:54 +0300 Subject: [PATCH 22/36] Remove unnecessary dependency. --- framework/src/Volo.Abp.Http/Volo.Abp.Http.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/src/Volo.Abp.Http/Volo.Abp.Http.csproj b/framework/src/Volo.Abp.Http/Volo.Abp.Http.csproj index 1b2d7caa8d..df1e907450 100644 --- a/framework/src/Volo.Abp.Http/Volo.Abp.Http.csproj +++ b/framework/src/Volo.Abp.Http/Volo.Abp.Http.csproj @@ -14,7 +14,6 @@ - From 810000299421679a40ea734a8232e015b400a30a Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Mon, 7 Jan 2019 22:34:51 +0300 Subject: [PATCH 23/36] Resolved #719: Create Volo.Abp.IdentityModel package. --- framework/Volo.Abp.sln | 9 ++- .../Volo.Abp.Http.Client.IdentityModel.csproj | 1 + .../AbpHttpClientIdentityModelModule.cs | 10 +--- ...delRemoteServiceHttpClientAuthenticator.cs | 56 +++++++++++++++++++ .../RemoteServiceConfigurationExtensions.cs | 6 +- .../IHttpClientAuthenticator.cs | 9 --- .../IRemoteServiceHttpClientAuthenticator.cs | 9 +++ ...llRemoteServiceHttpClientAuthenticator.cs} | 4 +- ...teServiceHttpClientAuthenticateContext.cs} | 4 +- .../DynamicHttpProxyInterceptor.cs | 6 +- .../Volo.Abp.IdentityModel.csproj | 21 +++++++ .../IdentityModel/AbpIdentityModelModule.cs | 15 +++++ .../IIdentityModelHttpClientAuthenticator.cs | 9 +++ .../IdentityClientConfiguration.cs | 2 +- .../IdentityClientConfigurationDictionary.cs | 2 +- .../IdentityModel/IdentityClientOptions.cs | 2 +- ...ntityModelHttpClientAuthenticateContext.cs | 27 +++++++++ ...elRemoteServiceHttpClientAuthenticator.cs} | 36 +++--------- nupkg/common.ps1 | 1 + 19 files changed, 172 insertions(+), 57 deletions(-) create mode 100644 framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs delete mode 100644 framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IHttpClientAuthenticator.cs create mode 100644 framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IRemoteServiceHttpClientAuthenticator.cs rename framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/{NullHttpClientAuthenticator.cs => NullRemoteServiceHttpClientAuthenticator.cs} (52%) rename framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/{HttpClientAuthenticateContext.cs => RemoteServiceHttpClientAuthenticateContext.cs} (80%) create mode 100644 framework/src/Volo.Abp.IdentityModel/Volo.Abp.IdentityModel.csproj create mode 100644 framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/AbpIdentityModelModule.cs create mode 100644 framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IIdentityModelHttpClientAuthenticator.cs rename framework/src/{Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client => Volo.Abp.IdentityModel/Volo/Abp}/IdentityModel/IdentityClientConfiguration.cs (98%) rename framework/src/{Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client => Volo.Abp.IdentityModel/Volo/Abp}/IdentityModel/IdentityClientConfigurationDictionary.cs (89%) rename framework/src/{Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client => Volo.Abp.IdentityModel/Volo/Abp}/IdentityModel/IdentityClientOptions.cs (84%) create mode 100644 framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelHttpClientAuthenticateContext.cs rename framework/src/{Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs => Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs} (69%) diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index 36aef8acce..3b18df4e23 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -218,7 +218,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Security.Tests", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Settings.Tests", "test\Volo.Abp.Settings.Tests\Volo.Abp.Settings.Tests.csproj", "{5F3A2D1E-EA89-40A7-8D2F-FB4EB2092403}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Http.Client.IdentityModel", "src\Volo.Abp.Http.Client.IdentityModel\Volo.Abp.Http.Client.IdentityModel.csproj", "{D211A446-38FA-4F97-9A95-1F004A0FFF69}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Http.Client.IdentityModel", "src\Volo.Abp.Http.Client.IdentityModel\Volo.Abp.Http.Client.IdentityModel.csproj", "{D211A446-38FA-4F97-9A95-1F004A0FFF69}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.IdentityModel", "src\Volo.Abp.IdentityModel\Volo.Abp.IdentityModel.csproj", "{64D99E19-EE25-465A-82E5-17B25F4C4E18}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -622,6 +624,10 @@ Global {D211A446-38FA-4F97-9A95-1F004A0FFF69}.Debug|Any CPU.Build.0 = Debug|Any CPU {D211A446-38FA-4F97-9A95-1F004A0FFF69}.Release|Any CPU.ActiveCfg = Release|Any CPU {D211A446-38FA-4F97-9A95-1F004A0FFF69}.Release|Any CPU.Build.0 = Release|Any CPU + {64D99E19-EE25-465A-82E5-17B25F4C4E18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {64D99E19-EE25-465A-82E5-17B25F4C4E18}.Debug|Any CPU.Build.0 = Debug|Any CPU + {64D99E19-EE25-465A-82E5-17B25F4C4E18}.Release|Any CPU.ActiveCfg = Release|Any CPU + {64D99E19-EE25-465A-82E5-17B25F4C4E18}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -728,6 +734,7 @@ Global {7CE07034-7E02-4C78-B981-F1039412CA5E} = {447C8A77-E5F0-4538-8687-7383196D04EA} {5F3A2D1E-EA89-40A7-8D2F-FB4EB2092403} = {447C8A77-E5F0-4538-8687-7383196D04EA} {D211A446-38FA-4F97-9A95-1F004A0FFF69} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} + {64D99E19-EE25-465A-82E5-17B25F4C4E18} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo.Abp.Http.Client.IdentityModel.csproj b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo.Abp.Http.Client.IdentityModel.csproj index c19bd29eb4..b96d471322 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo.Abp.Http.Client.IdentityModel.csproj +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo.Abp.Http.Client.IdentityModel.csproj @@ -16,6 +16,7 @@ + \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs index 9946083fb8..356acfe16f 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/AbpHttpClientIdentityModelModule.cs @@ -1,18 +1,14 @@ -using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.IdentityModel; using Volo.Abp.Modularity; namespace Volo.Abp.Http.Client.IdentityModel { [DependsOn( - typeof(AbpHttpClientModule) + typeof(AbpHttpClientModule), + typeof(AbpIdentityModelModule) )] public class AbpHttpClientIdentityModelModule : AbpModule { - public override void ConfigureServices(ServiceConfigurationContext context) - { - var configuration = context.Services.GetConfiguration(); - Configure(configuration); - } } } 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 new file mode 100644 index 0000000000..a5ef33e83b --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs @@ -0,0 +1,56 @@ +using System.Net.Http.Headers; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Http; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Client.Authentication; +using Volo.Abp.IdentityModel; + +namespace Volo.Abp.Http.Client.IdentityModel +{ + [Dependency(ReplaceServices = true)] + public class IdentityModelRemoteServiceHttpClientAuthenticator : IRemoteServiceHttpClientAuthenticator, ITransientDependency + { + public IHttpContextAccessor HttpContextAccessor { get; set; } + + protected IIdentityModelHttpClientAuthenticator IdentityModelHttpClientAuthenticator { get; } + + public IdentityModelRemoteServiceHttpClientAuthenticator(IIdentityModelHttpClientAuthenticator identityModelHttpClientAuthenticator) + { + IdentityModelHttpClientAuthenticator = identityModelHttpClientAuthenticator; + } + + public async Task Authenticate(RemoteServiceHttpClientAuthenticateContext context) + { + var accessToken = await GetAccessTokenFromHttpContextOrNullAsync(); + + if (accessToken != null) + { + //TODO: "Bearer" should be configurable + context.Client.DefaultRequestHeaders.Authorization + = new AuthenticationHeaderValue("Bearer", accessToken); + } + else + { + await IdentityModelHttpClientAuthenticator.Authenticate( + new IdentityModelHttpClientAuthenticateContext( + 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) + { + return null; + } + + return await httpContext.GetTokenAsync("access_token"); + } + } +} 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 b42920442f..9d1c8a71e9 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,17 +5,19 @@ namespace Volo.Abp.Http.Client { public static class RemoteServiceConfigurationExtensions { + public const string IdentityClient = "IdentityClient"; + [CanBeNull] public static string GetIdentityClient([NotNull] this RemoteServiceConfiguration configuration) { Check.NotNullOrEmpty(configuration, nameof(configuration)); - return configuration.GetOrDefault("IdentityClient"); + return configuration.GetOrDefault(IdentityClient); } public static RemoteServiceConfiguration SetIdentityClient([NotNull] this RemoteServiceConfiguration configuration, [CanBeNull] string value) { - configuration["IdentityClient"] = value; + configuration[IdentityClient] = value; return configuration; } } diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IHttpClientAuthenticator.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IHttpClientAuthenticator.cs deleted file mode 100644 index 83d6f9dd31..0000000000 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IHttpClientAuthenticator.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Threading.Tasks; - -namespace Volo.Abp.Http.Client.Authentication -{ - public interface IHttpClientAuthenticator - { - Task Authenticate(HttpClientAuthenticateContext context); - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IRemoteServiceHttpClientAuthenticator.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IRemoteServiceHttpClientAuthenticator.cs new file mode 100644 index 0000000000..920d38f2e6 --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/IRemoteServiceHttpClientAuthenticator.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.Http.Client.Authentication +{ + public interface IRemoteServiceHttpClientAuthenticator + { + Task Authenticate(RemoteServiceHttpClientAuthenticateContext context); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/NullHttpClientAuthenticator.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/NullRemoteServiceHttpClientAuthenticator.cs similarity index 52% rename from framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/NullHttpClientAuthenticator.cs rename to framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/NullRemoteServiceHttpClientAuthenticator.cs index a22ebd3674..6928f10dae 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/NullHttpClientAuthenticator.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/NullRemoteServiceHttpClientAuthenticator.cs @@ -4,9 +4,9 @@ using Volo.Abp.DependencyInjection; namespace Volo.Abp.Http.Client.Authentication { [Dependency(TryRegister = true)] - public class NullHttpClientAuthenticator : IHttpClientAuthenticator, ISingletonDependency + public class NullRemoteServiceHttpClientAuthenticator : IRemoteServiceHttpClientAuthenticator, ISingletonDependency { - public Task Authenticate(HttpClientAuthenticateContext context) + public Task Authenticate(RemoteServiceHttpClientAuthenticateContext context) { return Task.CompletedTask; } diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpClientAuthenticateContext.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/RemoteServiceHttpClientAuthenticateContext.cs similarity index 80% rename from framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpClientAuthenticateContext.cs rename to framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/RemoteServiceHttpClientAuthenticateContext.cs index 7374b79694..fff00d5bf8 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/HttpClientAuthenticateContext.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/Authentication/RemoteServiceHttpClientAuthenticateContext.cs @@ -2,7 +2,7 @@ namespace Volo.Abp.Http.Client.Authentication { - public class HttpClientAuthenticateContext + public class RemoteServiceHttpClientAuthenticateContext { public HttpClient Client { get; } @@ -10,7 +10,7 @@ namespace Volo.Abp.Http.Client.Authentication public RemoteServiceConfiguration RemoteService { get; } - public HttpClientAuthenticateContext( + public RemoteServiceHttpClientAuthenticateContext( HttpClient client, HttpRequestMessage request, RemoteServiceConfiguration remoteService) 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 f3f6e8eae6..d367c7b09e 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 @@ -27,7 +27,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying private readonly RemoteServiceOptions _remoteServiceOptions; private readonly AbpHttpClientOptions _clientOptions; private readonly IJsonSerializer _jsonSerializer; - private readonly IHttpClientAuthenticator _clientAuthenticator; + private readonly IRemoteServiceHttpClientAuthenticator _clientAuthenticator; static DynamicHttpProxyInterceptor() { @@ -42,7 +42,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying IOptionsSnapshot remoteServiceOptions, IApiDescriptionFinder apiDescriptionFinder, IJsonSerializer jsonSerializer, - IHttpClientAuthenticator clientAuthenticator) + IRemoteServiceHttpClientAuthenticator clientAuthenticator) { _httpClientFactory = httpClientFactory; _apiDescriptionFinder = apiDescriptionFinder; @@ -123,7 +123,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying AddHeaders(invocation, action, requestMessage, apiVersion); await _clientAuthenticator.Authenticate( - new HttpClientAuthenticateContext( + new RemoteServiceHttpClientAuthenticateContext( client, requestMessage, remoteServiceConfig diff --git a/framework/src/Volo.Abp.IdentityModel/Volo.Abp.IdentityModel.csproj b/framework/src/Volo.Abp.IdentityModel/Volo.Abp.IdentityModel.csproj new file mode 100644 index 0000000000..ac757528c7 --- /dev/null +++ b/framework/src/Volo.Abp.IdentityModel/Volo.Abp.IdentityModel.csproj @@ -0,0 +1,21 @@ + + + + + + netstandard2.0 + Volo.Abp.IdentityModel + Volo.Abp.IdentityModel + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/AbpIdentityModelModule.cs b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/AbpIdentityModelModule.cs new file mode 100644 index 0000000000..cadeb794a7 --- /dev/null +++ b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/AbpIdentityModelModule.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.IdentityModel +{ + public class AbpIdentityModelModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + + Configure(configuration); + } + } +} diff --git a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IIdentityModelHttpClientAuthenticator.cs b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IIdentityModelHttpClientAuthenticator.cs new file mode 100644 index 0000000000..80215263c8 --- /dev/null +++ b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IIdentityModelHttpClientAuthenticator.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.IdentityModel +{ + public interface IIdentityModelHttpClientAuthenticator + { + Task Authenticate(IdentityModelHttpClientAuthenticateContext context); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfiguration.cs b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfiguration.cs similarity index 98% rename from framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfiguration.cs rename to framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfiguration.cs index 9512328222..520195e7ce 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfiguration.cs +++ b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfiguration.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using IdentityModel; -namespace Volo.Abp.Http.Client.IdentityModel +namespace Volo.Abp.IdentityModel { public class IdentityClientConfiguration : Dictionary { diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfigurationDictionary.cs b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfigurationDictionary.cs similarity index 89% rename from framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfigurationDictionary.cs rename to framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfigurationDictionary.cs index 7f79df0b37..62c9359a74 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientConfigurationDictionary.cs +++ b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientConfigurationDictionary.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Volo.Abp.Http.Client.IdentityModel +namespace Volo.Abp.IdentityModel { public class IdentityClientConfigurationDictionary : Dictionary { diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientOptions.cs b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientOptions.cs similarity index 84% rename from framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientOptions.cs rename to framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientOptions.cs index e9b1175bcb..f05d5c8511 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityClientOptions.cs +++ b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityClientOptions.cs @@ -1,4 +1,4 @@ -namespace Volo.Abp.Http.Client.IdentityModel +namespace Volo.Abp.IdentityModel { public class IdentityClientOptions { diff --git a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelHttpClientAuthenticateContext.cs b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelHttpClientAuthenticateContext.cs new file mode 100644 index 0000000000..849ae7196d --- /dev/null +++ b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelHttpClientAuthenticateContext.cs @@ -0,0 +1,27 @@ +using System.Net.Http; + +namespace Volo.Abp.IdentityModel +{ + public class IdentityModelHttpClientAuthenticateContext + { + public HttpClient Client { get; } + + /// + /// The identity client name configured with the . + /// + public string IdentityClientName { get; } + + /// + /// + /// + /// object to be authorized + /// The identity client name configured with the . + public IdentityModelHttpClientAuthenticateContext( + HttpClient client, + string identityClientName = null) + { + Client = client; + IdentityClientName = identityClientName; + } + } +} diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs similarity index 69% rename from framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs rename to framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs index c3aaf4d93c..4a0daea58d 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelHttpClientAuthenticator.cs +++ b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs @@ -4,21 +4,14 @@ using System.Net.Http.Headers; using System.Threading.Tasks; using IdentityModel; using IdentityModel.Client; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; -using Volo.Abp.Http.Client.Authentication; -namespace Volo.Abp.Http.Client.IdentityModel +namespace Volo.Abp.IdentityModel { - //TODO: This class should be optimized and improved: - [Dependency(ReplaceServices = true)] - public class IdentityModelHttpClientAuthenticator : IHttpClientAuthenticator, ITransientDependency + public class IdentityModelHttpClientAuthenticator : IIdentityModelHttpClientAuthenticator, ITransientDependency { - public IHttpContextAccessor HttpContextAccessor { get; set; } - protected IdentityClientOptions ClientOptions { get; } public IdentityModelHttpClientAuthenticator( @@ -27,10 +20,9 @@ namespace Volo.Abp.Http.Client.IdentityModel ClientOptions = options.Value; } - public async Task Authenticate(HttpClientAuthenticateContext context) + public async Task Authenticate(IdentityModelHttpClientAuthenticateContext context) { - var accessToken = await GetAccessTokenFromHttpContextOrNullAsync() ?? - await GetAccessTokenFromServerOrNullAsync(context); + var accessToken = await GetAccessTokenFromServerOrNullAsync(context); if (accessToken != null) { @@ -40,18 +32,7 @@ namespace Volo.Abp.Http.Client.IdentityModel } } - protected virtual async Task GetAccessTokenFromHttpContextOrNullAsync() - { - var httpContext = HttpContextAccessor?.HttpContext; - if (httpContext == null) - { - return null; - } - - return await httpContext.GetTokenAsync("access_token"); - } - - protected virtual async Task GetAccessTokenFromServerOrNullAsync(HttpClientAuthenticateContext context) + protected virtual async Task GetAccessTokenFromServerOrNullAsync(IdentityModelHttpClientAuthenticateContext context) { var configuration = GetClientConfiguration(context); @@ -75,15 +56,14 @@ namespace Volo.Abp.Http.Client.IdentityModel return tokenResponse.AccessToken; } - private IdentityClientConfiguration GetClientConfiguration(HttpClientAuthenticateContext context) + private IdentityClientConfiguration GetClientConfiguration(IdentityModelHttpClientAuthenticateContext context) { - var identityClientName = context.RemoteService.GetIdentityClient(); - if (identityClientName.IsNullOrEmpty()) + if (context.IdentityClientName.IsNullOrEmpty()) { return ClientOptions.IdentityClients.Default; } - return ClientOptions.IdentityClients.GetOrDefault(identityClientName) ?? + return ClientOptions.IdentityClients.GetOrDefault(context.IdentityClientName) ?? ClientOptions.IdentityClients.Default; } diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index ba084c1175..e29ba634b9 100644 --- a/nupkg/common.ps1 +++ b/nupkg/common.ps1 @@ -64,6 +64,7 @@ $projects = ( "framework/src/Volo.Abp.Http.Abstractions", "framework/src/Volo.Abp.Http.Client", "framework/src/Volo.Abp.Http.Client.IdentityModel", + "framework/src/Volo.Abp.IdentityModel", "framework/src/Volo.Abp.Json", "framework/src/Volo.Abp.Localization", "framework/src/Volo.Abp.Localization.Abstractions", From 58becc59aeacff85c7e4a053c23632705edde07c Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Tue, 8 Jan 2019 09:53:43 +0300 Subject: [PATCH 24/36] Add missing GetCancellationToken calls in repositories --- .../EntityFrameworkCore/EfCoreRepository.cs | 27 ++++++++++++------- .../Repositories/MongoDB/MongoDbRepository.cs | 6 ++--- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index acf4d7ce80..23b4e36b75 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -86,7 +86,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore if (autoSave) { - await DbContext.SaveChangesAsync(cancellationToken); + await DbContext.SaveChangesAsync(GetCancellationToken(cancellationToken)); } return updatedEntity; @@ -108,7 +108,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore if (autoSave) { - await DbContext.SaveChangesAsync(cancellationToken); + await DbContext.SaveChangesAsync(GetCancellationToken(cancellationToken)); } } @@ -122,8 +122,8 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore public override async Task> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default) { return includeDetails - ? await WithDetails().ToListAsync(cancellationToken) - : await DbSet.ToListAsync(cancellationToken); + ? await WithDetails().ToListAsync(GetCancellationToken(cancellationToken)) + : await DbSet.ToListAsync(GetCancellationToken(cancellationToken)); } public override long GetCount() @@ -133,7 +133,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore public override async Task GetCountAsync(CancellationToken cancellationToken = default) { - return await DbSet.LongCountAsync(cancellationToken); + return await DbSet.LongCountAsync(GetCancellationToken(cancellationToken)); } protected override IQueryable GetQueryable() @@ -153,7 +153,10 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore public override async Task DeleteAsync(Expression> predicate, bool autoSave = false, CancellationToken cancellationToken = default) { - var entities = await GetQueryable().Where(predicate).ToListAsync(GetCancellationToken(cancellationToken)); + var entities = await GetQueryable() + .Where(predicate) + .ToListAsync(GetCancellationToken(cancellationToken)); + foreach (var entity in entities) { DbSet.Remove(entity); @@ -161,7 +164,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore if (autoSave) { - await DbContext.SaveChangesAsync(cancellationToken); + await DbContext.SaveChangesAsync(GetCancellationToken(cancellationToken)); } } @@ -171,7 +174,10 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore CancellationToken cancellationToken = default) where TProperty : class { - await DbContext.Entry(entity).Collection(propertyExpression).LoadAsync(GetCancellationToken(cancellationToken)); + await DbContext + .Entry(entity) + .Collection(propertyExpression) + .LoadAsync(GetCancellationToken(cancellationToken)); } public virtual async Task EnsurePropertyLoadedAsync( @@ -180,7 +186,10 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore CancellationToken cancellationToken = default) where TProperty : class { - await DbContext.Entry(entity).Reference(propertyExpression).LoadAsync(GetCancellationToken(cancellationToken)); + await DbContext + .Entry(entity) + .Reference(propertyExpression) + .LoadAsync(GetCancellationToken(cancellationToken)); } public override IQueryable WithDetails() diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index 11e79b32e2..194f604847 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -221,7 +221,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB public override async Task> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default) { - return await GetMongoQueryable().ToListAsync(cancellationToken); + return await GetMongoQueryable().ToListAsync(GetCancellationToken(cancellationToken)); } public override long GetCount() @@ -231,7 +231,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB public override async Task GetCountAsync(CancellationToken cancellationToken = default) { - return await GetMongoQueryable().LongCountAsync(cancellationToken); + return await GetMongoQueryable().LongCountAsync(GetCancellationToken(cancellationToken)); } public override void Delete(Expression> predicate, bool autoSave = false) @@ -257,7 +257,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB foreach (var entity in entities) { - await DeleteAsync(entity, autoSave, GetCancellationToken(cancellationToken)); + await DeleteAsync(entity, autoSave, cancellationToken); } } From 1a3f20b59be13c20a36a781437bb5e2e261e608a Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Jan 2019 10:30:58 +0300 Subject: [PATCH 25/36] identity server clients refactor --- .../Volo/Abp/IdentityServer/Clients/Client.cs | 105 +++++++++++++++--- .../Abp/IdentityServer/Clients/ClientClaim.cs | 17 ++- .../Clients/ClientCorsOrigin.cs | 7 +- .../IdentityServer/Clients/ClientGrantType.cs | 5 + .../Clients/ClientIdPRestriction.cs | 5 + .../Clients/ClientPostLogoutRedirectUri.cs | 5 + .../IdentityServer/Clients/ClientProperty.cs | 5 + .../Clients/ClientRedirectUri.cs | 5 + .../Abp/IdentityServer/Clients/ClientScope.cs | 6 + ...yServerDbContextModelCreatingExtensions.cs | 2 + 10 files changed, 140 insertions(+), 22 deletions(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs index 8c4846102b..f45926fb9a 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs @@ -144,18 +144,19 @@ namespace Volo.Abp.IdentityServer.Clients AllowedGrantTypes.Add(new ClientGrantType(Id, grantType)); } - public virtual void AddGrantTypes(IEnumerable grantTypes) + public virtual void RemoveAllAllowedGrantTypes() { - AllowedGrantTypes.AddRange( - grantTypes.Select( - grantType => new ClientGrantType(Id, grantType) - ) - ); + AllowedGrantTypes.Clear(); } - public virtual void RemoveAllAllowedGrantTypes() + public virtual void RemoveGrantType(string grantType) { - AllowedGrantTypes.Clear(); + AllowedGrantTypes.RemoveAll(r => r.GrantType == grantType); + } + + public virtual ClientGrantType FindGrantType(string grantType) + { + return AllowedGrantTypes.FirstOrDefault(r => r.GrantType == grantType); } public virtual void AddSecret([NotNull] string value, DateTime? expiration = null, string type = IdentityServerConstants.SecretTypes.SharedSecret, string description = null) @@ -183,6 +184,16 @@ namespace Volo.Abp.IdentityServer.Clients AllowedScopes.Clear(); } + public virtual void RemoveScope(string scope) + { + AllowedScopes.RemoveAll(r => r.Scope == scope); + } + + public virtual ClientScope FindScope(string scope) + { + return AllowedScopes.FirstOrDefault(r => r.Scope == scope); + } + public virtual void AddCorsOrigin([NotNull] string origin) { AllowedCorsOrigins.Add(new ClientCorsOrigin(Id, origin)); @@ -198,29 +209,49 @@ namespace Volo.Abp.IdentityServer.Clients PostLogoutRedirectUris.Add(new ClientPostLogoutRedirectUri(Id, postLogoutRedirectUri)); } - public virtual void RemoveAllCorsOrigin() + public virtual void RemoveAllCorsOrigins() { AllowedCorsOrigins.Clear(); } - public virtual void RemoveAllRedirectUri() + public virtual void RemoveCorsOrigin(string uri) + { + AllowedCorsOrigins.RemoveAll(c => c.Origin == uri); + } + + public virtual void RemoveAllRedirectUris() { RedirectUris.Clear(); } - public virtual void RemoveAllPostLogoutRedirectUri() + public virtual void RemoveRedirectUri(string uri) + { + RedirectUris.RemoveAll(r => r.RedirectUri == uri); + } + + public virtual void RemoveAllPostLogoutRedirectUris() { PostLogoutRedirectUris.Clear(); } - public virtual void AddIdentityProviderRestriction([NotNull] string provider) + public virtual void RemovePostLogoutRedirectUri(string uri) { - IdentityProviderRestrictions.Add(new ClientIdPRestriction(Id, provider)); + PostLogoutRedirectUris.RemoveAll(p => p.PostLogoutRedirectUri == uri); } - public virtual void RemoveAllIdentityProviderRestriction() + public virtual ClientCorsOrigin FindCorsOrigin(string uri) { - IdentityProviderRestrictions.Clear(); + return AllowedCorsOrigins.FirstOrDefault(c => c.Origin == uri); + } + + public virtual ClientRedirectUri FindRedirectUri(string uri) + { + return RedirectUris.FirstOrDefault(r => r.RedirectUri == uri); + } + + public virtual ClientPostLogoutRedirectUri FindPostLogoutRedirectUri(string uri) + { + return PostLogoutRedirectUris.FirstOrDefault(p => p.PostLogoutRedirectUri == uri); } public virtual void AddProperty([NotNull] string key, [NotNull] string value) @@ -233,14 +264,54 @@ namespace Volo.Abp.IdentityServer.Clients Properties.Clear(); } - public virtual void AddClaim(IGuidGenerator guidGenerator, [NotNull] string type, string value) + public virtual void RemoveProperty(string key, string value) { - Claims.Add(new ClientClaim(guidGenerator.Create(), Id, type, value)); + Properties.RemoveAll(c => c.Value == value && c.Key == key); + } + + public virtual ClientProperty FindProperty(string key, string value) + { + return Properties.FirstOrDefault(c => c.Key == key && c.Value == value); + } + + public virtual void AddClaim([NotNull] string value, string type) + { + Claims.Add(new ClientClaim(Id, type, value)); } public virtual void RemoveAllClaims() { Claims.Clear(); } + + public virtual void RemoveClaim(string value, string type) + { + Claims.RemoveAll(c => c.Value == value && c.Type == type); + } + + public virtual ClientClaim FindClaim(string value, string type) + { + return Claims.FirstOrDefault(c => c.Type == type && c.Value == value); + } + + public virtual void AddIdentityProviderRestriction([NotNull] string provider) + { + IdentityProviderRestrictions.Add(new ClientIdPRestriction(Id, provider)); + } + + public virtual void RemoveAllIdentityProviderRestrictions() + { + IdentityProviderRestrictions.Clear(); + } + + public virtual void RemoveIdentityProviderRestriction(string provider) + { + IdentityProviderRestrictions.RemoveAll(r => r.Provider == provider); + } + + public virtual ClientIdPRestriction FindIdentityProviderRestriction(string provider) + { + return IdentityProviderRestrictions.FirstOrDefault(r => r.Provider == provider); + } } } \ No newline at end of file diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs index 29b44a40f7..f0b35d772a 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs @@ -4,7 +4,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientClaim : Entity + public class ClientClaim : Entity { public virtual Guid ClientId { get; set; } @@ -14,17 +14,26 @@ namespace Volo.Abp.IdentityServer.Clients protected ClientClaim() { - + + } + + public virtual bool Equals(Guid clientId, string value, string type) + { + return ClientId == clientId && Type == type && Value == value; } - protected internal ClientClaim(Guid id, Guid clientId, [NotNull] string type, string value) + protected internal ClientClaim(Guid clientId, [NotNull] string type, string value) { Check.NotNull(type, nameof(type)); - Id = id; ClientId = clientId; Type = type; Value = value; } + + public override object[] GetKeys() + { + return new object[] { ClientId, Type, Value }; + } } } \ No newline at end of file diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs index c8177baee8..73f4b47637 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs @@ -12,7 +12,12 @@ namespace Volo.Abp.IdentityServer.Clients protected ClientCorsOrigin() { - + + } + + public virtual bool Equals(Guid clientId, [NotNull] string uri) + { + return ClientId == clientId && Origin == uri; } protected internal ClientCorsOrigin(Guid clientId, [NotNull] string origin) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs index ccbf0b666e..696ae1cd46 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs @@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients } + public virtual bool Equals(Guid clientId, [NotNull] string grantType) + { + return ClientId == clientId && GrantType == grantType; + } + protected internal ClientGrantType(Guid clientId, [NotNull] string grantType) { Check.NotNull(grantType, nameof(grantType)); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs index 00f1aa1020..aff16986c2 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs @@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients } + public virtual bool Equals(Guid clientId, [NotNull] string provider) + { + return ClientId == clientId && Provider == provider; + } + protected internal ClientIdPRestriction(Guid clientId, [NotNull] string provider) { Check.NotNull(provider, nameof(provider)); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs index 9042d54522..0e0ca17ae8 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs @@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients } + public virtual bool Equals(Guid clientId, [NotNull] string uri) + { + return ClientId == clientId && PostLogoutRedirectUri == uri; + } + protected internal ClientPostLogoutRedirectUri(Guid clientId, [NotNull] string postLogoutRedirectUri) { Check.NotNull(postLogoutRedirectUri, nameof(postLogoutRedirectUri)); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs index 31d131e762..daddd94e83 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs @@ -17,6 +17,11 @@ namespace Volo.Abp.IdentityServer.Clients } + public virtual bool Equals(Guid clientId, [NotNull] string key, string value) + { + return ClientId == clientId && Key == key && Value == value; + } + protected internal ClientProperty(Guid clientId, [NotNull] string key, [NotNull] string value) { Check.NotNull(key, nameof(key)); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs index ff8a3edc05..89d461b58b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs @@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients } + public virtual bool Equals(Guid clientId, [NotNull] string uri) + { + return ClientId == clientId && RedirectUri == uri; + } + protected internal ClientRedirectUri(Guid clientId, [NotNull] string redirectUri) { Check.NotNull(redirectUri, nameof(redirectUri)); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs index eb72ddf7cb..f94de116bb 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs @@ -1,4 +1,5 @@ using System; +using JetBrains.Annotations; using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients @@ -14,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients } + public virtual bool Equals(Guid clientId, [NotNull] string scope) + { + return ClientId == clientId && Scope == scope; + } + protected internal ClientScope(Guid clientId, string scope) { ClientId = clientId; diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs index efda009d68..3c38f2e2c7 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs @@ -103,6 +103,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore { claim.ToTable(tablePrefix + "ClientClaims", schema); + claim.HasKey(x => new { x.ClientId, x.Type, x.Value }); + claim.Property(x => x.Type).HasMaxLength(ClientClaimConsts.TypeMaxLength).IsRequired(); claim.Property(x => x.Value).HasMaxLength(ClientClaimConsts.ValueMaxLength).IsRequired(); }); From c132d469683cd9f8a3735a4d4dfa2541d57d68bb Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Jan 2019 10:42:24 +0300 Subject: [PATCH 26/36] identity server identityresource refactor --- .../IdentityServer/IdentityResources/IdentityClaim.cs | 7 ++++++- .../IdentityResources/IdentityResource.cs | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityClaim.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityClaim.cs index 39453421ef..8b4a22b584 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityClaim.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityClaim.cs @@ -9,7 +9,12 @@ namespace Volo.Abp.IdentityServer.IdentityResources protected IdentityClaim() { - + + } + + public virtual bool Equals(Guid identityResourceId, [NotNull] string type) + { + return IdentityResourceId == identityResourceId && Type == type; } protected internal IdentityClaim(Guid identityResourceId, [NotNull] string type) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs index 37b259fe61..9ecaa42741 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using JetBrains.Annotations; using Volo.Abp.Domain.Entities; @@ -61,5 +62,15 @@ namespace Volo.Abp.IdentityServer.IdentityResources { UserClaims.Clear(); } + + public virtual void RemoveUserClaim(string type) + { + UserClaims.RemoveAll(c => c.Type == type); + } + + public virtual IdentityClaim FindUserClaim(string type) + { + return UserClaims.FirstOrDefault(c => c.Type == type); + } } } From 1e643381c32fff35ab096f7bf767637e3a1f6571 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Jan 2019 11:45:39 +0300 Subject: [PATCH 27/36] identity server apiresource refactor --- .../ApiResources/ApiResource.cs | 40 +++++++++++++++++-- .../ApiResources/ApiResourceClaim.cs | 7 +++- .../IdentityServer/ApiResources/ApiScope.cs | 18 ++++++++- .../ApiResources/ApiScopeClaim.cs | 5 +++ .../IdentityServer/ApiResources/ApiSecret.cs | 7 +++- 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs index fef31bdec5..c6c74ac24f 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using IdentityServer4; using JetBrains.Annotations; using Volo.Abp.Domain.Entities; @@ -57,16 +58,27 @@ namespace Volo.Abp.IdentityServer.ApiResources Secrets.Add(new ApiSecret(Id, value, expiration, type, description)); } - public virtual void AddScope( + public virtual void RemoveSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + Secrets.RemoveAll(s => s.Value == value && s.Type == type); + } + + public virtual ApiSecret FindSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + return Secrets.FirstOrDefault(s => s.Type == type && s.Value == value); + } + + public virtual ApiScope AddScope( [NotNull] string name, string displayName = null, string description = null, bool required = false, bool emphasize = false, - bool showInDiscoveryDocument = true, - ApiScopeClaim[] userClaims = null) + bool showInDiscoveryDocument = true) { - Scopes.Add(new ApiScope(Id, name, displayName, description, required, emphasize, showInDiscoveryDocument)); + var scope = new ApiScope(Id, name, displayName, description, required, emphasize, showInDiscoveryDocument); + Scopes.Add(scope); + return scope; } public virtual void AddUserClaim([NotNull] string type) @@ -79,6 +91,16 @@ namespace Volo.Abp.IdentityServer.ApiResources UserClaims.Clear(); } + public virtual void RemoveClaim(string type) + { + UserClaims.RemoveAll(c => c.Type == type); + } + + public virtual ApiResourceClaim FindClaim(string type) + { + return UserClaims.FirstOrDefault(c => c.Type == type); + } + public virtual void RemoveAllSecrets() { Secrets.Clear(); @@ -92,5 +114,15 @@ namespace Volo.Abp.IdentityServer.ApiResources } Scopes.Clear(); } + + public virtual void RemoveScope(string name) + { + Scopes.RemoveAll(r => r.Name == name); + } + + public virtual ApiScope FindScope(string name) + { + return Scopes.FirstOrDefault(r => r.Name == name); + } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs index 89fec1c017..e71d694656 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs @@ -9,7 +9,12 @@ namespace Volo.Abp.IdentityServer.ApiResources protected ApiResourceClaim() { - + + } + + public virtual bool Equals(Guid apiResourceId, [NotNull] string type) + { + return ApiResourceId == apiResourceId && Type == type; } protected internal ApiResourceClaim(Guid apiResourceId, [NotNull] string type) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs index f96debb31a..e81dd849ec 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using JetBrains.Annotations; using Volo.Abp.Domain.Entities; @@ -26,7 +27,12 @@ namespace Volo.Abp.IdentityServer.ApiResources protected ApiScope() { - + + } + + public virtual bool Equals(Guid apiResourceId, [NotNull] string name) + { + return ApiResourceId == apiResourceId && Name == name; } protected internal ApiScope( @@ -61,6 +67,16 @@ namespace Volo.Abp.IdentityServer.ApiResources UserClaims.Clear(); } + public virtual void RemoveClaim(string name, string type) + { + UserClaims.RemoveAll(r => r.Name == name && r.Type == type); + } + + public virtual ApiScopeClaim FindClaim(string name, string type) + { + return UserClaims.FirstOrDefault(r => r.Name == name && r.Type == type); + } + public override object[] GetKeys() { return new object[] { ApiResourceId, Name }; diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeClaim.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeClaim.cs index 5c7dbdbe23..729ff9c344 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeClaim.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeClaim.cs @@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.ApiResources } + public virtual bool Equals(Guid apiResourceId, [NotNull] string name, [NotNull] string type) + { + return ApiResourceId == apiResourceId && Name == name && Type == type; + } + protected internal ApiScopeClaim(Guid apiResourceId, [NotNull] string name, [NotNull] string type) : base(type) { diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs index 41c4bc53c2..e692183a71 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs @@ -10,7 +10,12 @@ namespace Volo.Abp.IdentityServer.ApiResources protected ApiSecret() { - + + } + + public virtual bool Equals(Guid apiResourceId, [NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + return ApiResourceId == apiResourceId && Value == value && Type == type; } protected internal ApiSecret( From c5af4a0441b1dc2132d503b1f327ba7c08fa7eb9 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Jan 2019 12:08:12 +0300 Subject: [PATCH 28/36] Update AbpTagHelperLocalizer.cs Resolved https://github.com/abpframework/abp/issues/720 --- .../TagHelpers/AbpTagHelperLocalizer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperLocalizer.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperLocalizer.cs index 35ad5a894d..72d32ce10b 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperLocalizer.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperLocalizer.cs @@ -20,14 +20,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers public string GetLocalizedText(string text, ModelExplorer explorer) { - var localizer = GetLocalizer(explorer); + var localizer = GetStringLocalizer(explorer); return localizer == null ? text : localizer[text].Value; } public IStringLocalizer GetLocalizer(ModelExplorer explorer) { - return GetLocalizer(explorer); + return GetStringLocalizer(explorer); } private IStringLocalizer GetStringLocalizer(ModelExplorer explorer) From 3eda49b792e585940c76d54a467575b58807fac7 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Jan 2019 13:18:43 +0300 Subject: [PATCH 29/36] Update ClientRepository.cs --- .../Clients/ClientRepository.cs | 69 ------------------- 1 file changed, 69 deletions(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs index aee58475fe..62043562e8 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs @@ -42,75 +42,6 @@ namespace Volo.Abp.IdentityServer.Clients return await DbSet.CountAsync(); } - //public override async Task UpdateAsync(Client entity, bool autoSave = false, CancellationToken cancellationToken = default) - //{ - - // var secrets = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var secret in secrets) - // { - // DbContext.Set().Remove(secret); - // } - - // var claims = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var claim in claims) - // { - // DbContext.Set().Remove(claim); - // } - - // var grantTypes = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var grantType in grantTypes) - // { - // DbContext.Set().Remove(grantType); - // } - - // var restrictions = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var restriction in restrictions) - // { - // DbContext.Set().Remove(restriction); - // } - - // var properties = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var clientProperty in properties) - // { - // DbContext.Set().Remove(clientProperty); - // } - - // var scopes = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var scope in scopes) - // { - // DbContext.Set().Remove(scope); - // } - - // var corsOrigins = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var corsOrigin in corsOrigins) - // { - // DbContext.Set().Remove(corsOrigin); - // } - - // var redirectUris = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var redirectUri in redirectUris) - // { - // DbContext.Set().Remove(redirectUri); - // } - - // var postLogoutRedirectUris = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var postLogoutRedirectUri in postLogoutRedirectUris) - // { - // DbContext.Set().Remove(postLogoutRedirectUri); - // } - - // return await base.UpdateAsync(entity, autoSave, cancellationToken); - //} - public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); From e5915ed499ba34e744ed78262715f8b37528f45f Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Tue, 8 Jan 2019 13:20:16 +0300 Subject: [PATCH 30/36] Created IdentityResourceDataSeeder --- .../IIdentityResourceDataSeeder.cs | 9 ++++ .../IIdentityResourceRepository.cs | 7 +-- .../IdentityResources/IdentityResource.cs | 14 +++++ .../IdentityResourceDataSeeder.cs | 52 +++++++++++++++++++ .../IdentityResourceRepository.cs | 25 +++++---- .../MongoIdentityResourceRepository.cs | 12 ++++- 6 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceDataSeeder.cs create mode 100644 modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceDataSeeder.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceDataSeeder.cs new file mode 100644 index 0000000000..cd50765ec5 --- /dev/null +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceDataSeeder.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.IdentityServer.IdentityResources +{ + public interface IIdentityResourceDataSeeder + { + Task CreateStandardResourcesAsync(); + } +} \ No newline at end of file diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs index 09eb9a762b..af53d12d38 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs @@ -22,11 +22,12 @@ namespace Volo.Abp.IdentityServer.IdentityResources CancellationToken cancellationToken = default ); - Task> GetListAsync( - bool includeDetails = false, + Task FindByNameAsync( + string name, + bool includeDetails = true, CancellationToken cancellationToken = default ); - Task GetTotalCount(); + Task GetTotalCountAsync(); } } \ No newline at end of file diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs index 37b259fe61..b01296dad3 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using JetBrains.Annotations; using Volo.Abp.Domain.Entities; @@ -52,6 +53,19 @@ namespace Volo.Abp.IdentityServer.IdentityResources UserClaims = new List(); } + public IdentityResource(Guid id, IdentityServer4.Models.IdentityResource resource) + { + Id = id; + Name = resource.Name; + DisplayName = resource.DisplayName; + Description = resource.Description; + Enabled = resource.Enabled; + Required = resource.Required; + Emphasize = resource.Emphasize; + ShowInDiscoveryDocument = resource.ShowInDiscoveryDocument; + UserClaims = resource.UserClaims.Select(claimType => new IdentityClaim(id, claimType)).ToList(); + } + public virtual void AddUserClaim([NotNull] string type) { UserClaims.Add(new IdentityClaim(Id, type)); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs new file mode 100644 index 0000000000..af62b8ed15 --- /dev/null +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs @@ -0,0 +1,52 @@ +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Guids; + +namespace Volo.Abp.IdentityServer.IdentityResources +{ + public class IdentityResourceDataSeeder : IIdentityResourceDataSeeder, ITransientDependency + { + protected IIdentityResourceRepository IdentityResourceRepository { get; } + protected IGuidGenerator GuidGenerator { get; } + + public IdentityResourceDataSeeder( + IIdentityResourceRepository identityResourceRepository, + IGuidGenerator guidGenerator) + { + IdentityResourceRepository = identityResourceRepository; + GuidGenerator = guidGenerator; + } + + public virtual async Task CreateStandardResourcesAsync() + { + var resources = new IdentityServer4.Models.IdentityResource[] + { + new IdentityServer4.Models.IdentityResources.OpenId(), + new IdentityServer4.Models.IdentityResources.Profile(), + new IdentityServer4.Models.IdentityResources.Email(), + new IdentityServer4.Models.IdentityResources.Address(), + new IdentityServer4.Models.IdentityResources.Phone() + }; + + foreach (var resource in resources) + { + await AddIfNotExistsAsync(resource); + } + } + + protected virtual async Task AddIfNotExistsAsync(IdentityServer4.Models.IdentityResource resource) + { + if (await IdentityResourceRepository.FindByNameAsync(resource.Name) != null) + { + return; + } + + await IdentityResourceRepository.InsertAsync( + new IdentityResource( + GuidGenerator.Create(), + resource + ) + ); + } + } +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs index deef97424f..a6ff62fc05 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs @@ -31,15 +31,6 @@ namespace Volo.Abp.IdentityServer.IdentityResources return await query.ToListAsync(GetCancellationToken(cancellationToken)); } - public virtual async Task> GetListAsync( - bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await DbSet - .IncludeDetails(includeDetails) - .ToListAsync(GetCancellationToken(cancellationToken)); - } - public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); @@ -49,12 +40,24 @@ namespace Volo.Abp.IdentityServer.IdentityResources bool includeDetails = false, CancellationToken cancellationToken = default) { return await DbSet - .IncludeDetails(includeDetails).OrderBy(sorting ?? "name desc") + .IncludeDetails(includeDetails) + .OrderBy(sorting ?? "name desc") .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } - public virtual async Task GetTotalCount() + public async Task FindByNameAsync( + string name, + bool includeDetails = true, + CancellationToken cancellationToken = default) + { + return await DbSet + .IncludeDetails(includeDetails) + .Where(x => x.Name == name) + .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); + } + + public virtual async Task GetTotalCountAsync() { return await DbSet.CountAsync(); } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs index c5d4d7750f..85505c2987 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs @@ -28,6 +28,16 @@ namespace Volo.Abp.IdentityServer.MongoDB .ToListAsync(GetCancellationToken(cancellationToken)); } + public async Task FindByNameAsync( + string name, + bool includeDetails = true, + CancellationToken cancellationToken = default) + { + return await GetMongoQueryable() + .Where(x => x.Name == name) + .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); + } + public async Task> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false, CancellationToken cancellationToken = default) { @@ -36,7 +46,7 @@ namespace Volo.Abp.IdentityServer.MongoDB .ToListAsync(GetCancellationToken(cancellationToken)); } - public virtual async Task GetTotalCount() + public virtual async Task GetTotalCountAsync() { return await GetCountAsync(); } From d12f7bdf3644d673ef20cadb4eea69c90d7a223e Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Jan 2019 13:20:19 +0300 Subject: [PATCH 31/36] Update ApiResourceRepository.cs --- .../ApiResources/ApiResourceRepository.cs | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs index 1234141229..bad674f435 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs @@ -66,32 +66,6 @@ namespace Volo.Abp.IdentityServer.ApiResources return await DbSet.CountAsync(); } - public override async Task UpdateAsync(ApiResource entity, bool autoSave = false, CancellationToken cancellationToken = default) - { - var scopeClaims = DbContext.Set().Where(sc => sc.ApiResourceId == entity.Id); - - foreach (var scopeClaim in scopeClaims) - { - DbContext.Set().Remove(scopeClaim); - } - - var scopes = DbContext.Set().Where(s => s.ApiResourceId == entity.Id); - - foreach (var scope in scopes) - { - DbContext.Set().Remove(scope); - } - - var secrets = DbContext.Set().Where(s => s.ApiResourceId == entity.Id); - - foreach (var secret in secrets) - { - DbContext.Set().Remove(secret); - } - - return await base.UpdateAsync(entity, autoSave, cancellationToken); - } - public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default) { var scopeClaims = DbContext.Set().Where(sc => sc.ApiResourceId == id); From c19834ec2e48bef8d8bd5ae3edcab3b4307f5661 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Jan 2019 16:54:07 +0300 Subject: [PATCH 32/36] Added margin to bottom of input tag helper for checkboxes --- .../TagHelpers/Form/AbpInputTagHelperService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs index d4cc92deb5..48cf748f24 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs @@ -50,6 +50,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form output.TagName = "div"; LeaveOnlyGroupAttributes(context, output); output.Attributes.AddClass(isCheckbox ? "form-check" : "form-group"); + output.Attributes.AddClass(isCheckbox ? "mb-2" : ""); output.Content.SetHtmlContent(output.Content.GetContent() + innerHtml); } } From 10d8ff47e68a7a040f1bd685fd49bbcaff26a846 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 9 Jan 2019 09:43:31 +0300 Subject: [PATCH 33/36] IdentityServer: Added AbpIdentityServerTestData.cs --- .../IdentityServer/AbpIdentityServerTestData.cs | 14 ++++++++++++++ .../AbpIdentityServerTestDataBuilder.cs | 11 +++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestData.cs diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestData.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestData.cs new file mode 100644 index 0000000000..0392cc889d --- /dev/null +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestData.cs @@ -0,0 +1,14 @@ +using System; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.IdentityServer +{ + public class AbpIdentityServerTestData : ISingletonDependency + { + public Guid Client1Id { get; } = Guid.NewGuid(); + + public Guid ApiResource1Id { get; } = Guid.NewGuid(); + + public Guid IdentityResource1Id { get; } = Guid.NewGuid(); + } +} diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs index 472c23b7e2..f40bdfe965 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs @@ -14,14 +14,17 @@ namespace Volo.Abp.IdentityServer private readonly IClientRepository _clientRepository; private readonly IIdentityResourceRepository _identityResourceRepository; //private readonly IPersistentGrantRepository _persistentGrantRepository; + private readonly AbpIdentityServerTestData _testData; public AbpIdentityServerTestDataBuilder( IGuidGenerator guidGenerator, IApiResourceRepository apiResourceRepository, IClientRepository clientRepository, - IIdentityResourceRepository identityResourceRepository + IIdentityResourceRepository identityResourceRepository, + AbpIdentityServerTestData testData /*IPersistentGrantRepository persistentGrantRepository*/) { + _testData = testData; _guidGenerator = guidGenerator; _apiResourceRepository = apiResourceRepository; _clientRepository = clientRepository; @@ -46,21 +49,21 @@ namespace Volo.Abp.IdentityServer private void AddIdentityResources() { - _identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource1")); + _identityResourceRepository.Insert(new IdentityResource(_testData.IdentityResource1Id, "NewIdentityResource1")); _identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource2")); _identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource3")); } private void AddApiResources() { - _apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource1")); + _apiResourceRepository.Insert(new ApiResource(_testData.ApiResource1Id, "NewApiResource1")); _apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource2")); _apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource3")); } private void AddClients() { - _clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId1")); + _clientRepository.Insert(new Client(_testData.Client1Id, "ClientId1")); _clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId2")); _clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId3")); } From 3e2e06b2c7e3e4b2619133876aa1952540fe86f5 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 9 Jan 2019 14:03:45 +0300 Subject: [PATCH 34/36] Identity server test builder: detailed sample client --- .../AbpIdentityServerTestDataBuilder.cs | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs index f40bdfe965..f3db9821b8 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs @@ -1,4 +1,5 @@ -using Volo.Abp.DependencyInjection; +using System.Collections.Generic; +using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.Clients; @@ -63,7 +64,28 @@ namespace Volo.Abp.IdentityServer private void AddClients() { - _clientRepository.Insert(new Client(_testData.Client1Id, "ClientId1")); + var client = new Client(_testData.Client1Id, "ClientId1") + { + Description = nameof(Client.Description), + ClientName = nameof(Client.ClientName), + ClientUri = nameof(Client.ClientUri), + LogoUri = nameof(Client.LogoUri), + ProtocolType = nameof(Client.ProtocolType), + FrontChannelLogoutUri = nameof(Client.FrontChannelLogoutUri) + }; + + client.AddCorsOrigin(nameof(ClientCorsOrigin.Origin)); + client.AddClaim(nameof(ClientClaim.Value), nameof(ClientClaim.Type)); + client.AddGrantType(nameof(ClientGrantType.GrantType)); + client.AddIdentityProviderRestriction(nameof(ClientIdPRestriction.Provider)); + client.AddPostLogoutRedirectUri(nameof(ClientPostLogoutRedirectUri.PostLogoutRedirectUri)); + client.AddProperty(nameof(ClientProperty.Key), nameof(ClientProperty.Value)); + client.AddRedirectUri(nameof(ClientRedirectUri.RedirectUri)); + client.AddScope(nameof(ClientScope.Scope)); + client.AddSecret(nameof(ClientSecret.Value)); + + _clientRepository.Insert(client); + _clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId2")); _clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId3")); } From 9ef35331418a8599d917886ab1fdd341c811317e Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Wed, 9 Jan 2019 14:27:30 +0300 Subject: [PATCH 35/36] Revise IdentityClaimType ctor and properties --- .../Abp/Identity/IdentityClaimValueType.cs | 6 +---- .../Volo/Abp/Identity/IdentityClaimType.cs | 26 ++++++++++++------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityClaimValueType.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityClaimValueType.cs index 69d40a4607..7ea73ef3f0 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityClaimValueType.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentityClaimValueType.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Volo.Abp.Identity +namespace Volo.Abp.Identity { public enum IdentityClaimValueType { diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaimType.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaimType.cs index d8722669fb..b857c940f8 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaimType.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaimType.cs @@ -1,5 +1,5 @@ -using System; -using JetBrains.Annotations; +using JetBrains.Annotations; +using System; using Volo.Abp.Domain.Entities; namespace Volo.Abp.Identity @@ -8,15 +8,15 @@ namespace Volo.Abp.Identity { public virtual string Name { get; protected set; } - public virtual bool Required { get; protected set; } + public virtual bool Required { get; set; } public virtual bool IsStatic { get; protected set; } - public virtual string Regex { get; protected set; } + public virtual string Regex { get; set; } - public virtual string RegexDescription { get; protected set; } + public virtual string RegexDescription { get; set; } - public virtual string Description { get; protected set; } + public virtual string Description { get; set; } public virtual IdentityClaimValueType ValueType { get; protected set; } @@ -25,12 +25,18 @@ namespace Volo.Abp.Identity } - public IdentityClaimType(Guid id, [NotNull] string name, bool required, bool isStatic, [CanBeNull]string regex, [CanBeNull]string regexDescription, [CanBeNull] string description, IdentityClaimValueType valueType = IdentityClaimValueType.String) + public IdentityClaimType( + Guid id, + [NotNull] string name, + bool required = false, + bool isStatic = false, + [CanBeNull] string regex = null, + [CanBeNull] string regexDescription = null, + [CanBeNull] string description = null, + IdentityClaimValueType valueType = IdentityClaimValueType.String) { - Check.NotNull(name, nameof(name)); - Id = id; - Name = name; + Name = Check.NotNull(name, nameof(name)); Required = required; IsStatic = isStatic; Regex = regex; From d0dcccc95b7a5f60779265ba179f649a6010ad9e Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Wed, 9 Jan 2019 14:55:50 +0300 Subject: [PATCH 36/36] Refactored identity module --- .../Identity/IIDentityClaimTypeRepository.cs | 13 ++++--- .../Abp/Identity/IdenityClaimTypeManager.cs | 14 +++----- .../EfCoreIdentityClaimTypeRepository.cs | 15 ++++---- .../MongoIdentityClaimTypeRepository.cs | 35 +++++++++++-------- .../IdentityClaimTypeRepository_Tests.cs | 4 +-- .../IdentityResourceDataSeeder.cs | 33 ++++++++++++++--- 6 files changed, 72 insertions(+), 42 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIDentityClaimTypeRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIDentityClaimTypeRepository.cs index e55bdd966b..c2d5b4fd5c 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIDentityClaimTypeRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIDentityClaimTypeRepository.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; @@ -8,10 +7,16 @@ namespace Volo.Abp.Identity { public interface IIdentityClaimTypeRepository : IBasicRepository { - Task DoesNameExist(string name, Guid? claimTypeId = null); + /// + /// Checks if there is a entity with given name. + /// + /// Name to check + /// + /// An Id value to ignore on checking. + /// If there is an entity with given it's ignored. + /// + Task AnyAsync(string name, Guid? ignoredId = null); Task> GetListAsync(string sorting, int maxResultCount, int skipCount); - - Task GetTotalCount(); } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdenityClaimTypeManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdenityClaimTypeManager.cs index eac38b9f24..69e5428e66 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdenityClaimTypeManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdenityClaimTypeManager.cs @@ -1,26 +1,20 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; using Volo.Abp.Domain.Services; -using Volo.Abp.Guids; namespace Volo.Abp.Identity { public class IdenityClaimTypeManager : DomainService { private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository; - private readonly IGuidGenerator _guidGenerator; - public IdenityClaimTypeManager(IIdentityClaimTypeRepository identityClaimTypeRepository, IGuidGenerator guidGenerator) + public IdenityClaimTypeManager(IIdentityClaimTypeRepository identityClaimTypeRepository) { _identityClaimTypeRepository = identityClaimTypeRepository; - _guidGenerator = guidGenerator; } public virtual async Task CreateAsync(IdentityClaimType claimType) { - if (await _identityClaimTypeRepository.DoesNameExist(claimType.Name)) + if (await _identityClaimTypeRepository.AnyAsync(claimType.Name)) { throw new AbpException($"Name Exist: {claimType.Name}"); } @@ -30,7 +24,7 @@ namespace Volo.Abp.Identity public virtual async Task UpdateAsync(IdentityClaimType claimType) { - if (await _identityClaimTypeRepository.DoesNameExist(claimType.Name, claimType.Id)) + if (await _identityClaimTypeRepository.AnyAsync(claimType.Name, claimType.Id)) { throw new AbpException($"Name Exist: {claimType.Name}"); } diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs index f50ed08d35..50a4578cae 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs @@ -11,13 +11,17 @@ namespace Volo.Abp.Identity.EntityFrameworkCore { public class EfCoreIdentityClaimTypeRepository : EfCoreRepository, IIdentityClaimTypeRepository { - public EfCoreIdentityClaimTypeRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) + public EfCoreIdentityClaimTypeRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) { + } - public async Task DoesNameExist(string name, Guid? claimTypeId = null) + public async Task AnyAsync(string name, Guid? ignoredId = null) { - return await DbSet.WhereIf(claimTypeId != null, ct => ct.Id != claimTypeId).CountAsync(ct => ct.Name == name) > 0; + return await DbSet + .WhereIf(ignoredId != null, ct => ct.Id != ignoredId) + .CountAsync(ct => ct.Name == name) > 0; } public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount) @@ -28,10 +32,5 @@ namespace Volo.Abp.Identity.EntityFrameworkCore return identityClaimTypes; } - - public async Task GetTotalCount() - { - return await DbSet.CountAsync(); - } } } diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs index 654848bb1b..c2bbd56a6d 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs @@ -1,9 +1,10 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Linq.Dynamic.Core; using System.Threading.Tasks; +using MongoDB.Driver; using MongoDB.Driver.Linq; +using System.Linq; +using System.Linq.Dynamic.Core; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; @@ -15,23 +16,29 @@ namespace Volo.Abp.Identity.MongoDB { } - public async Task DoesNameExist(string name, Guid? claimTypeId = null) + public async Task AnyAsync(string name, Guid? ignoredId = null) { - return GetMongoQueryable().WhereIf(claimTypeId != null, ct => ct.Id != claimTypeId).Count(ct => ct.Name == name) > 0; + if (ignoredId == null) + { + return await GetMongoQueryable() + .Where(ct => ct.Name == name) + .AnyAsync(); + } + else + { + return await GetMongoQueryable() + .Where(ct => ct.Id != ignoredId && ct.Name == name) + .AnyAsync(); + } } public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount) { - var identityClaimTypes = GetMongoQueryable().OrderBy(sorting ?? "name desc") - .PageBy(skipCount, maxResultCount) - .ToList(); - - return identityClaimTypes; - } - - public async Task GetTotalCount() - { - return await GetMongoQueryable().CountAsync(); + return await GetMongoQueryable() + .OrderBy(sorting ?? nameof(IdentityClaimType.Name)) + .As>() + .PageBy>(skipCount, maxResultCount) + .ToListAsync(); } } } diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityClaimTypeRepository_Tests.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityClaimTypeRepository_Tests.cs index 56de1d5d5f..3250c0b04a 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityClaimTypeRepository_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityClaimTypeRepository_Tests.cs @@ -28,11 +28,11 @@ namespace Volo.Abp.Identity { var claim = (await ClaimTypeRepository.GetListAsync()).FirstOrDefault(); - var result1 = await ClaimTypeRepository.DoesNameExist(claim.Name); + var result1 = await ClaimTypeRepository.AnyAsync(claim.Name); result1.ShouldBe(true); - var result2 = await ClaimTypeRepository.DoesNameExist(Guid.NewGuid().ToString()); + var result2 = await ClaimTypeRepository.AnyAsync(Guid.NewGuid().ToString()); result2.ShouldBe(false); } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs index af62b8ed15..a5c1e23861 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs @@ -1,20 +1,24 @@ using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; +using Volo.Abp.Identity; namespace Volo.Abp.IdentityServer.IdentityResources { public class IdentityResourceDataSeeder : IIdentityResourceDataSeeder, ITransientDependency { + protected IIdentityClaimTypeRepository ClaimTypeRepository { get; } protected IIdentityResourceRepository IdentityResourceRepository { get; } protected IGuidGenerator GuidGenerator { get; } public IdentityResourceDataSeeder( IIdentityResourceRepository identityResourceRepository, - IGuidGenerator guidGenerator) + IGuidGenerator guidGenerator, + IIdentityClaimTypeRepository claimTypeRepository) { IdentityResourceRepository = identityResourceRepository; GuidGenerator = guidGenerator; + ClaimTypeRepository = claimTypeRepository; } public virtual async Task CreateStandardResourcesAsync() @@ -30,11 +34,16 @@ namespace Volo.Abp.IdentityServer.IdentityResources foreach (var resource in resources) { - await AddIfNotExistsAsync(resource); + foreach (var claimType in resource.UserClaims) + { + await AddClaimTypeIfNotExistsAsync(claimType); + } + + await AddIdentityResourceIfNotExistsAsync(resource); } } - - protected virtual async Task AddIfNotExistsAsync(IdentityServer4.Models.IdentityResource resource) + + protected virtual async Task AddIdentityResourceIfNotExistsAsync(IdentityServer4.Models.IdentityResource resource) { if (await IdentityResourceRepository.FindByNameAsync(resource.Name) != null) { @@ -48,5 +57,21 @@ namespace Volo.Abp.IdentityServer.IdentityResources ) ); } + + protected virtual async Task AddClaimTypeIfNotExistsAsync(string claimType) + { + if (await ClaimTypeRepository.AnyAsync(claimType)) + { + return; + } + + await ClaimTypeRepository.InsertAsync( + new IdentityClaimType( + GuidGenerator.Create(), + claimType, + isStatic: true + ) + ); + } } }