ABAP RAP – Instance Authorization
source link: https://blogs.sap.com/2022/12/08/abap-rap-instance-authorization/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
ABAP RAP – Instance Authorization
Hello,
In this beginner blog post we are going to see how we can use Authorizations (Instance Authorization) in ABAP Restful Application Programming Model.
Ref: https://help.sap.com/docs/BTP/923180ddb98240829d935862025004d6/2f888de9d96e44acbfde2936d2c8bf24.html
Instance Authorization
Instance authorization is used for all authorization checks, in addition to the user role. With instance authorization, you can define authorization on a field or operation (UPDATE, DELETE). Instance authorization is only possible for instance-based operations.
Instance authorization is not available for CREATE operation.
Step 1
Add Instance keyword in Behavior Definition file.
Define Instance authorization in the behavior definition and implement it in the behavior implementation class
Step 2
Add method in Behavior Definition Implementation class.
Use quick fix option available to generate the method declaration for the authorization control in the behavior Implementation from behavior definition editor.
Got new method Definition, which is used to put custom code for Authorization Check
Step 3
Implement GET_INSTANCE_AUTHORIZATION method with below code.
REQUESTED_AUTHORIZATION is Importing parameter which identified which authorization control is requested by user.
In our demo scenario we have requested UPDATE or EDIT authorization.
RESULT parameter is available which must be filled with AUTHORIZATION result.
METHOD get_instance_authorizations.
DATA: update_requested type abap_bool,
update_grtanted TYPE abap_bool.
READ ENTITIES OF zi_student_5000 IN LOCAL MODE
ENTITY Student
FIELDS ( Status ) WITH CORRESPONDING #( keys )
RESULT DATA(studentadmitted)
FAILED failed.
CHECK studentadmitted is not initial.
update_requested = COND #( WHEN requested_authorizations-%update = if_abap_behv=>mk-on OR
requested_authorizations-%action-Edit = if_abap_behv=>mk-on THEN
abap_true ELSE abap_false ).
loop at studentadmitted ASSIGNING FIELD-SYMBOL(<lfs_studentadmitted>).
if <lfs_studentadmitted>-Status = abap_false.
if update_requested = abap_true.
update_grtanted = is_update_allowed( ).
if update_grtanted = abap_false.
APPEND VALUE #( %tky = <lfs_studentadmitted>-%tky ) to failed-student.
APPEND VALUE #( %tky = keys[ 1 ]-%tky
%msg = new_message_with_text(
severity = if_abap_behv_message=>severity-error
text = 'No Authorization to update status!!!'
)
) to reported-student.
ENDIF.
endif.
endif.
endloop.
ENDMETHOD.
Testing Instance Auth. Implementation
Simulating IS_UPDATE_ALLOWED method for Authorization Object Check by returning ABAP_FALSE, which says Authorization check failed.
Run application and click on Set Admitted button.
Since the method IS_UPDATE_ALLOWED returned ABAP_FALSE, which is simulation for Actual Authorization Object returned ABAP_FALSE
Error message is displayed to user.
Previous Blog Post : Global Authorization in ABAP RAP
Thanks-
Abhishek
Recommend
-
10
杭州 - @Yjmaple - 感觉现在人们工作压力挺大的,上周去听了杭州 live hourse 活死人的现场,瞬间炸翻, 这是 LZ 第一次现场看秀, 尤其杨和苏的几首不要太帅
-
11
凭啥咱不能过六一!(原创rap)87.0万播放 · 2474弹幕2021-06-01 04:00:14 全站排行榜最高第13名 凭啥咱不能过六...
-
9
【官方MV】「催眠麦克风 -Division Rap Battle-+」Division All Stars_哔哩哔哩_bilibili【官方MV】「催眠麦克风 -Division Rap Battle-+」Division All Stars33.5万播放 · 8576弹幕2021-06-28 04:00:14 全站排行榜最高第89名
-
5
唱支Rap给党听181.1万播放 · 6408弹幕2021-06-27 00:30:00 全站排行榜最高第7名 唱支Rap给党听...
-
11
Safa Golrokh Bahoosh September 19, 2022 6 minut...
-
5
Sujit Kumar October 14, 2022 5 minute read
-
6
Frequently Asked Questions This document answers the most frequently asked questions around the ABAP RESTful Application Programming Model (RAP) which offers a standardized programming model to efficientl...
-
2
Intro Hello everyone ! In this blog I am going to talk about RAP model –RESTful ABAP Programming Model. As described by SAP :- The ABAP RESTful Application Programming Model (in short RAP) defines the archi...
-
9
Ramjee Korada February 25, 2023 6 minute read...
-
7
ABAP RAP - Validation on List records ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK