Skip to content

Commit 6c020fc

Browse files
Merge branch 'sap-tutorials:master' into master
2 parents b64dbe9 + 30449a6 commit 6c020fc

11 files changed

Lines changed: 82 additions & 79 deletions

File tree

-11.8 KB
Loading
-24.3 KB
Loading

tutorials/hana-cloud-cap-add-authentication/hana-cloud-cap-add-authentication.md

Lines changed: 74 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,72 @@ The UAA will provide user identity, as well as assigned roles and user attribute
3838

3939
![Basic xs-security.json](basic_xs_security.png)
4040

41-
1. **We won't add application scopes in this tutorial**, but those can be added using the CDS syntax in your services. If you do add scopes to the services you can generate a sample xs-security.json using the following command and merge that into the basics xs-security.json file generated by the Application Router wizard.
41+
1. To really test the impact of roles in our application, lets add some security to our services. Open the `interaction_srv.cds` from the `srv` folder. Adjust the code as follows to make `Interactions_Header` service only available to authenticated users and `Interactions_Items` only available to users with the `Admin` role and restrict the results during read operations to only those records where the language column has the value of German (DE).
42+
43+
```cap cds
44+
using app.interactions from '../db/interactions';
45+
service CatalogService {
46+
47+
@requires: 'authenticated-user'
48+
entity Interactions_Header
49+
as projection on interactions.Interactions_Header;
50+
51+
@requires: 'Admin'
52+
@restrict: [{ grant: 'READ', where: 'LANGU = ''DE'''}]
53+
entity Interactions_Items
54+
as projection on interactions.Interactions_Items;
55+
56+
}
57+
```
58+
59+
1. When you do add scopes to the services as we did in the previous step you can generate a sample `xs-security.json` using the following command and merge that into the basics `xs-security.json` file generated by the Application Router wizard.
4260
4361
```shell
44-
cds compile srv/ --to xsuaa
62+
cds compile srv/ --to xsuaa > xs-security.json
4563
```
4664
47-
1. Since we want to test the security setup from the Business Application Studio, we are going to have add some additional configuration to the xs-security.json. You need to add another property to the xs-security.json to configure which redirect URIs are allowed. Also while editing, add an `xsappname` with the value `myhanaapp` and a `tenant-mode` of `dedicated` as well
65+
![Updated xs-security.json](updated_xs_security.png)
66+
67+
1. Since we want to test the security setup from the Business Application Studio, we are going to have add some additional configuration to the `xs-security.json`. You need to add another property to the `xs-security.json` to configure which redirect URIs are allowed by the `OAuth` configuration. Also while editing, add an `xsappname` with the value `myhanaapp` and a `tenant-mode` of `dedicated` as well. We can also add `credential-types` as a security best practice. You can read more about the [Credential Types in this blog post](https://blogs.sap.com/2022/07/05/why-developers-should-care-about-credential-types-for-xsuaa/) by [`Dinu PAVITHRAN`](https://people.sap.com/dinu.pavithran)
4868
4969
```json
5070
{
51-
"xsappname": "myhanaapp",
52-
"tenant-mode": "dedicated",
53-
"scopes": [],
54-
"attributes": [],
55-
"role-templates": [],
56-
"oauth2-configuration": {
57-
"redirect-uris": [
58-
"https://*.applicationstudio.cloud.sap/**"
59-
]
71+
"xsappname": "myhanaapp",
72+
"tenant-mode": "dedicated",
73+
"scopes": [
74+
{
75+
"name": "$XSAPPNAME.Admin",
76+
"description": "Admin"
77+
}
78+
],
79+
"attributes": [],
80+
"role-templates": [
81+
{
82+
"name": "Admin",
83+
"description": "generated",
84+
"scope-references": [
85+
"$XSAPPNAME.Admin"
86+
],
87+
"attribute-references": []
6088
}
89+
],
90+
"oauth2-configuration": {
91+
"credential-types": [
92+
"binding-secret",
93+
"x509"
94+
],
95+
"redirect-uris": [
96+
"https://*.applicationstudio.cloud.sap/**"
97+
]
98+
}
6199
}
62100
```
63101
64102
![oauth2-configuration in the xs-security.json](oauth2_config.png)
65103
66104
This wild card will allow testing from the Application Studio by telling the XSUAA it should allow authentication requests from this URL. See section [Application Security Descriptor Configuration Syntax](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/517895a9612241259d6941dbf9ad81cb.html) for more details on configuration options.
67105
68-
1. Open a terminal and create the XSUAA services instance with the xs-security.json configuration using the following command:
106+
1. Open a terminal and create the XSUAA services instance with the `xs-security.json` configuration using the following command:
69107
70108
```shell
71109
cf create-service xsuaa application MyHANAApp-auth -c xs-security.json
@@ -75,57 +113,16 @@ The UAA will provide user identity, as well as assigned roles and user attribute
75113
76114
### Configure the application
77115
78-
1. In the previous tutorial, the application router wizard created a `default-env.json` file in the root of the project, to configure the connection to the service instance when running locally for testing. We will now extend that same file to do the same for the XSUAA instance we just created in the previous step.
79-
80-
1. Open the default-env.json and add an `xsuaa` section with a placeholder for the credentials which we will fill soon:
81-
82-
```json
83-
"VCAP_SERVICES":{
84-
"xsuaa": [{
85-
"name": "MyHANAApp-auth",
86-
"label": "xsuaa",
87-
"tags": ["xsuaa"],
88-
"credentials": {
89-
...
90-
}
91-
}]
92-
```
93-
94-
![default-env.json xsuaa placeholder](xsuaa_placeholder.png)
95-
96116
1. From the terminal, we need to create a service key. This will give us access to the credentials for your XSUAA instance.
97117
98118
```shell
99-
cf create-service-key MyHANAApp-auth default
100-
cf service-key MyHANAApp-auth default
119+
cf create-service-key MyHANAApp-auth default
101120
```
102121
103-
![Create service key](create_service_key.png)
104-
105-
1. Copy the output of the service-key command and paste it into the credentials section of the default-env.json file.
106-
107-
![Paste Service Key details](paste_service_key.png)
108-
109-
It should look something like this:
110-
111-
![Example default-env.json with Service Key Details](example_default_env.png)
112-
113122
1. Change back to the root of your project in the terminal and issue the command `cds bind -2 MyHANAApp-auth:default`. This is the same command that we used to bind our running CAP application to HANA DB earlier. Now we are adding a binding to the security XSUAA service as well.
114123
115124
![CDS Bind](cds_bind.png)
116125
117-
1. Open the `srv/interaction_srv.cds` file. You need to add `@requires: 'authenticated-user'` to the service definition. Authentication and scopes can also be applied at the individual entity level.
118-
119-
![Add Authentication to CDS Service](cds_auth.png)
120-
121-
1. Finally we are going to need some additional Node.js modules for CAP to process the authentication. We can both add them to the package.json dependencies and install them all in one step from the terminal.
122-
123-
```shell
124-
npm install -save passport @sap/xssec @sap/xsenv @sap/audit-logging
125-
```
126-
127-
![Add Node.js dependencies](node_dependencies.png)
128-
129126
### Create and grant roles for application
130127
131128
1. Before we can test our application, we need to create a role that includes the XSUAA instance details and grant to that our user. We will do this from the SAP Business Technology Platform cockpit. In the cockpit, you set up the roles and role collections and assign the role collections to your users. This brings the necessary authorization information into the JWT token when the user logs on to your application through XSUAA and Application Router.
@@ -150,30 +147,34 @@ The UAA will provide user identity, as well as assigned roles and user attribute
150147
151148
1. The `approuter` component implements the necessary handshake with XSUAA to let the user log in interactively. The resulting JWT token is sent to the application where it's used to enforce authorization.
152149
153-
1. Next open the xs-app.json file in the /app folder. Here want to make several adjustments. Change the `authenicationMethod` to `route`. This will turn on authentication. You can deactivate it later by switching back to `none`. Also add/update the routes. We are adding authentication to CAP service route. We are also adding the Application Router User API route (which is nice for testing the UAA connection). Finally add the route to the local directory to serve the UI5/Fiori web content.
150+
1. Next open the xs-app.json file in the /app folder. Here want to make several adjustments. Change the `authenicationMethod` to `route`. This will turn on authentication. You can deactivate it later by switching back to `none`. Also add/update the routes. We are adding authentication to CAP service route. We are also adding the Application Router User API route (`sap-approuter-userapi`), which is nice for testing the UAA connection. We will also add the custom `logoutEndpoint` of `/app-logout`. You can add this path to your URL if you want to force logout your user; which can be helpful to pickup any changes to your role configuration during development. Finally add the route to the local directory to serve the UI5/Fiori web content.
154151
155152
```json
156-
{
153+
{
157154
"authenticationMethod": "route",
155+
"logout": {
156+
"logoutEndpoint": "/app-logout",
157+
"logoutPage": "/"
158+
},
158159
"routes": [
159160
{
160-
"source": "^/app/(.*)$",
161-
"target": "$1",
162-
"localDir": ".",
163-
"cacheControl": "no-cache, no-store, must-revalidate",
164-
"authenticationType": "xsuaa"
161+
"source": "^/app/(.*)$",
162+
"target": "$1",
163+
"localDir": ".",
164+
"cacheControl": "no-cache, no-store, must-revalidate",
165+
"authenticationType": "xsuaa"
165166
},
166167
{
167-
"source": "^/user-api(.*)",
168-
"target": "$1",
169-
"service": "sap-approuter-userapi"
168+
"source": "^/user-api(.*)",
169+
"target": "$1",
170+
"service": "sap-approuter-userapi"
170171
},
171172
{
172-
"source": "^/(.*)$",
173-
"target": "$1",
174-
"destination": "srv-api",
175-
"csrfProtection": true,
176-
"authenticationType": "xsuaa"
173+
"source": "^/(.*)$",
174+
"target": "$1",
175+
"destination": "srv-api",
176+
"csrfProtection": true,
177+
"authenticationType": "xsuaa"
177178
}
178179
]
179180
}
@@ -187,19 +188,19 @@ The UAA will provide user identity, as well as assigned roles and user attribute
187188
188189
This means your security setup is working. Accessing the CAP service directly will always produce an error now as there is no authentication token present. We need to run via the Application Router to generate and forward the authentication token.
189190
190-
1. Without stopping the CAP service, open a second terminal. In this terminal change to the `/app` folder and then run `npm start` to start the Application Router.
191+
1. Without stopping the CAP service, open a second terminal. In this terminal run `cds bind --exec -- npm start --prefix app` to start the Application Router but using the `cds bind` command to inject all the `UAA` configuration into the Application Router automatically and securely as well.
191192
192193
![Run Application Router](run_app_router.png)
193194
194195
1. Open the application router in a new tab. Click on the `Interactions_Header`. Now instead of the Unauthorized error you received when testing CAP service directly, you should see the data returned normally.
195196
196197
![CAP Service successful](cap_successful.png)
197198
198-
1. Finally change the ULR path to `/interaction_items/webapp/index.html`. You are now testing the Fiori free style application from the previous tutorial with data from the CAP service but all with authentication.
199+
1. Finally change the ULR path to `/interaction_items/webapp/index.html`. You are now testing the Fiori free style application from the previous tutorial with data from the CAP service but all with authentication. You should also only be seeing a single record thanks to the data restriction we placed on the service as well.
199200
200201
![Fiori with authentication](fiori_with_authentication.png)
201202
202-
1. Add /user-api/attributes to the end of the URL and you should see your Email and other User details. This is testing that the application router is actually getting the security token from the UAA instance.
203+
1. Add `/user-api/attributes` to the end of the URL and you should see your Email and other User details. This is testing that the application router is actually getting the security token from the UAA instance.
203204
204205
![test auth details](user_attributes.png)
205206
9.2 KB
Loading
-18.6 KB
Loading
35.9 KB
Loading
53.8 KB
Loading
6.87 KB
Loading

tutorials/hana-cloud-cap-calc-view/hana-cloud-cap-calc-view.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ parser: v2
99

1010
# Create Calculation View and Expose via CAP (SAP HANA Cloud)
1111

12-
<!-- description -->Learn how to combine HANA native artifacts, like calculation views, with SAP Cloud Application Programming Model (CAP).
12+
<!-- description -->Learn how to combine HANA native artifacts, like calculation views, with SAP Cloud Application Programming Model (CAP)
1313

1414
## You will learn
1515

tutorials/hana-cloud-cap-create-database-cds/hana-cloud-cap-create-database-cds.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ The SAP Cloud Application Programming model utilizes core data services to defin
4646
4747
1. Use the following content in this new file:
4848
49-
```CDS
49+
```CAP CDS
5050
namespace app.interactions;
5151
5252
using { Country } from '@sap/cds/common';
@@ -89,7 +89,7 @@ The SAP Cloud Application Programming model utilizes core data services to defin
8989
9090
1. Use the following content in this new file:
9191
92-
```CDS
92+
```CAP CDS
9393
9494
using app.interactions from '../db/interactions';
9595
service CatalogService {
@@ -213,7 +213,7 @@ You can now check the generated tables and views in the Database Explorer.
213213
1. Note the name of the table matches the generated `hdbtable` artifacts. You will also see the physical schema managed by the HDI container.
214214
215215
> Unless a name is specified during deployment, HDI containers are automatically created with names relative to the project and user generating them. This allows developers to work on different versions of the same HDI container at the same time.
216-
> !![Build database module](8.png)
216+
> ![Build database module](8.png)
217217
218218
### Load data into your tables
219219

0 commit comments

Comments
 (0)