Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Ravikumar_H
Discoverer

Introduction:

Authorization refers to controlling access to resources and operations within an OData service. OData is a protocol that standardizes the way data is exposed and consumed over the web, typically using RESTful APIs.

OData(Open Data Protocol) is a widely adopted standard for building and consuming RESTful APIs. It simplifies data sharing across disparate systems, making it easier for developers to expose and consume data in a standardized manner. However, with great power comes great responsibility, and securing OData services is paramount to protect sensitive information. In this blog post, we'll delve into the intricacies of authorization in OData and explore best practices for securing your OData services.

Role-based authorization is a common practice in securing OData services. Assigning specific roles to users and granting permissions based on these roles helps control access to different resources. This approach ensures that users only have the necessary privileges required for their tasks.

Authentication vs. Authorization

Before delving into OData authorization, it's crucial to distinguish between authentication and authorization:

Authentication: Verifying the identity of users or systems making requests. Common methods include OAuth, API keys, or username/password.

Authorization: Determining the actions and data access permissions granted to authenticated users or systems.

Here I am creating a Odata project in Tcode SEGW by providing Project name and Description.

ravi_kumar_0-1706700294884.png

 Import the Database table to the project by following the below steps

ravi_kumar_1-1706700294894.png

  Provide the name of Database table in ABAP Structure.

ravi_kumar_2-1706700294898.png

  Here Check out the Required fields for your Requirement and Click on Next.

ravi_kumar_3-1706700294903.png

  Here Check on the Key fields present in the Table and click on finish.

ravi_kumar_4-1706700294907.png

 

ravi_kumar_5-1706700294922.png

Then Generate the OData Service, After Generating Components and methods will get Generated.

ravi_kumar_6-1706700294928.png

  Here in Get Entityset I'm writing select Query to fetch the data.

ravi_kumar_7-1706700294932.png

 

To Provide Authorization to OData we need to follow below Steps.

Step 1: Go to Tcode :- SU20, Create Authorization field as shown below

ravi_kumar_8-1706700294935.png

Then Create Authorization Object in Tcode SU21 and Assign Authorization field to the Authorization Object.

ravi_kumar_9-1706700294939.png

Step 2: Create authorization for the role Tcode : PFCG

we'll see how to Provide Authorization to ODATA by Assigning roles.

Go to Tcode : PFCG and Provide Role and Description.

Then  Select the Role as per your Requirement, Here i am Selecting Single Role.

ravi_kumar_10-1706700294942.png

After selecting Single Role New Page will get displayed, Here click On Menu Tab.

ravi_kumar_11-1706700294947.png

  In Transaction Arrow symbol, choose Authorization default.

ravi_kumar_12-1706700294949.png

 Choose the SAP Gateway Business Suite Enablement - Service

ravi_kumar_13-1706700294953.png

 Then choose your service

ravi_kumar_14-1706700294959.png

 

ravi_kumar_15-1706700294963.png

  Here we can see that our Service is Added to the role.

ravi_kumar_16-1706700294969.png

 Then Click on Authorization Tab

ravi_kumar_17-1706700294974.png

  Then Click on Change Authorization Data.

ravi_kumar_18-1706700294975.png

Click on Manually and provide your Authorization Name and select the Action and Click on Generate.

ravi_kumar_19-1706700294982.png

After Generating will get the Message 'Profiles were Updated'.

Then Go to Transaction Code ‘SU01’ to set role for the User.

ravi_kumar_20-1706700294984.png

 

ravi_kumar_21-1706700294991.png

 Enter your Role name and click enter.

ravi_kumar_22-1706700294997.png

Then in Profiles click on generate which is located next to the Role name.

By Performing this we can Provide Authorization to ODATA Service.

ravi_kumar_23-1706700295010.png

Output for the HANAUSER18(My user). When Authorized user try to access.

 

ravi_kumar_24-1706700295027.png

Output for HANAUSER24 (Other user) When Non authorized user try to Access it will throw error.

1 Comment
chholzermsg
Participant
0 Kudos

Hi @Ravikumar_H ,

thank you very much for this blog.

And how would it be the other way around? i.e. I have an OData service and I want to know, which role I need to access it?

Regards

Christian