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

Add Authorization

This tutorial shows you how to enable authentication and authorization for your CAP application.

Overview

🎓 beginner 20 min. SAP Cloud Application Programming ModelBeginnerNode JsJavaSAP Business Technology PlatformSAP Fiori

You will learn

  • How to add CAP role restrictions to entities.
  • How to add users for local testing.
  • How to access the Incident Management application with a password.
Created by September 27, 2023
Contributors

Prerequisites

Prerequisites

You’ve added a launch page for local testing to your application. Follow the steps in the Use a Local Launch Page tutorial that is part of the Develop a Full-Stack CAP Application Following SAP BTP Developer’s Guide tutorial group.

OUT OF MAINTENANCE

This tutorial is no longer maintained. For an up-to-date version and support with any issues, refer to the Develop a Full-Stack CAP Application Following the SAP BTP Developer’s Guide mission in the SAP Discovery Center.

Steps

Step 1 Add CAP role restrictions to entities

  1. Open the srv/services.cds file.

  2. To specify restrictions, add the annotate ProcessorService with @(requires: 'support'); and the annotate AdminService with @(requires: 'admin'); lines to the srv/services.cds file:

    CDS
    using { sap.capire.incidents as my } from '../db/schema';
    
    /**
    * Used by support team members to process incidents
    */
    service ProcessorService  {
      ...
    }
    annotate ProcessorService.Incidents with @odata.draft.enabled; 
    annotate ProcessorService with @(requires: 'support');
    
    service AdminService {
      ...
    }
    annotate AdminService with @(requires: 'admin');

With these changes, users with the support role can view and change the incidents and customers, while users with the admin role can perform admin activities such as auditing logs.

Step 2 Add users for local testing
+
Step 3 Access the Incident Management application with a password
+

Resources

Discussion

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

Submit detailed feedback Discuss in Community
Steps
Step 1 of 3
1. Add CAP role restrictions to entities 2. Add users for local testing 3. Access the Incident Management application with a password

Learn more →