BTP CAP Part 3: Securing CAP Services with XSUAA Role-Based Authorization
Preview · a free account unlocks the full lesson
Secure CAP declaratively: @requires and @restrict annotations for roles and instance-based conditions, generating xs-security. json with cds compile, mocked users for local testing, XSUAA in production, and testing authorization in hybrid mode.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Part 2 built CAP services; this part covers securing them with XSUAA-based, role-based authorization. The @requires annotation restricts an entire service or entity to specific roles, such as 'authenticated-user' or 'Admin'. The @restrict annotation goes further, defining exactly which grants apply per event — READ, WRITE, a custom action — and can add instance-level conditions through a where clause.
Locally, mocked users defined in package.json simulate roles during development, while in production those same roles come from real XSUAA tokens. Running cds add xsuaa, or cds compile, generates the xs-security.json file directly from these annotations, so the authorization model and the security configuration stay in sync automatically.
Create a free account to keep reading
You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.
- Full explanation
- Code example
- Real project scenario
- Common mistakes
- Best practices
- Interview angle
One tap with Google works too. Every topic keeps its first lesson open to everyone.
Keep exploring
Interview questions on this topic
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.