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
@@ -21,6 +21,10 @@ It provides three ways of integration
21
21
2.**Role based permissions** - Permissions are associated to roles and users have a specific role attached. This actually reduces redundancy in DB a lot, as most of the time, users will have many common permissions. If that is not the case for you, then, use method #1 above.
22
22
3.**Role based permissions with user level override** - This is the most flexible architecture. In this case, method #2 is implemented as is. On top of it, we also add user-level permissions override, allow/deny permissions over role permissions. So, say there is user who can perform all admin role actions except he cannot remove users from the system. So, DeleteUser permission can be denied at user level and role can be set as Admin for the user.
23
23
24
+
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:
25
+
1.**Using default casbin policy document** - Define policy document in default casbin format in the app, and configure authorise decorator to use those policies.
26
+
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.
27
+
24
28
Refer to the usage section below for details on integration
25
29
26
30
## Install
@@ -37,13 +41,21 @@ For a quick starter guide, you can refer to our [loopback 4 starter](https://git
37
41
38
42
In order to use this component into your LoopBack application, please follow below steps.
39
43
40
-
- Add component to application.
44
+
- Add component to application. Also add providers to implement casbin authorisation.
- If using method #1 from above, implement Permissions interface in User model and add permissions array.
@@ -117,6 +129,81 @@ export class User extends Entity implements UserPermissionsOverride<string> {
117
129
}
118
130
```
119
131
132
+
- Implement the **Casbin Resource value modifier provider**. Customise the resource value based on business logic using route arguments parameter in the provider.
thrownewHttpErrors.InternalServerError(`Metadata object not found`);
158
+
}
159
+
const res =metadata.resource;
160
+
161
+
// Now modify the resource parameter using on path params, as per business logic.
162
+
// Returning resource value as such for default case.
163
+
164
+
return`${res}`;
165
+
}
166
+
}
167
+
168
+
```
169
+
- 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.
- 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
permissions, // do authUser.permissions if using method #1
291
+
authUser,
292
+
resVal,
197
293
request,
198
294
);
199
295
// Checking access to route here
@@ -213,10 +309,10 @@ export class MySequence implements SequenceHandler {
213
309
The above sequence also contains user authentication using [loopback4-authentication](https://github.com/sourcefuse/loopback4-authentication) package. You can refer to the documentation for the same for more details.
214
310
215
311
- Now we can add access permission keys to the controller methods using authorize
216
-
decorator as below.
312
+
decorator as below. Set isCasbinPolicy parameter to use casbin default policy format. Default is false.
0 commit comments