SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Secure Your Application on SAP Business Technology Platform Cloud Foundry

Protect your Java-based Hello World microservice with authenticated and authorized users.

Overview

🎓 intermediate 50 min. SAP Cloud SdkIntermediateSAP S 4hanaSAP Business Technology PlatformJava

You will learn

  • โœ”How to set up and configure the App Router component as a central entry point to your microservice landscape to handle authentication and authorization
  • โœ”How to protect your Java microservice so that it only accepts requests based on a valid JSON Web Token (JWT) that is received from the App Router
  • โœ”Assign roles and scopes to your application users and let your backend deal with authorization information
Unknown U Unknown May 15, 2025
Created by May 3, 2019
Contributors

Prerequisites

Prerequisites

Steps

Step 1 Concepts
โ€”

Before diving deeper into the real setup of the architecture, let’s quickly review the architecture this tutorial intends to go for.

Figure 1 presents the final setup. First, there still is your existing “Hello World” or “Business Partner” Java-based microservice that you have created in the previous tutorials. However, instead of letting the customer access this application directly, you will use the so-called Application Router (App Router) that serves two purposes.

On the one hand, the App Router is a general entry point into the world of microservices. The main idea is that you can split an application into multiple microservices with independent deployability, polyglot runtimes & persistence, and independent teams. Therefore, a central entry component is required that hides the complexity of the microservice landscape from the end customer.

On the other hand, the App Router is mainly responsible for managing authentication flows. The App Router takes incoming, unauthenticated requests from users and initiates an OAuth2 flow with the Extended Services for User Account and Authentication (XSUAA). The XSUAA service is an SAP-specific extension of CloudFoundry's UAA service to deal with authentication and authorization (it may again delegate this aspect to other providers such as external Identity Providers, see later in this tutorial). If the user authenticates at the XSUAA, it will respond with a JSON Web Token (JWT) containing the authenticated users as well as all scopes that he or she has been granted.

Authentication Flow during Runtime
Authentication Flow during Runtime
Figure 1: Authentication Flow during Runtime

The JWT is passed by the App Router to the underlying microservices so that they are freed up from this task. At the same time, these microservices can only be accessed with a valid JWT, hence, are protected from unauthenticated traffic.

The JWT contains a signature that needs to be verifiable by every microservice to establish trust. Hence, every service requires a key (client-secrets or public keys) to verify this signature and reject any requests with non-valid JWTs. Therefore, every service has to maintain a service binding to the XSUAA that provides this information for runtime verification (Figure 2). To enable this, every microservice binds to a dedicated XSUAA instance which writes this information into the VCAP_SERVICES environment variable which the microservices can use to verify any token’s validity.

Provisioning view with XSUAA binding
Provisioning view with XSUAA binding

Figure 2: Provisioning view with XSUAA binding

With these basics in mind, let’s create the picture of Figure 1 and Figure 2 by setting up the App Router, XSUAA and backend microservices to enable full application security.

Step 2 Set up the App Router
+
Step 3 Understanding the AppRouter's `manifest.yml`
+
Step 4 Bind the XSUAA Service
+
Step 5 Protect your backend microservice
+
Step 6 Assign users to scopes
+
Step 7 Deploy and test the application
+
Step 8 Understanding Roles, Role Collections and Scopes
+
Step 9 Troubleshoot JSON Web Tokens
+
Step 10 Troubleshoot OAuth scopes from XSUAA
+
Step 11 Test yourself
+
Step 12 Test yourself
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 12
1. Concepts 2. Set up the App Router 3. Understanding the AppRouter's `manifest.yml` 4. Bind the XSUAA Service 5. Protect your backend microservice 6. Assign users to scopes 7. Deploy and test the application 8. Understanding Roles, Role Collections and Scopes 9. Troubleshoot JSON Web Tokens 10. Troubleshoot OAuth scopes from XSUAA 11. Test yourself 12. Test yourself

Learn more →