You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-22Lines changed: 71 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,6 @@ It provides three ways of integration
23
23
24
24
[Extension enhancement using CASBIN authorisation](#Extension-enhancement-using-CASBIN-authorisation)
25
25
26
-
27
26
Refer to the usage section below for details on integration
28
27
29
28
## Install
@@ -119,6 +118,7 @@ export class User extends Entity implements UserPermissionsOverride<string> {
119
118
}
120
119
}
121
120
```
121
+
122
122
- For method #3, we also provide a simple provider function [_AuthorizationBindings.USER_PERMISSIONS_](<[./src/providers/user-permissions.provider.ts](https://github.com/sourcefuse/loopback4-authorization/blob/master/src/providers/user-permissions.provider.ts)>) to evaluate the user permissions based on its role permissions and user-level overrides. Just inject it
# Extension enhancement using CASBIN authorisation
273
273
274
-
As a further enhancement to these methods, we are using [casbin library!](https://casbin.org/docs/en/overview) to define permissions at level of entity or resource associated with an API call. Casbin authorisation implementation can be performed in two ways:
274
+
As a further enhancement to these methods, we are using [casbin library](https://casbin.org/docs/en/overview) to define permissions at level of entity or resource associated with an API call. Casbin authorisation implementation can be performed in two ways:
275
+
275
276
1.**Using default casbin policy document** - Define policy document in default casbin format in the app, and configure authorise decorator to use those policies.
276
277
2.**Defining custom logic to form dynamic policies** - Implement dynamic permissions based on app logic in casbin-enforcer-config provider. Authorisation extension will dynamically create casbin policy using this business logic to give the authorisation decisions.
- Implement the **Casbin Resource value modifier provider**. Customise the resource value based on business logic using route arguments parameter in the provider.
299
301
300
302
```ts
@@ -303,22 +305,32 @@ import {HttpErrors} from '@loopback/rest';
thrownewHttpErrors.InternalServerError(`Metadata object not found`);
324
336
}
@@ -330,40 +342,77 @@ export class CasbinResValModifierProvider
330
342
return`${res}`;
331
343
}
332
344
}
333
-
334
345
```
335
-
- Implement the **casbin enforcer config provider** . Provide the casbin model path. In case 1 of using [default casbin format policy!](https://casbin.org/docs/en/how-it-works), provide the casbin policy path. In other case of creating dynamic policy, provide the array of Resource-Permission objects for a given user, based on business logic.
346
+
347
+
- Implement the **casbin enforcer config provider** . Provide the casbin model path. Model definition can be initialized from [.CONF file, from code, or from a string](https://casbin.org/docs/en/model-storage).
348
+
In the case of policy creation being handled by extension (isCasbinPolicy parameter is false), provide the array of Resource-Permission objects for a given user, based on business logic.
349
+
In other case, provide the policy from file or as CSV string or from [casbin Adapters](https://casbin.org/docs/en/adapters).
350
+
**NOTE**: In the second case, if model is initialized from .CONF file, then any of the above formats can be used for policy. But if model is being initialised from code or string, then policy should be provided as [casbin adapter](https://casbin.org/docs/en/adapters) only.
0 commit comments