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
@@ -196,7 +196,7 @@ The interaction between the CAP application and AMS (via plugin) is as follows:
196
196
3. CAP performs the authorization on the basis of the CDS authorization model and the injected user claims.
197
197
198
198
199
-
### Adding AMS Support
199
+
### Adding AMS Support { .java }
200
200
201
201
**AMS is transparent to CAP application code** and can be easily consumed via plugin dependency.
202
202
@@ -303,6 +303,49 @@ In general, AMS provides highly flexible APIs to define and enforce authorizatio
303
303
**In the context of CAP projects, only a limited subset of these APIs is relevant and is offered in a streamlined way via the CAP integration plugins**.
304
304
:::
305
305
306
+
### Adding AMS Support { .node }
307
+
308
+
**AMS is transparent to CAP application code** and can be easily consumed via plugin dependency.
309
+
310
+
To enhance your project with AMS, you can make use of CDS CLI tooling:
311
+
312
+
```sh
313
+
cds add ams
314
+
```
315
+
316
+
This automatically adds required configuration for AMS, taking into account the concrete application context (tenant mode and runtime environment etc.).
317
+
If required, it also runs the new `cds add ias` command to configure the project for IAS authentication.
318
+
319
+
::: details See dependencies added
320
+
321
+
```json [package.json]
322
+
{
323
+
"dependencies": [
324
+
"@sap/ams": "^3",
325
+
"@sap/xssec": "^4"
326
+
],
327
+
"devDependencies": [
328
+
"@sap/ams-dev": "^2"
329
+
}
330
+
```
331
+
:::
332
+
333
+
`@sap/ams` integrates into the CAP framework to handle incoming requests.
334
+
Based on the user's assigned [policies](#policies), the user's roles are determined to decorate the [user.is](/node.js/authentication#user-is) function with additional roles.
335
+
The framework then authorizes the request as usual based on the user's roles.
336
+
337
+
For local development, `@sap/ams-dev` needs to compile the DCL files to Data Control Notation (DCN) files in `gen/dcn` which is the machine-readable version of DCL that is required by AMS at runtime.
- Validate `ams.attributes` annotations for type coherence against the AMS schema.
342
+
- Generate policies from the CDS model during the build using a [custom build task](../deployment/custom-builds#custom-build-plugins).
343
+
- Generate a deployer application during the build to upload the Data Control Language (DCL) base policies.
344
+
345
+
::: tip
346
+
In general, AMS provides highly flexible APIs to define and enforce authorization rules at runtime suitable for native Cloud applications.
347
+
**In the context of CAP projects, only a limited subset of these APIs is relevant and is offered in a streamlined way via the CAP integration plugins**.
348
+
:::
306
349
307
350
### Prepare CDS Model
308
351
@@ -406,6 +449,8 @@ AMS policies represent the business-level roles of end users interacting with th
406
449
Often, they reflect real-world jobs or functions.
407
450
:::
408
451
452
+
<divclass="impl java">
453
+
409
454
After the application is built, check the *srv/src/main/resources/ams* folder to see the generated AMS *schema* and a *basePolicies* DCL file in a package called *cap*:
410
455
411
456
::: code-group
@@ -419,6 +464,23 @@ After the application is built, check the *srv/src/main/resources/ams* folder to
419
464
420
465
:::
421
466
467
+
</div>
468
+
469
+
<divclass="impl node">
470
+
After the application is built, check the *ams/dcl* folder to see the generated AMS *schema* and a *basePolicies* DCL file in a package called *cap*:
471
+
472
+
::: code-group
473
+
474
+
```[./ams]
475
+
└─ dcl
476
+
├─ cap
477
+
│ └─ basePolicies.dcl
478
+
└─ schema.dcl
479
+
```
480
+
481
+
:::
482
+
</div>
483
+
422
484
[Learn more about policy generation](https://sap.github.io/cloud-identity-developer-guide/CAP/cds-Plugin.html#dcl-generation){.learn-more}
423
485
424
486
@@ -490,20 +552,23 @@ cds:
490
552
491
553
<div class="impl node">
492
554
493
-
```json
555
+
```json [package.json]
494
556
{
495
557
"cds": {
496
558
"requires": {
497
559
"auth": {
498
560
"[development]": {
499
561
"kind": "mocked",
500
562
"users": {
501
-
"content-manager": {
502
-
"policies": ["cap.ContentManager"]
563
+
"content-manager": { // [!code ++:5]
564
+
"policies": [
565
+
"cap.ContentManager"
566
+
]
503
567
},
504
-
"stock-manager": {
505
-
"policies": ["cap.StockManager"]
506
-
}
568
+
"stock-manager": { // [!code ++:5]
569
+
"policies": [
570
+
"cap.StockManager"
571
+
]
507
572
}
508
573
}
509
574
}
@@ -581,19 +646,21 @@ You can verify in the UI that mock user `stock-manager-fiction` is restricted to
581
646
<div class="impl node">
582
647
583
648
::: tip
584
-
Don't miss to add the policy files in sub folders of `ams` reflecting the namespace properly: Policy `local.StockManagerFiction` is expected to be in a file within directory `/ams/dcl/local/`.
649
+
Don't miss to add the policy files in sub folders of `ams/dcl` reflecting the namespace properly: Policy `local.StockManagerFiction` is expected to be in a file within directory `./ams/dcl/local/`.
585
650
:::
586
651
587
-
```json
652
+
```json [package.json]
588
653
{
589
654
"cds": {
590
655
"requires": {
591
656
"auth": {
592
657
"[development]": {
593
658
"kind": "mocked",
594
659
"users": {
595
-
"stock-manager-fiction": {
596
-
"policies": ["local.StockManagerFiction"]
660
+
"stock-manager-fiction": { // [!code ++:5]
661
+
"policies": [
662
+
"local.StockManagerFiction"
663
+
]
597
664
}
598
665
}
599
666
}
@@ -616,13 +683,15 @@ Policies can be automatically deployed to the AMS server during deployment of th
616
683
617
684
Enhancing the project with by `cds add ams` automatically adds task e.g. in the MTA for AMS policy deyployment.
@@ -658,6 +727,54 @@ Note that the policy deployer task requires a path to a directory structure cont
658
727
By default, the path points to `srv/src/gen/policies` which is prepared automatically during build step with the appropriate policy-content copied from `srv/src/main/resources/ams`.
659
728
In addition, `@sap/ams` needs to be referenced to add the deployer logic.
Note that the policy deployer task requires a path to a directory structure containing the `ams/dcl` root folder with the policies to be deployed.
773
+
By default, the path points to `gen/policies` which is prepared automatically during build step with the appropriate policy-content copied from `ams/dcl`.
774
+
In addition, `@sap/ams` needs to be referenced to add the deployer logic.
775
+
776
+
<div>
777
+
661
778
::: tip
662
779
Several microservices sharing the same IAS instance need a common folder structure the deployer task operates on.
663
780
It contains the common view of policies applied to all services.
@@ -1546,10 +1663,35 @@ During development, it might be useful to activate logger `com.sap.cds.security.
1546
1663
}
1547
1664
```
1548
1665
1549
-
This makes the runtime tracing user information of authenticated users to the application log like this:
1666
+
You can verify a valid configfuration of the AMS plugin by the following log output:
0 commit comments