Configure authentication and authorization for applications.
Outcomes
Configure different RH-SSO clients for the OpenID Connect (OIDC) Authorization Code Flow.
Describe the content of different OIDC tokens.
Create and manage users and roles in RH-SSO.
Create groups of users and assign roles by using groups.
Configure authentication options.
Configure password policies for the users.
Configure required actions for log in.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
[student@workstation ~]$ lab start auth-review
Procedure 3.4. Instructions
In this exercise you configure your RH-SSO realm to enhance the security of the authentication of the users. Then, you create two clients, and configure the realm with the roles required by the applications.
The finance-webapp application is a server-side web application that uses the OpenID Connect authorization code flow as a confidential client to authenticate the application users.
The application uses the Java Quarkus framework, and the Quarkus integration with OpenID Connect identity servers.
The finance-webapp application calls an external endpoint in the marketing-restful-api application.
The marketing-restful-api application is a Node.js back end service which serves REST endpoints.
It uses the OpenID Connect authorization code flow as a bearer-only client.
Thus, the application cannot initiate the login process, but RH-SSO can generate the access token for this client.
The marketing-restful-api application uses the Node.js adapter from RH-SSO to integrate with the authentication server.
The finance-webapp and marketing-restful-api applications perform access control by using two RH-SSO realm roles.
The following table shows the relationship between the roles and the application endpoints.
Table 3.8. Roles and Endpoints
| Role | Application | Endpoint |
|---|---|---|
| None (only authenticated) | finance-webapp |
http://localhost:8080/finance/showtokens
|
| finance-user | finance-webapp |
http://localhost:8080/finance/showinvoices
|
| marketing-user | marketing-restful-api |
http://localhost:3000/campaign/list
|
Prepare the RH-SSO rhtraining realm to allow user registration.
Log in to the RH-SSO Admin Console.
On the workstation machine, use Firefox to navigate to the Red Hat Single Sign-On web UI URL at https://sso.lab.example.com:8080.
Click .
Log in as the admin user with redhat as the password.
By default, the main page shows the menu for the rhtraining realm.
Activate user registration.
From within the → menu, click .
Then, set the button to ON.
Click .
Enhance password security by forcing all the users to have a password with a minimum length of 10 characters, and at least 1 special character.
In the RH-SSO Admin Console, click → .
Then, click .
Add password policies to the rhtraining realm.
In the drop down button, select the following list of password policies.
You must add the policies one by one.
Modify the Policy Value field to 10 for the Minimum Length policy.
Special Characters
Minimum Length (10)
After adding all the password policies, click .
Create a client for the Quarkus finance-webapp in the rhtraining realm.
The new client must allow only the OpenID Connect authorization code flow (standard flow) as a confidential client. Create the client based on the following criteria.
| Field | Value |
|---|---|
Client ID
|
finance-webapp
|
Client Protocol
|
openid-connect
|
Root URL
|
http://localhost:8080/finance
|
Navigate to realm, and then click → . Then, click .
Create the client based on the criteria from the previous table.
Click .
On the page that opens, set Direct Access Grants Enabled to OFF, and select confidential in the Access Type field.

Scroll down and click .
Navigate to the tab, and take note of the secret value.

Inspect the ID and access tokens emitted for the alice user and the finance-webapp client from the RH-SSO Admin Console.
Create a client for the marketing-restful-api services applications in the rhtraining realm.
The new client must allow only the OpenID Connect authorization code flow (standard flow) as a bearer-only client. Create the client based on the following criteria.
Table 3.9. Marketing Restful API client creation
| Field | Value |
|---|---|
Client ID
|
marketing-restful-api
|
Client Protocol
|
openid-connect
|
Root URL
|
http://localhost:3000/campaign
|
Navigate to the realm, and then click → .
Then, click .
Create the client based on the criteria from the previous table.
Click .
On the page that opens, select bearer-only in the Access Type field.
Scroll down and click .
Try to inspect the tokens for the marketing-restful-api client.
The marketing-restful-api client is a bearer-only client.
Thus, the client cannot start a login flow, and in the RH-SSO Admin Console there is no tab.
Run the finance-webapp application.
The application is in the ~/DO313/labs/auth-review/finance-webapp directory, and it is started with the mvn quarkus:dev command.
Open the terminal application on the workstation machine and change to the ~/DO313/labs/auth-review/finance-webapp directory.
[student@workstation ~]$ cd ~/DO313/labs/auth-review/finance-webappModify the finance-webapp/src/main/resources/application.properties configuration file, to include the client secret you noted in a previous step.
quarkus.oidc.auth-server-url=https://sso.lab.example.com:8080/auth/realms/rhtraining
quarkus.oidc.application-type=web-app
#For web-app type applications, Quarkus needs to read the roles from access token, instead of the idToken:
quarkus.oidc.roles.source=accesstoken
quarkus.oidc.client-id=finance-webapp
quarkus.oidc.credentials.secret=passw0rd
...output omitted...From the terminal, compile and run the application.
[student@workstation finance-webapp]$ mvn quarkus:dev
...output omitted...
2022-12-15 07:41:26,210 INFO [io.quarkus] (Quarkus Main Thread) finance-webapp 1.0.0-SNAPSHOT on JVM (powered by Quarkus 2.14.2.Final) started in 3.001s. Listening on: http://localhost:8080
2022-12-15 07:41:26,211 INFO [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2022-12-15 07:41:26,211 INFO [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, oidc, oidc-client, oidc-token-propagation, qute, reactive-routes, rest-client, rest-client-jackson, resteasy, resteasy-qute, security, servlet, smallrye-context-propagation, smallrye-jwt, vertx]
--
Tests paused
Press [r] to resume testing, [o] Toggle test output, [:] for the terminal, [h] for more options>The application can take some minutes downloading dependencies.
Leave the terminal open.
Run the marketing-restful-api application.
The application is in the ~/DO313/labs/auth-review/marketing-restful-api directory, and it is started with the npm install && npm run start commands.
Open a new terminal application on the workstation machine, and change to the ~/DO313/labs/auth-review/marketing-restful-api directory.
[student@workstation ~]$ cd ~/DO313/labs/auth-review/marketing-restful-apiFrom the terminal, install dependencies and run the application.
[student@workstation marketing-restful-api]$ npm install && npm run start
...oupout omitted...
> marketing-restful-api@0.0.1 start /home/student/DO313/labs/auth-review/marketing-restful-api
> node app.js
Started at port 3000The application can take some minutes downloading dependencies.
Leave the terminal open.
Register a new bob user from the finance-webapp client.
The application is at http://localhost:8080/finance.
Register the new bob user based on the following criteria:
| Field | Value |
|---|---|
First name
|
Bob
|
Last name
|
Liddle
|
Email
|
bob@example.com
|
Username
|
bob
|
Password
|
bob
|
Confirm Password
|
bob
|
Try to use the following passwords:
BobBob@
BobBobBob@
Then, try to access to the link in the finance-webapp application.
Open a new Firefox private window and navigate to the finance web application at http://localhost:8080/finance.
Click .
In the rhtraining realm login page click .
Register the bob user based on the criteria from the previous table.
Click . The RH-SSO login page does not allow that password.
Only the BobBobBob@ password is accepted.
In the finance-webapp application, click to access the list of campaigns.
The bob user cannot see the list of campaigns because the user is not in the marketing-user role.
Create the marketing-user role to access the marketing-restful-api application, and configure it as a default role for all new users.
Delete the existing alice user and register a new alice user.
Then, use the Chromium Web Browser to test the access to the /finance/showcampaigns/list endpoint at the External API link within the finance-webapp application.
Register the new alice user based on the following criteria:
| Field | Value |
|---|---|
First name
|
Alice
|
Last name
|
Liddle
|
Email
|
alice@example.com
|
Username
|
alice
|
Password
|
AliceAlice@
|
Confirm Password
|
AliceAlice@
|
From within the → menu, click .
Then, in the alice user row, click .
Confirm the action by clicking .
Open a new Chromium Web Browser window and navigate to the finance web application at http://localhost:8080/finance.
Click .
In the rhtraining realm login page click .
Register the user based on the criteria from the previous table.
Click .
In the finance-webapp application, click to access the list of campaigns.
The alice user can see the list of campaigns because they are in the default marketing-user realm role.
In the finance-webapp application, click .
The alice user cannot see the list of invoices because they are not in the finance-user role.
Create the finance-user role to access to the finance-webapp application's list of invoices.
Create the managers group and assign the finance-user role to it.
Then, add the alice user to the group and test access to the /finance/showinvoices endpoint.
From the RH-SSO Admin Console, navigate to the realm, and then click → .
Then click .
Type managers as the group name, and click .
Click the tab.
Then, select the finance-user role in the list of available roles, and click .
Add the alice user to the managers group.
From the RH-SSO Admin Console, navigate to → . Then click .
Click in the alice users row.
Then, navigate to the tab, select the managers group, and click .
Open a new Firefox private window and navigate to the finance web application at http://localhost:8080/finance.
Click , and log in as the alice user, with AliceAlice@ as the password.
The alice user can see the list of invoices because they are in the managers group, which has the finance-user role.
Close all terminals and all the browsers windows, and change to the /home/student directory.