|
CLASS zcl_core_authority_check DEFINITION |
|
PUBLIC |
|
CREATE PUBLIC . |
|
|
|
PUBLIC SECTION. |
|
|
|
INTERFACES zif_core_authority_check . |
|
|
|
CONSTANTS: |
|
BEGIN OF sc_activity_field, |
|
actvt TYPE zcore_auth_field VALUE 'ACTVT', |
|
END OF sc_activity_field . |
|
CONSTANTS: |
|
BEGIN OF sc_activity_value, |
|
display TYPE zcore_auth_value VALUE '03', |
|
END OF sc_activity_value . |
|
CONSTANTS sc_authorized TYPE abap_bool VALUE abap_true ##NO_TEXT. |
|
CONSTANTS sc_unauthorized TYPE abap_bool VALUE abap_false ##NO_TEXT. |
|
|
|
METHODS constructor |
|
IMPORTING |
|
!io_auth_conditions TYPE REF TO if_auth_objects_to_conditions OPTIONAL . |
|
PROTECTED SECTION. |
|
PRIVATE SECTION. |
|
|
|
DATA mo_auth_conditions TYPE REF TO if_auth_objects_to_conditions . |
|
|
|
METHODS is_authorized |
|
IMPORTING |
|
!iv_authorization_object TYPE zcore_auth_object |
|
RETURNING |
|
VALUE(result) TYPE abap_bool |
|
RAISING |
|
zcx_core_authority_check . |
|
ENDCLASS. |
|
|
|
|
|
|
|
CLASS ZCL_CORE_AUTHORITY_CHECK IMPLEMENTATION. |
|
|
|
|
|
* <SIGNATURE>---------------------------------------------------------------------------------------+ |
|
* | Instance Public Method ZCL_CORE_AUTHORITY_CHECK->CONSTRUCTOR |
|
* +-------------------------------------------------------------------------------------------------+ |
|
* | [--->] IO_AUTH_CONDITIONS TYPE REF TO IF_AUTH_OBJECTS_TO_CONDITIONS(optional) |
|
* +--------------------------------------------------------------------------------------</SIGNATURE> |
|
METHOD constructor. |
|
|
|
IF mo_auth_conditions IS BOUND. |
|
mo_auth_conditions = io_auth_conditions. |
|
ELSE. |
|
mo_auth_conditions = cl_auth_objects_to_conditions=>create( NEW cl_auth_object_values_provider( ) ). |
|
ENDIF. |
|
|
|
ENDMETHOD. |
|
|
|
|
|
* <SIGNATURE>---------------------------------------------------------------------------------------+ |
|
* | Instance Private Method ZCL_CORE_AUTHORITY_CHECK->IS_AUTHORIZED |
|
* +-------------------------------------------------------------------------------------------------+ |
|
* | [--->] IV_AUTHORIZATION_OBJECT TYPE ZCORE_AUTH_OBJECT |
|
* | [<-()] RESULT TYPE ABAP_BOOL |
|
* | [!CX!] ZCX_CORE_AUTHORITY_CHECK |
|
* +--------------------------------------------------------------------------------------</SIGNATURE> |
|
METHOD is_authorized. |
|
|
|
mo_auth_conditions->get_conditions( |
|
EXPORTING |
|
iv_authorization_object = iv_authorization_object |
|
IMPORTING |
|
et_conditions = DATA(lt_conditions) |
|
ev_authorized = result |
|
). |
|
|
|
IF result = abap_false. |
|
RAISE EXCEPTION TYPE zcx_core_authority_check |
|
EXPORTING |
|
textid = zcx_core_authority_check=>not_authorized |
|
mv_authorization_object = iv_authorization_object. |
|
ENDIF. |
|
|
|
ENDMETHOD. |
|
|
|
|
|
* <SIGNATURE>---------------------------------------------------------------------------------------+ |
|
* | Instance Public Method ZCL_CORE_AUTHORITY_CHECK->ZIF_CORE_AUTHORITY_CHECK~CHECK_DISPLAY |
|
* +-------------------------------------------------------------------------------------------------+ |
|
* | [--->] IV_AUTHORIZATION_OBJECT TYPE ZCORE_AUTH_OBJECT |
|
* | [--->] IT_FIELD_MAPPING TYPE TT_FIELD_MAPPING(optional) |
|
* | [<-()] RESULT TYPE ABAP_BOOL |
|
* | [!CX!] ZCX_CORE_AUTHORITY_CHECK |
|
* +--------------------------------------------------------------------------------------</SIGNATURE> |
|
METHOD zif_core_authority_check~check_display. |
|
|
|
mo_auth_conditions->add_authorization_object( |
|
iv_authorization_object = iv_authorization_object |
|
it_activities = VALUE #( ( auth_field = sc_activity_field-actvt value = sc_activity_value-display ) ) |
|
it_field_mapping = it_field_mapping |
|
). |
|
|
|
result = is_authorized( iv_authorization_object ). |
|
|
|
ENDMETHOD. |
|
ENDCLASS. |
how to use: