From 9d65f8bbe5cfc54a1ed07296cc31fc3084298a33 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Sun, 15 Oct 2023 21:18:54 +0330 Subject: [PATCH 01/13] Support for SimpleQueryServiceController with TFilterRequestContract --- .../SimpleQueryServiceController.cs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/SimpleQueryServiceController.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/SimpleQueryServiceController.cs index 4cecc3e..8a6ea5d 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/SimpleQueryServiceController.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/SimpleQueryServiceController.cs @@ -13,14 +13,16 @@ namespace EasyMicroservices.Cores.AspCoreApi /// /// /// + /// /// /// /// [ApiController] [Route("api/[controller]/[action]")] - public class SimpleQueryServiceController : ReadableQueryServiceController + public class SimpleQueryServiceController : ReadableQueryServiceController where TResponseContract : class where TEntity : class + where TFilterRequestContract : FilterRequestContract { /// /// @@ -146,4 +148,36 @@ public virtual Task SoftDeleteBulkByIds(SoftDeleteBulkRequestCo return WritableContractLogic.SoftDeleteBulkByIds(request, cancellationToken); } } + + /// + /// + /// + /// + /// + /// + /// + /// + [ApiController] + [Route("api/[controller]/[action]")] + public class SimpleQueryServiceController : SimpleQueryServiceController + where TResponseContract : class + where TEntity : class + { + /// + /// + /// + /// + public SimpleQueryServiceController(IContractLogic contractLogic) : base(contractLogic) + { + } + + /// + /// + /// + /// + /// + public SimpleQueryServiceController(IBaseUnitOfWork unitOfWork) : base(unitOfWork) + { + } + } } \ No newline at end of file From 04d6737e6bfc579aff92b28f3e72315dc98960f1 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Mon, 23 Oct 2023 17:44:54 +0330 Subject: [PATCH 02/13] Add support for MicroserviceName in IdentityManager for roles and permissions --- .../Managers/WhiteLabelManager.cs | 2 +- .../UnitOfWork.cs | 12 +++++++++- .../Interfaces/IUniqueIdentityManager.cs | 12 ++++++++++ .../Managers/DefaultUniqueIdentityManager.cs | 23 +++++++++++++++---- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs index 8f15fd4..5cdb88a 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs @@ -57,7 +57,7 @@ public async Task Initialize(string microserviceName, string whiteLableRoute, pa foundMicroservice.Id = addMicroservice.Result; } UnitOfWork.MicroserviceId = foundMicroservice.Id; - + UnitOfWork.MicroserviceName = microserviceName; var uniqueIdentityManager = new UnitOfWork(_serviceProvider).GetUniqueIdentityManager() as DefaultUniqueIdentityManager; var microserviceContextTableClient = new WhiteLables.GeneratedServices.MicroserviceContextTableClient(whiteLableRoute, HttpClient); diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs index 2d0b9f0..d660359 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using System.Threading.Tasks; namespace EasyMicroservices.Cores.AspEntityFrameworkCoreApi @@ -321,6 +322,10 @@ public virtual IMapperProvider GetMapper() /// /// /// + public static string MicroserviceName { get; set; } + /// + /// + /// public static IUniqueIdentityManager UniqueIdentityManager { get; set; } /// /// @@ -330,7 +335,12 @@ public virtual IMapperProvider GetMapper() public virtual IUniqueIdentityManager GetUniqueIdentityManager() { if (UniqueIdentityManager == null) - UniqueIdentityManager = new DefaultUniqueIdentityManager(DefaultUniqueIdentity, MicroserviceId); + { + if (DefaultUniqueIdentity.HasValue()) + UniqueIdentityManager = new DefaultUniqueIdentityManager(DefaultUniqueIdentity, MicroserviceId, MicroserviceName); + else + UniqueIdentityManager = new DefaultUniqueIdentityManager(MicroserviceId, MicroserviceName); + } return UniqueIdentityManager; } diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs index 327ad49..0879261 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs @@ -7,6 +7,18 @@ namespace EasyMicroservices.Cores.Database.Interfaces /// public interface IUniqueIdentityManager { + /// + /// + /// + string StartUniqueIdentity { get; set; } + /// + /// + /// + long MicroserviceId { get; set; } + /// + /// + /// + string MicroserviceName { get; set; } /// /// update unique identity /// diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs index ab5f6c2..cf5717a 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs @@ -18,21 +18,25 @@ public class DefaultUniqueIdentityManager : IUniqueIdentityManager /// /// /// - public DefaultUniqueIdentityManager(string startUniqueIdentity, long microserviceId) + /// + public DefaultUniqueIdentityManager(string startUniqueIdentity, long microserviceId, string microserviceName) { if (startUniqueIdentity.IsNullOrEmpty()) throw new ArgumentNullException(nameof(startUniqueIdentity)); StartUniqueIdentity = startUniqueIdentity; MicroserviceId = microserviceId; + MicroserviceName = microserviceName; } /// /// /// /// - public DefaultUniqueIdentityManager(long microserviceId) + /// + public DefaultUniqueIdentityManager(long microserviceId, string microserviceName) { MicroserviceId = microserviceId; + MicroserviceName = microserviceName; } /// @@ -43,8 +47,19 @@ public DefaultUniqueIdentityManager() } - string StartUniqueIdentity { get; set; } - long MicroserviceId { get; set; } + /// + /// + /// + public string StartUniqueIdentity { get; set; } + /// + /// + /// + public long MicroserviceId { get; set; } + /// + /// + /// + public string MicroserviceName { get; set; } + Dictionary TableIds { get; set; } = new Dictionary(); /// /// From 169162569d7c25fafa36f5af04e5d48a7472e5d1 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Mon, 23 Oct 2023 17:45:22 +0330 Subject: [PATCH 03/13] Add more tests for role and permissions --- .../AuthorizationRolePermissionsTests.cs | 142 ++++++++++++++++++ .../BasicTests.cs | 9 +- .../Controllers/UserController.cs | 39 ++++- ...syMicroservices.Cores.AspCore.Tests.csproj | 7 +- .../LongIdMappedDatabaseLogicBaseTest.cs | 2 +- .../EasyMicroservices.Cores.Tests.csproj | 2 +- 6 files changed, 192 insertions(+), 9 deletions(-) create mode 100644 src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs new file mode 100644 index 0000000..5987cb1 --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs @@ -0,0 +1,142 @@ +using EasyMicroservices.AuthenticationsMicroservice.VirtualServerForTests; +using EasyMicroservices.AuthenticationsMicroservice.VirtualServerForTests.TestResources; +using EasyMicroservices.Cores.AspCoreApi.Authorizations; +using EasyMicroservices.Cores.AspCoreApi.Interfaces; +using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces; +using EasyMicroservices.ServiceContracts; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.IdentityModel.Tokens; +using System.Net.Http.Headers; +using System.Text; + +namespace EasyMicroservices.Cores.AspCore.Tests +{ + public class AuthorizationRolePermissionsTests : BasicTests + { + public override int AppPort => 4566; + public AuthorizationRolePermissionsTests() : base() + { } + + protected override void InitializeTestHost(bool isUseAuthorization, Action serviceCollection) + { + serviceCollection = (services) => + { + services.AddScoped(); + services.AddScoped(service => service.GetService().GetUniqueIdentityManager()); + services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => + { + options.TokenValidationParameters = new TokenValidationParameters + { + ValidateIssuer = true, + ValidateAudience = true, + ValidateLifetime = true, + ValidateIssuerSigningKey = true, + ValidIssuer = "https://github.com/easymicroservices", + ValidAudience = "easymicroservices", + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("VGhpc0lzQVNlY3JldEtleUZvckp3dEF1dGhlbnRpY2F0aW9u=")) + }; + }); + }; + base.InitializeTestHost(true, serviceCollection); + } + + protected override void AssertTrue(MessageContract messageContract) + { + Assert.True(messageContract.Error.FailedReasonType == FailedReasonType.AccessDenied, messageContract.ToString()); + } + + protected override void AssertFalse(MessageContract messageContract) + { + Assert.False(messageContract); + AssertTrue(messageContract); + } + + protected override void AuthorizeAssert(MessageContract messageContract) + { + AssertTrue(messageContract); + } + + static AuthenticationVirtualTestManager AuthenticationVirtualTestManager = new(); + [Theory] + [InlineData("TestExampleFailed", "EndUser", "NoAccess", "NoAccess", false)] + [InlineData("TestExample", "EndUser", "User", "CheckHasAccess", true)] + [InlineData("TestExample", "EndUser", null, "CheckHasAccess", true)] + [InlineData("TestExample", "EndUser", null, null, true)] + [InlineData("TestExample", "EndUser", "User", null, true)] + public async Task WriterRoleTest(string microserviceName, string roleName, string serviceName, string methodName, bool result) + { + int portNumber = 1045; + AspCoreAuthorization.AuthenticationRouteAddress = $"http://localhost:{portNumber}"; + await AuthenticationVirtualTestManager.OnInitialize(portNumber); + var resources = AuthenticationResource.GetResources(microserviceName, new Dictionary>() + { + { + roleName , + new List() + { + new TestServicePermissionContract() + { + MicroserviceName = microserviceName, + MethodName = methodName, + ServiceName = serviceName + } + } + } + }); + + foreach (var resource in resources) + { + AuthenticationVirtualTestManager.AppendService(portNumber, resource.Key, resource.Value); + } + HttpClient CurrentHttpClient = new HttpClient(); + if (result) + { + var loginResult = await CurrentHttpClient.GetFromJsonAsync>($"{GetBaseUrl()}/api/user/login"); + Assert.True(loginResult); + CurrentHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", loginResult.Result); + } + var data = await CurrentHttpClient.GetFromJsonAsync($"{GetBaseUrl()}/api/user/CheckHasAccess"); + if (!result) + AssertTrue(data); + else + Assert.True(data, data.ToString()); + } + + [Theory] + [InlineData("TestExampleFailed", "EndUser", "NoAccess")] + [InlineData("TestExample", "EndUser", "User")] + [InlineData("TestExample", "EndUser", null)] + public async Task ReaderRoleTest(string microserviceName, string roleName, string serviceName) + { + int portNumber = 1045; + AspCoreAuthorization.AuthenticationRouteAddress = $"http://localhost:{portNumber}"; + await AuthenticationVirtualTestManager.OnInitialize(portNumber); + var resources = AuthenticationResource.GetResources(microserviceName, new Dictionary>() + { + { + roleName , + new List() + { + new TestServicePermissionContract() + { + MicroserviceName = microserviceName, + MethodName = "CheckHasAccess", + ServiceName = serviceName + } + } + } + }); + + foreach (var resource in resources) + { + AuthenticationVirtualTestManager.AppendService(portNumber, resource.Key, resource.Value); + } + HttpClient CurrentHttpClient = new HttpClient(); + var loginResult = await CurrentHttpClient.GetFromJsonAsync>($"{GetBaseUrl()}/api/user/login"); + Assert.True(loginResult); + CurrentHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", loginResult.Result); + var data = await CurrentHttpClient.GetFromJsonAsync($"{GetBaseUrl()}/api/user/CheckHasNoAccess"); + AssertTrue(data); + } + } +} diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs index 1f57a07..96f9d99 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs @@ -67,7 +67,7 @@ public async Task AuthorizeTest() { var data = await HttpClient.GetStringAsync($"{GetBaseUrl()}/api/user/AuthorizeError"); var result = JsonConvert.DeserializeObject(data); - Assert.True(result.Error.FailedReasonType == FailedReasonType.SessionAccessDenied); + AuthorizeAssert(result); } [Fact] @@ -76,7 +76,7 @@ public async Task InternalErrorTest() var data = await HttpClient.GetStringAsync($"{GetBaseUrl()}/api/user/InternalError"); var result = JsonConvert.DeserializeObject(data); AssertFalse(result); - if (result.Error.FailedReasonType != FailedReasonType.SessionAccessDenied) + if (result.Error.FailedReasonType != FailedReasonType.SessionAccessDenied && result.Error.FailedReasonType != FailedReasonType.AccessDenied) AssertContains(result.Error.StackTrace, x => x.Contains("UserController.cs")); } @@ -97,6 +97,11 @@ public async Task AddUser() AssertTrue(users.Result.All(x => DefaultUniqueIdentityManager.DecodeUniqueIdentity(x.UniqueIdentity).Length > 2)); } + protected virtual void AuthorizeAssert(MessageContract messageContract) + { + Assert.True(messageContract.Error.FailedReasonType == FailedReasonType.SessionAccessDenied); + } + protected virtual void AssertTrue(MessageContract messageContract) { Assert.True(messageContract); diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Controllers/UserController.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Controllers/UserController.cs index d3caed3..0d12ae9 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Controllers/UserController.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Controllers/UserController.cs @@ -1,11 +1,14 @@ using EasyMicroservices.Cores.AspCoreApi; +using EasyMicroservices.Cores.AspCoreApi.Attributes; using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces; -using EasyMicroservices.Cores.Database.Interfaces; using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Entities; using EasyMicroservices.ServiceContracts; -using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.IdentityModel.Tokens; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using System.Text; namespace EasyMicroservices.Cores.AspCore.Tests.Controllers { @@ -22,6 +25,38 @@ public MessageContract AuthorizeError() return true; } + [HttpGet] + public MessageContract CheckHasAccess() + { + return true; + } + + [HttpGet] + public MessageContract CheckHasNoAccess() + { + return true; + } + + [HttpGet] + [AllowAnonymous] + public MessageContract Login() + { + var tokenHandler = new JwtSecurityTokenHandler(); + var key = Encoding.UTF8.GetBytes("VGhpc0lzQVNlY3JldEtleUZvckp3dEF1dGhlbnRpY2F0aW9u="); + var tokenDescriptor = new SecurityTokenDescriptor + { + Subject = new ClaimsIdentity(new List() { new Claim(ClaimTypes.Role, "EndUser") }), + Expires = DateTime.UtcNow.AddSeconds(1000), + Issuer = "https://github.com/easymicroservices", + Audience = "easymicroservices", + SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) + }; + var token = tokenHandler.CreateToken(tokenDescriptor); + var tokenString = tokenHandler.WriteToken(token); + + return tokenString; + } + [HttpGet] public MessageContract InternalError() { diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/EasyMicroservices.Cores.AspCore.Tests.csproj b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/EasyMicroservices.Cores.AspCore.Tests.csproj index 5b5f671..9bc94c0 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/EasyMicroservices.Cores.AspCore.Tests.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/EasyMicroservices.Cores.AspCore.Tests.csproj @@ -9,8 +9,9 @@ - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive @@ -25,7 +26,7 @@ - 7.0.11 + 7.0.12 diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs b/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs index 93445d7..f1f8c1f 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs +++ b/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs @@ -65,7 +65,7 @@ public virtual IDatabase GetDatabase() const long SubjectTableContextId = 153; public virtual IUniqueIdentityManager GetUniqueIdentityManager() { - var manager = new DefaultUniqueIdentityManager("1-1", 5); + var manager = new DefaultUniqueIdentityManager("1-1", 5, "TestExample"); manager.InitializeTables(5, manager.GetContextName(typeof(MyTestContext)), manager.GetTableName(typeof(UserEntity)), TableContextId); manager.InitializeTables(5, manager.GetContextName(typeof(MyTestContext)), manager.GetTableName(typeof(ProfileEntity)), ProfileTableContextId); manager.InitializeTables(5, manager.GetContextName(typeof(MyTestContext)), manager.GetTableName(typeof(CategoryEntity)), CategoryTableContextId); diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj b/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj index eab82a2..8d7b51c 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj @@ -14,7 +14,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive From 715c69fd2b529b2ef064ae6190246a7dae79408c Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Mon, 23 Oct 2023 17:45:33 +0330 Subject: [PATCH 04/13] Add support for role and permissions --- .../Authorizations/AspCoreAuthorization.cs | 107 ++++++++++++++++++ .../EasyMicroservices.Cores.AspCoreApi.csproj | 8 ++ .../Interfaces/IAuthorization.cs | 4 - .../StartUpExtensions.cs | 2 +- .../EasyMicroservices.Cores.Database.csproj | 2 +- ...ores.Relational.EntityFrameworkCore.csproj | 2 +- 6 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs new file mode 100644 index 0000000..83f308f --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs @@ -0,0 +1,107 @@ +using EasyMicroservices.Cores.AspCoreApi.Attributes; +using EasyMicroservices.Cores.AspCoreApi.Interfaces; +using EasyMicroservices.Cores.Database.Interfaces; +using EasyMicroservices.ServiceContracts; +using EasyMicroservices.Utilities.Collections.Generic; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Controllers; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Security.Claims; +using System.Threading.Tasks; +using ServicePermissionContract = Authentications.GeneratedServices.ServicePermissionContract; +namespace EasyMicroservices.Cores.AspCoreApi.Authorizations +{ + /// + /// + /// + public class AspCoreAuthorization : IAuthorization + { + /// + /// + /// + public AspCoreAuthorization(IUniqueIdentityManager uniqueIdentityManager) + { + UniqueIdentityManager = uniqueIdentityManager; + } + + /// + /// + /// + public IUniqueIdentityManager UniqueIdentityManager { get; } + /// + /// + /// + public static string AuthenticationRouteAddress { get; set; } + + /// + /// + /// + /// + /// + /// + public async Task CheckIsAuthorized(HttpContext httpContext) + { + var hasPermission = await HasPermission(httpContext).AsCheckedResult(); + if (!hasPermission) + return (FailedReasonType.AccessDenied, "Sorry, you cannot call this service, you have not enough permissions!"); + return true; + } + + static ConcurrentDictionary> CachedPermissions { get; set; } = new(); + static readonly ConcurrentTreeDictionary TreeDictionary = new ConcurrentTreeDictionary(); + async Task FetchData(string roleName) + { + var servicePermissionClient = new Authentications.GeneratedServices.ServicePermissionClient(AuthenticationRouteAddress, new System.Net.Http.HttpClient()); + var permissionsResult = await servicePermissionClient.GetAllPermissionsByAsync(new Authentications.GeneratedServices.ServicePermissionRequestContract() + { + MicroserviceName = UniqueIdentityManager.MicroserviceName, + RoleName = roleName + }); + if (permissionsResult.IsSuccess) + { + CachedPermissions[roleName] = permissionsResult.Result; + AddToTreeDictionary(roleName, permissionsResult.Result); + return true; + } + return permissionsResult.ToContract(); + } + + void AddToTreeDictionary(string roleName, ICollection permissions) + { + foreach (var permission in permissions) + { + TreeDictionary.TryAdd(roleName, permission.MicroserviceName, permission.ServiceName, permission.MethodName, true); + } + } + + async Task> HasPermission(HttpContext httpContext) + { + var controllerActionDescriptor = httpContext.GetEndpoint().Metadata.GetMetadata(); + if (controllerActionDescriptor.ControllerTypeInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute)).Any() || + controllerActionDescriptor.MethodInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute)).Any()) + return true; + + string controllerName = httpContext.Request.RouteValues["controller"].ToString(); + string actionName = httpContext.Request.RouteValues["action"].ToString(); + List roleClaims = httpContext.User.FindAll(ClaimTypes.Role).ToList(); + if (roleClaims.Count == 0) + return (FailedReasonType.AccessDenied, "There is no claim role founded! did you forgot to use services.AddAuthentication?"); + if (!roleClaims.All(x => CachedPermissions.ContainsKey(x.Value))) + { + foreach (var role in roleClaims) + { + var fetchDataResult = await FetchData(role.Value); + if (!fetchDataResult) + return fetchDataResult.ToContract(); + } + } + return roleClaims.Any(role => TreeDictionary.TryGetValue(new object[] { role.Value, UniqueIdentityManager.MicroserviceName, controllerName, actionName }, out IList permissions) + && permissions.LastOrDefault() is bool value && value); + } + } +} diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj index c083b6b..84ef016 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj @@ -25,4 +25,12 @@ + + + + + + + + diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Interfaces/IAuthorization.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Interfaces/IAuthorization.cs index 96c6aa5..3784286 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Interfaces/IAuthorization.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Interfaces/IAuthorization.cs @@ -1,9 +1,5 @@ using EasyMicroservices.ServiceContracts; using Microsoft.AspNetCore.Http; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; namespace EasyMicroservices.Cores.AspCoreApi.Interfaces diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs index e3c004f..ccf93b0 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs @@ -76,7 +76,7 @@ static async Task ExceptionHandler(HttpContext context) context.Response.StatusCode = (int)HttpStatusCode.OK; var exception = context.Features.Get()?.Error; MessageContract response = exception is InvalidResultOfMessageContractException ex ? ex.MessageContract : exception; - if (exception.Message.Contains("Authenti", StringComparison.OrdinalIgnoreCase)) + if (exception.Message.Contains("Authenti", StringComparison.OrdinalIgnoreCase) && response.Error.FailedReasonType != FailedReasonType.AccessDenied) response.Error.FailedReasonType = FailedReasonType.SessionAccessDenied; response.Error.ServiceDetails.MethodName = context.Request.Path.ToString(); var json = JsonSerializer.Serialize(response); diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj index a44eb23..3c97c77 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj index 78a77e1..1f4a748 100644 --- a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj @@ -21,7 +21,7 @@ - + From c59a0fae6ba50e5ead109e0c6b150c6a36806682 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Mon, 23 Oct 2023 17:46:47 +0330 Subject: [PATCH 05/13] add versions --- .../EasyMicroservices.Cores.AspCoreApi.csproj | 2 +- .../EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj | 2 +- .../EasyMicroservices.Cores.Contracts.csproj | 2 +- .../EasyMicroservices.Cores.Database.csproj | 2 +- .../EasyMicroservices.Cores.EntityFrameworkCore.csproj | 2 +- ...asyMicroservices.Cores.Relational.EntityFrameworkCore.csproj | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj index 84ef016..6fc4198 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.38 + 0.0.0.40 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj index fdc1b60..0aa0e17 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.22 + 0.0.0.40 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet,aspcore,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj index b234b64..4959aa8 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.14 + 0.0.0.40 core contracts. EasyMicroservices@gmail.com core,cores,base,contract,contracts,dto,dtos diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj index 3c97c77..73c6f37 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.39 + 0.0.0.40 core of database. EasyMicroservices@gmail.com core,cores,base,database diff --git a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj index a3876f2..ebd64ad 100644 --- a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.30 + 0.0.0.40 ef core of database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj index 1f4a748..6a912b3 100644 --- a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.27 + 0.0.0.40 ef core of Relational database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore,Relational From 4432a55d3b69ad958570cf75c99cf3638d3ca00d Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Mon, 23 Oct 2023 17:55:32 +0330 Subject: [PATCH 06/13] clean not used code --- .../Controllers/UserController.cs | 1 - .../Authorizations/AspCoreAuthorization.cs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Controllers/UserController.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Controllers/UserController.cs index 0d12ae9..27c56b3 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Controllers/UserController.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Controllers/UserController.cs @@ -1,5 +1,4 @@ using EasyMicroservices.Cores.AspCoreApi; -using EasyMicroservices.Cores.AspCoreApi.Attributes; using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces; using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Entities; using EasyMicroservices.ServiceContracts; diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs index 83f308f..3759d2c 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs @@ -1,5 +1,4 @@ -using EasyMicroservices.Cores.AspCoreApi.Attributes; -using EasyMicroservices.Cores.AspCoreApi.Interfaces; +using EasyMicroservices.Cores.AspCoreApi.Interfaces; using EasyMicroservices.Cores.Database.Interfaces; using EasyMicroservices.ServiceContracts; using EasyMicroservices.Utilities.Collections.Generic; From b2431d04eb494c85a4b238d71fc7314e87d7586e Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Mon, 23 Oct 2023 22:24:54 +0330 Subject: [PATCH 07/13] update packages --- .../AuthorizationRolePermissionsTests.cs | 4 ++-- .../EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs | 2 +- .../EasyMicroservices.Cores.AspCore.Tests.csproj | 2 +- .../EasyMicroservices.Cores.Tests.csproj | 4 ++-- .../Laboratories/WhiteLabelLaboratoryTest.cs | 3 ++- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs index 5987cb1..da626bd 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs @@ -66,7 +66,7 @@ protected override void AuthorizeAssert(MessageContract messageContract) public async Task WriterRoleTest(string microserviceName, string roleName, string serviceName, string methodName, bool result) { int portNumber = 1045; - AspCoreAuthorization.AuthenticationRouteAddress = $"http://localhost:{portNumber}"; + AspCoreAuthorization.AuthenticationRouteAddress = $"http://{localhost}:{portNumber}"; await AuthenticationVirtualTestManager.OnInitialize(portNumber); var resources = AuthenticationResource.GetResources(microserviceName, new Dictionary>() { @@ -109,7 +109,7 @@ public async Task WriterRoleTest(string microserviceName, string roleName, strin public async Task ReaderRoleTest(string microserviceName, string roleName, string serviceName) { int portNumber = 1045; - AspCoreAuthorization.AuthenticationRouteAddress = $"http://localhost:{portNumber}"; + AspCoreAuthorization.AuthenticationRouteAddress = $"http://{localhost}:{portNumber}"; await AuthenticationVirtualTestManager.OnInitialize(portNumber); var resources = AuthenticationResource.GetResources(microserviceName, new Dictionary>() { diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs index 96f9d99..4bd7ed2 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs @@ -44,7 +44,7 @@ string RouteAddress { get { - return $"http://localhost:{AppPort}"; + return $"http://{localhost}:{AppPort}"; } } diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/EasyMicroservices.Cores.AspCore.Tests.csproj b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/EasyMicroservices.Cores.AspCore.Tests.csproj index 9bc94c0..3134651 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/EasyMicroservices.Cores.AspCore.Tests.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/EasyMicroservices.Cores.AspCore.Tests.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj b/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj index 8d7b51c..4f96004 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj @@ -9,7 +9,7 @@ - + @@ -20,7 +20,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs b/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs index a57020a..03999cf 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs +++ b/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs @@ -8,12 +8,13 @@ namespace EasyMicroservices.Cores.Tests.Laboratories { public abstract class WhiteLabelLaboratoryTest { + public const string localhost = "localhost"; protected int Port = 6041; string _routeAddress = ""; public HttpClient HttpClient { get; set; } = new HttpClient(); public WhiteLabelLaboratoryTest() { - _routeAddress = $"http://localhost:{Port}"; + _routeAddress = $"http://{localhost}:{Port}"; } protected static WhiteLabelVirtualTestManager WhiteLabelVirtualTestManager { get; set; } = new WhiteLabelVirtualTestManager(); From b1705777759b2cc11334dd637d05ae1251c21cd5 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Mon, 23 Oct 2023 22:34:58 +0330 Subject: [PATCH 08/13] make httpclient static --- .../AuthorizationRolePermissionsTests.cs | 2 ++ src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs | 1 - .../Laboratories/WhiteLabelLaboratoryTest.cs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs index da626bd..879045b 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs @@ -42,6 +42,7 @@ protected override void InitializeTestHost(bool isUseAuthorization, Action serviceCollection) { diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs b/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs index 03999cf..515dec5 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs +++ b/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs @@ -11,7 +11,7 @@ public abstract class WhiteLabelLaboratoryTest public const string localhost = "localhost"; protected int Port = 6041; string _routeAddress = ""; - public HttpClient HttpClient { get; set; } = new HttpClient(); + protected static HttpClient HttpClient { get; set; } = new HttpClient(); public WhiteLabelLaboratoryTest() { _routeAddress = $"http://{localhost}:{Port}"; From c2bad955c55c505564cbbb81673281b0e8cb0a3c Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Tue, 24 Oct 2023 10:33:49 +0330 Subject: [PATCH 09/13] add logs --- .../Managers/WhiteLabelManager.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs index 5cdb88a..4df5594 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using System.Linq; using System.Net.Http; -using System.Text; using System.Threading.Tasks; using WhiteLables.GeneratedServices; @@ -34,7 +33,9 @@ string GetDefaultUniqueIdentity(ICollection whiteLables, lon public async Task Initialize(string microserviceName, string whiteLableRoute, params Type[] dbContextTypes) { - Debug.WriteLine($"WhiteLabelManager Initialized!"); + Trace.WriteLine($"T WhiteLabelManager Initialized! {microserviceName} {whiteLableRoute}"); + Console.WriteLine($"C WhiteLabelManager Initialized! {microserviceName} {whiteLableRoute}"); + Debug.WriteLine($"D WhiteLabelManager Initialized! {microserviceName} {whiteLableRoute}"); Debug.WriteLine(Environment.StackTrace); if (dbContextTypes.IsEmpty()) return; From b1ce993d16977d6c24a66ee8f21459b5de4c5a10 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Tue, 24 Oct 2023 10:36:38 +0330 Subject: [PATCH 10/13] add more logs --- .../Managers/WhiteLabelManager.cs | 5 +---- .../Laboratories/WhiteLabelLaboratoryTest.cs | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs index 4df5594..4291f98 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs @@ -33,10 +33,7 @@ string GetDefaultUniqueIdentity(ICollection whiteLables, lon public async Task Initialize(string microserviceName, string whiteLableRoute, params Type[] dbContextTypes) { - Trace.WriteLine($"T WhiteLabelManager Initialized! {microserviceName} {whiteLableRoute}"); - Console.WriteLine($"C WhiteLabelManager Initialized! {microserviceName} {whiteLableRoute}"); - Debug.WriteLine($"D WhiteLabelManager Initialized! {microserviceName} {whiteLableRoute}"); - Debug.WriteLine(Environment.StackTrace); + Console.WriteLine($"WhiteLabelManager Initialize! {microserviceName} {whiteLableRoute}"); if (dbContextTypes.IsEmpty()) return; var whiteLabelClient = new WhiteLables.GeneratedServices.WhiteLabelClient(whiteLableRoute, HttpClient); diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs b/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs index 515dec5..6a7e7e6 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs +++ b/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs @@ -30,6 +30,7 @@ protected async Task OnInitialize() return; if (await WhiteLabelVirtualTestManager.OnInitialize(Port)) { + Console.WriteLine($"WhiteLabelVirtualTestManager Initialized! {Port}"); foreach (var item in WhiteLabelResource.GetResources(new MyTestContext(new DatabaseBuilder()), "TextExample")) { WhiteLabelVirtualTestManager.AppendService(Port, item.Key, item.Value); From f1c9c24ed937b1939842dfb16a1d5d3166b42d57 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Tue, 24 Oct 2023 10:38:56 +0330 Subject: [PATCH 11/13] change localhost to ip address --- .../Laboratories/WhiteLabelLaboratoryTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs b/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs index 6a7e7e6..f5d795d 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs +++ b/src/CSharp/EasyMicroservices.Cores.Tests/Laboratories/WhiteLabelLaboratoryTest.cs @@ -8,7 +8,7 @@ namespace EasyMicroservices.Cores.Tests.Laboratories { public abstract class WhiteLabelLaboratoryTest { - public const string localhost = "localhost"; + public const string localhost = "127.0.0.1"; protected int Port = 6041; string _routeAddress = ""; protected static HttpClient HttpClient { get; set; } = new HttpClient(); From 6c8bd2045b64444b85c022b6097cb13b3dbe698f Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Wed, 25 Oct 2023 16:40:50 +0330 Subject: [PATCH 12/13] Fix OnModelCreating bug for migration --- .../RelationalCoreContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/RelationalCoreContext.cs b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/RelationalCoreContext.cs index ad89784..509e9e7 100644 --- a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/RelationalCoreContext.cs +++ b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/RelationalCoreContext.cs @@ -70,7 +70,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) protected virtual StringBuilder AutoModelCreating(ModelBuilder modelBuilder) { StringBuilder stringBuilder = new StringBuilder(); - base.OnModelCreating(modelBuilder); + OnModelCreating(modelBuilder); foreach (var entityType in GetAllEntities(modelBuilder)) { modelBuilder.Entity(entityType, e => From 1a9939cd10f19a16d49bcb6b0b606cc0723a2f3c Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Wed, 25 Oct 2023 16:41:30 +0330 Subject: [PATCH 13/13] update versions --- .../EasyMicroservices.Cores.AspCoreApi.csproj | 2 +- .../EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj | 2 +- .../EasyMicroservices.Cores.Contracts.csproj | 2 +- .../EasyMicroservices.Cores.Database.csproj | 2 +- .../EasyMicroservices.Cores.EntityFrameworkCore.csproj | 2 +- ...asyMicroservices.Cores.Relational.EntityFrameworkCore.csproj | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj index 6fc4198..55d43e9 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.40 + 0.0.0.41 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj index 0aa0e17..51e0e5c 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.40 + 0.0.0.41 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet,aspcore,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj index 4959aa8..bd0dcb4 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.40 + 0.0.0.41 core contracts. EasyMicroservices@gmail.com core,cores,base,contract,contracts,dto,dtos diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj index 73c6f37..bfc6b1b 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.40 + 0.0.0.41 core of database. EasyMicroservices@gmail.com core,cores,base,database diff --git a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj index ebd64ad..de20e1c 100644 --- a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.40 + 0.0.0.41 ef core of database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj index 6a912b3..072b039 100644 --- a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.40 + 0.0.0.41 ef core of Relational database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore,Relational