casbin-net / casbin-aspnetcore

Casbin.NET integration middleware and sample code for ASP.NET Core
https://github.com/casbin/Casbin.NET
Apache License 2.0
64 stars 20 forks source link

Unable to get overrides for DefaultRequestTransformer and DefaultEnforcerFactory to work #24

Closed thoraj closed 3 years ago

thoraj commented 3 years ago

After upgrading to Casbin.AspNetCore v0.2.0 It seems the overrides specified in services.AddCasbinAuthorization() does not have an effect.

Using the code below I have not been able to verify that the DefaultEnforcerFactory lambda is called, or that the VerjiRbacTenantRequestTransformer() is ever called.

            services.AddCasbinAuthorization(options =>
            {
                options.PreferSubClaimType = "sub";
                options.DefaultModelPath = Path.Combine(@"AccessControl\CasbinConfigs", "basic_rest_domain_model.conf");
                options.DefaultPolicyPath = Path.Combine(@"AccessControl\CasbinConfigs", "basic_rest_domain_policy.csv");

                // Comment line below to use the default BasicRequestTransformer
                // Note: Commenting the line means that the action methods MUST have [CasbinAuthorize()] attribute which explicitly specifies obj and policy. Otherwise authorization will be denied
                options.DefaultRequestTransformer = new VerjiRbacTenantRequestTransformer();
                options.DefaultEnforcerFactory = (svc, model) =>
                {
                    var context = svc.GetRequiredService<VerjiCasbinDbContext>();
                    var adapter = new EFCoreAdapter<Guid>(context);
                    return new Enforcer(model, adapter);
                };
            });

Did anything change in v0.2.0 so this must be done differently?

PS: I'm consuming the packages from nuget.org (and not myget.org/casbin)

hsluoyz commented 3 years ago

@Sagilio

sagilio commented 3 years ago

Fixed by https://github.com/casbin-net/casbin-aspnetcore/commit/e5dc07746742f04ed17e2c9ebb07b34baa1e6585 and release in the v0.2.1.

hsluoyz commented 3 years ago

https://github.com/casbin-net/casbin-aspnetcore/releases/tag/v0.2.1