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
+84
Original file line number
Diff line number
Diff line change
@@ -421,3 +421,87 @@ List<NexusUserJpa> g = query.getN(22);
421
421
NexusUserJpa h = query.getSingle();
422
422
```
423
423
424
+
#### Tenant Capability
425
+
426
+
The system allows to save different tennants within the same tables, in order to ease development.
427
+
428
+
This is done on a per-DAO basis (per -table so to say), as there has to be a separate table holding permission-data regarding the tenant-IDs and corresponding reference-IDs.
429
+
430
+
```bash
431
+
--- Person
432
+
id (Long)
433
+
name (String)
434
+
435
+
--- Person_Permission
436
+
id (Long)
437
+
referenceId (Long)
438
+
tenantId (Long)
439
+
440
+
----------------------------------------
441
+
--- Person
442
+
1 Peter
443
+
2 Paul
444
+
3 Mary
445
+
446
+
--- Person_Permission
447
+
1 1 1
448
+
2 2 1
449
+
2 3 2
450
+
```
451
+
452
+
When a user having tenantId=1 associated will query the full list of Persons, he will inevitably receive 'Peter and Paul', whereas another user associated with tennantId=2 would receive 'Mary'.
453
+
454
+
##### Data-Side
455
+
456
+
To enable this feature, you have to generate a special DAO that is linked to the corresponding permissions-DAO by specifying the JPA-type of the permission-DAO and both the name of the reference-ID and tenant-ID field (all that is explained in the constructor of the DAO).
457
+
458
+
So you have to create the appropriate permission-table, a permission-JPA for the table.
459
+
460
+
##### User-Side
461
+
462
+
In order to query those tables accordingly, your querying user has to be associated with a tenant-ID.
463
+
464
+
In fact there are TWO associations with multiple tenant-IDs there.
465
+
The `tenant_read` set, used to determine if a user can see (and therefore modify or delete) a row, and the `tenant_write` set, used to determine how many and which permission-rows there are to write when creating a new row in the main-table.
466
+
467
+
###### Setting permissions in the DAO
468
+
469
+
On the DAO-level (if you do DB stuff on the server) you may specify those freely using the according setters in the query-builders of the DAO. When using the DAO you will only have to specify a single set of tenant-IDs since you know how you're planning on using those yourself (if you will create a row, then the tenant-ID set is equivalent to the `tenant_write`set; if you will only query, then specify a tenant-ID set equivalent to the `tenant_read`set).
470
+
471
+
###### Setting permissions via KeyCloak
472
+
473
+
In KeyCloak you have to specify both sets per user and the system will pick the appropriate set when manipulating or querying the database.
474
+
475
+
This is done by settings User-Attributes.
476
+
477
+
```bash
478
+
User: Psilo / Attributes
479
+
-- tenant_read: 1,3
480
+
-- tenant_write: 1
481
+
```
482
+
483
+
On KeyCloak-Setup, be advised that you have to specify an Attribute-Mapper for both attributes (`Clients-><ClientName>->Mappers, create with name=tenants_read/tenants_write, User Attribute=<name>, Token Claim Name=<name>, Claim JSON Type=String`).
484
+
485
+
That set up, the Attribute values will be passed on into the JWT token and parsed by Http-Server (the data will be copied to the Context.Attribute Object fromwhere you may retrieve them at any time during a request).
486
+
The system will decide automatically which set to use, so that in this example the user `Psilo` will be able to see rows that have the permission for tenant-ID 1or3, but when creating a row, it will only write a permission for tenant-ID 1.
487
+
488
+
##### Example
489
+
490
+
```java
491
+
// Passing the TestPermissionJpa class enables the tenant-capability.
492
+
// The TestPermissionJpa has a getReferenceId() and getTenantId() method
0 commit comments