Implementing a Custom RootPolicyProvider
In the common use case for Enforcer it is expected to declare the name of the root policy at startup. For situations where this may not be appropriate, such as a multi-tenanted application, you can provide your own logic to dynamically determine the appropriate root policy name.
Custom root policy resolution is done via the interface RSK.Enforcer.PDP.IProvideRootPolicy
, which is defined as follows:
public interace IProvideRootPolicy
{
Task<string> GetRootPolicyName();
}
To use your custom root policy provider, use the AddEnforcer
overload which does not take a root policy name, followed by the AddRootPolicyProvider<T>
method, specifying the concrete type to use as the root policy provider.
Example:
services
.AddEnforcer(o =>
{
o.Licensee = "Rock Solid knowledge";
o.LicenseKey = "<license key>";
})
.AddRootPolicyProvider<MyCustomRootPolicyProvider>();