Giter VIP home page Giter VIP logo

Comments (14)

JonPSmith avatar JonPSmith commented on September 26, 2024

Hi @PieterHaasbroek,

A couple of questions.

  1. There are two applications in the repo: DataAuthWebApp (handles multi-tenant) and TestWebApp (handles permissions only). Both of these have different AddUsersAndExtraAuthAsync methods - which one did you use?
  2. The Exception isn't very useful because it doesn't tell me which part of my code it failed in (that's the typical problem with exceptions Async methods). Is there any other exception information? Sometimes there is.

PS. I found one thing in the DataAuthWebApp's AddUsersAndExtraAuthAsync and changed it. But I plan to do more work on the application to support SQL Service in a few weeks time (after all the other things I need to do!).

from permissionaccesscontrol.

PieterHaasbroek avatar PieterHaasbroek commented on September 26, 2024

Hi @JonPSmith,

I've added you onto my private repository as a collaborator, see the following link:
https://github.com/PieterHaasbroek/9.Jon/invitations
It's still a work on progress with the contents, but this should enable you to run the code. The database connection links are in the main projects json file, you can add a test sql database test connection here and all should be fine.

It is a bit of a concatenation that I shared as this is the final framework I would like to use combining both permission and tenants.

You'll notice in the Program Main I have 2 codes. The reason for this is the async Main gives issues when generating migrations for Db creation.

I'll open an issue on the repository for ease of communication and we can transfer the final solution back to here for future reference.

Thanks for all the help!

from permissionaccesscontrol.

JonPSmith avatar JonPSmith commented on September 26, 2024

Hi @PieterHaasbroek,

Thanks for asking me into your project, but I plan to spend time making my original code handle real databases as well as in-memory (plus some other updates too). This should flush out the problems you are having with Async.

from permissionaccesscontrol.

JonPSmith avatar JonPSmith commented on September 26, 2024

Hi @PieterHaasbroek ,

Just to say I have been working on a new version of the project which works both with in-memory and real (SQL Server) databases. I was hoping to have it finished before the NDC Oslo conference (where I am speaking on this topic), but I didn't manage that.

There's no documentation for the new version yet so I don't suggest you use it. What I have done is sort out the async code and written lots of "CheckAdd" methods that only add users, permissions, etc. if they aren't already there. That was a big job but you need it if you have a real database.

If you follow me on twitter (@therefromedprog) then you will see what the next article comes out which explains how the new version works.

from permissionaccesscontrol.

PieterHaasbroek avatar PieterHaasbroek commented on September 26, 2024

Hi @JonPSmith

Thanks for the update. I've tinkered a bit and managed to get it going. Also built in a check for the seeding by using a logic check to prevent reseeding on subsequent runs. One quick question though, for the allocation of users to shops. Is it possible with the code as it is to add a user to more than 1 shop without the user being allocated as a district manager? - Disregard see you've added some additional authentication levels to the overall model e.g. company. This might be the differentiation I needed. Looking forward to your write-up on the revised code.

This framework is worth all the time you spent and is worth taking note of for effective management of authority in most app developments. Thanks for sharing it.

from permissionaccesscontrol.

JonPSmith avatar JonPSmith commented on September 26, 2024

Hi @PieterHaasbroek,

Glad it was helpful. The first version was thrown together, but this one should be much easier to use.

I spoke on the new version at NDC Oslo last Thursday and it went down really well. The questions were great and I plan to make some changes to the code to touch on those comments (mainly on multi-tenant). Once I have done that I will be writing two new articles.

Be warned: this will take some weeks as I have another talk to do this week and someone wants to contact me to do a job.

from permissionaccesscontrol.

PieterHaasbroek avatar PieterHaasbroek commented on September 26, 2024

Hi @JonPSmith ,

Thanks for the update. Like I said, this is definitely a code to note!

Perhaps one question relating to the new code (you might have incorporated this in the new version), but do you plan on making a separation of environment between multitenant systems? This will be quite useful in the long run.

What I commonly find in the engineering field is that there are often users who use applications as both an internal management tool as well as a collaboration platform. So the internal environment is used for management of the specific portion of work where Tenant X (host) will control the core contents of the app and act in a role with more permissions allowed while Tenant Y will then collaborate on Tenant X's collaborative area of his app, but then the same app can be hosted by Tenant Y to which Tenant X is a collaborator. I'm also trying to see if I can find a way to merge the collaboration section shared with a Tenant into the internal platform thereby creating separation of data while providing a contact point for collaboration. Thus creating a host environment (separated data) into different work groups (shops) sharing data on a common platform. (Note: Tenant in this context is relative to a group of resources)

from permissionaccesscontrol.

JonPSmith avatar JonPSmith commented on September 26, 2024

I thinking of a something like GitHub, where users can collaborate - correct? That's a different type of multi-tenant which I won't support that in this example application.

You can of course employ me to build such a system :)

from permissionaccesscontrol.

PieterHaasbroek avatar PieterHaasbroek commented on September 26, 2024

Almost, but not exactly. It is more geared towards erp / erpm.

What fun will that be? Haha! Will admit that your work is helping a lot with getting the framework to a point where I can see some light at the end of the tunnel.

from permissionaccesscontrol.

PieterHaasbroek avatar PieterHaasbroek commented on September 26, 2024

When I try to run the new code as is I get the following error:

System.InvalidOperationException
HResult=0x80131509
Message=No suitable constructor found for entity type 'UserDataHierarchical'. The following constructors had parameters that could not be bound to properties of the entity type: cannot bind 'linkedTenant' in 'UserDataHierarchical(string userId, int linkedTenantId, TenantBase linkedTenant)'; cannot bind 'linkedTenant' in 'UserDataHierarchical(string userId, TenantBase linkedTenant)'.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConstructorBindingConvention.Apply(InternalModelBuilder modelBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnModelBuilt(InternalModelBuilder modelBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnModelBuilt(InternalModelBuilder modelBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Internal.Model.Validate()
at Microsoft.EntityFrameworkCore.ModelBuilder.FinalizeModel()
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.<>c__DisplayClass5_0.b__1()
at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy1.CreateValue() at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator) at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel() at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model() at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__7_2(IServiceProvider p) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
at Microsoft.EntityFrameworkCore.DbContext.get_Model()
at GenericServices.Setup.Internal.SetupEntitiesExtensions.RegisterEntityClasses(DbContext context)
at GenericServices.Setup.Internal.SetupAllEntities..ctor(IServiceCollection services, IGenericServicesConfig publicConfig, Type[] contextTypes)
at GenericServices.Setup.ConfigureGenericServices.ConfigureGenericServicesEntities(IServiceCollection serviceCollection, Type[] contextTypes)
at PermissionAccessControl2.Startup.ConfigureServices(IServiceCollection services) in E:\App Development\ASP.Net\PermissionAccessControl2-master\PermissionAccessControl2-master\PermissionAccessControl2\Startup.cs:line 69

Do you know what this could be?

from permissionaccesscontrol.

JonPSmith avatar JonPSmith commented on September 26, 2024

Hi @PieterHaasbroek,

As I said this isn't anything like finished and will be bouncing around for some weeks yet. I only gave you a link to this so that you knew the first version wasn't the correct version to use. I have lots of things on so progress will be so, and the code will break many times.

The code will be 'stable but not finished' when I produce the first article, and it will be finished when I have written the third article. This will take more than a month.

from permissionaccesscontrol.

PieterHaasbroek avatar PieterHaasbroek commented on September 26, 2024

Hi @JonPSmith

Thanks. Looking forward to it. Seeing what you have done up to know made me quite inquisitive. So no intention to hurry you at all. Looking forward to see the final product.

Thanks!

from permissionaccesscontrol.

JonPSmith avatar JonPSmith commented on September 26, 2024

Hi @PieterHaasbroek,

The PermissionAccessControl2 is stable and runs. I have released a new article "A better way to handle ASP.NET Core authorization – six months on" which explains some of the changes.

I will be working on the next article which will mean changes to the code, but I will do that in a different branch and merge when I release the next article. That should happen in the next week or so.

from permissionaccesscontrol.

ladaltamirano avatar ladaltamirano commented on September 26, 2024

Hi Jon,

I transferred the discussion to GitHub as per your request. Thank you for the quick response.

So, run down of what I've done up to now:

  • Created and ASP.NET Core application (NetCoreApp 2.2 Framework) without authorization
  • Scaffolded Identity into the project
  • Transferred the database from in memory to Azure Hosted SQL
  • Customized the IdentityUser and added additional roles in a separate class library which is used for setting up the database
  • Migrated and updated the database
  • Updated the StartupExtensions code to reference to the User Class Library (this enables me to change the IdentityUser to the CustomUser - without this the StartupExtensions through an error as no instance of IdentityUser is used in the main startup)
  • Test the coding without seeding the database, it all runs smoothly and I can register new users and sign in.
  • Changed the Program Main to Async and added the StartupExtention there (as per your updated TestWebApp)
  • When running the code the following error occurs:

Pop-up in code (In Main App Program.cs at "await webHost.Services.AddUsersAndExtraAuthAsync()":
System.InvalidOperationException: 'A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext, however instance members are not guaranteed to be thread safe. This could also be caused by a nested query being evaluated on the client, if this is the case rewrite the query avoiding nested invocations.'

On Prompt:
fail: Microsoft.EntityFrameworkCore.Update[10000]
An exception occurred in the database while saving changes for context type 'User.Models.IdentityContext'. (DbContext of Asp Identity)
System.InvalidOperationException: A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext, however instance members are not guaranteed to be thread safe. This could also be caused by a nested query being evaluated on the client, if this is the case rewrite the query avoiding nested invocations.
at Microsoft.EntityFrameworkCore.Internal.ConcurrencyDetector.EnterCriticalSection()
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IReadOnlyList1 entriesToSave, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) System.InvalidOperationException: A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext, however instance members are not guaranteed to be thread safe. This could also be caused by a nested query being evaluated on the client, if this is the case rewrite the query avoiding nested invocations. at Microsoft.EntityFrameworkCore.Internal.ConcurrencyDetector.EnterCriticalSection() at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IReadOnlyList1 entriesToSave, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)

Hi Pieter. Could you write down the steps or commands to generate the migrations to work with SQL Server database? There are 4 dbcontexts which are in another library, so I was wondering how you could do these steps.
Thanks,

from permissionaccesscontrol.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.