mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-01 12:20:51 +08:00
parent
db22013699
commit
60f205d391
|
@ -1,149 +0,0 @@
|
|||
"! Default {@link ZIF_ABAPGIT_2FA_AUTHENTICATOR} implementation
|
||||
CLASS zcl_abapgit_2fa_auth_base DEFINITION
|
||||
PUBLIC
|
||||
ABSTRACT
|
||||
CREATE PUBLIC .
|
||||
|
||||
PUBLIC SECTION.
|
||||
INTERFACES:
|
||||
zif_abapgit_2fa_authenticator.
|
||||
ALIASES:
|
||||
authenticate FOR zif_abapgit_2fa_authenticator~authenticate,
|
||||
supports_url FOR zif_abapgit_2fa_authenticator~supports_url,
|
||||
is_2fa_required FOR zif_abapgit_2fa_authenticator~is_2fa_required,
|
||||
delete_access_tokens FOR zif_abapgit_2fa_authenticator~delete_access_tokens,
|
||||
begin FOR zif_abapgit_2fa_authenticator~begin,
|
||||
end FOR zif_abapgit_2fa_authenticator~end.
|
||||
METHODS:
|
||||
"! @parameter iv_supported_url_regex | Regular expression to check if a repository url is
|
||||
"! supported, used for default implementation of
|
||||
"! {@link .METH:supports_url}
|
||||
constructor IMPORTING iv_supported_url_regex TYPE clike.
|
||||
PROTECTED SECTION.
|
||||
CLASS-METHODS:
|
||||
"! Helper method to raise class based exception after traditional exception was raised
|
||||
"! <p>
|
||||
"! <em>sy-msg...</em> must be set right before calling!
|
||||
"! </p>
|
||||
raise_comm_error_from_sy RAISING zcx_abapgit_2fa_comm_error.
|
||||
METHODS:
|
||||
"! @parameter rv_running | Internal session is currently active
|
||||
is_session_running RETURNING VALUE(rv_running) TYPE abap_bool,
|
||||
"! Returns HTTP client configured with proxy (where required) for the given URL
|
||||
get_http_client_for_url
|
||||
IMPORTING iv_url TYPE string
|
||||
RETURNING VALUE(ri_client) TYPE REF TO if_http_client
|
||||
RAISING zcx_abapgit_2fa_comm_error.
|
||||
PRIVATE SECTION.
|
||||
DATA:
|
||||
mo_url_regex TYPE REF TO cl_abap_regex,
|
||||
mv_session_running TYPE abap_bool.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS ZCL_ABAPGIT_2FA_AUTH_BASE IMPLEMENTATION.
|
||||
|
||||
|
||||
METHOD authenticate.
|
||||
RAISE EXCEPTION TYPE zcx_abapgit_2fa_auth_failed. " Needs to be overwritten in subclasses
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD begin.
|
||||
IF mv_session_running = abap_true.
|
||||
RAISE EXCEPTION TYPE zcx_abapgit_2fa_illegal_state.
|
||||
ENDIF.
|
||||
|
||||
mv_session_running = abap_true.
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD constructor.
|
||||
CREATE OBJECT mo_url_regex
|
||||
EXPORTING
|
||||
pattern = iv_supported_url_regex
|
||||
ignore_case = abap_true.
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD delete_access_tokens.
|
||||
RAISE EXCEPTION TYPE zcx_abapgit_2fa_del_failed. " Needs to be overwritten in subclasses
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD end.
|
||||
IF mv_session_running = abap_false.
|
||||
RAISE EXCEPTION TYPE zcx_abapgit_2fa_illegal_state.
|
||||
ENDIF.
|
||||
|
||||
mv_session_running = abap_false.
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD get_http_client_for_url.
|
||||
DATA: lo_proxy TYPE REF TO zcl_abapgit_proxy_config,
|
||||
lx_abapgit_exc TYPE REF TO zcx_abapgit_exception,
|
||||
lv_error_text TYPE string.
|
||||
|
||||
CREATE OBJECT lo_proxy.
|
||||
cl_http_client=>create_by_url(
|
||||
EXPORTING
|
||||
url = iv_url
|
||||
ssl_id = zcl_abapgit_exit=>get_instance( )->get_ssl_id( )
|
||||
proxy_host = lo_proxy->get_proxy_url( iv_url )
|
||||
proxy_service = lo_proxy->get_proxy_port( iv_url )
|
||||
IMPORTING
|
||||
client = ri_client
|
||||
EXCEPTIONS
|
||||
argument_not_found = 1
|
||||
plugin_not_active = 2
|
||||
internal_error = 3
|
||||
OTHERS = 4 ).
|
||||
IF sy-subrc <> 0.
|
||||
raise_comm_error_from_sy( ).
|
||||
ENDIF.
|
||||
|
||||
IF lo_proxy->get_proxy_authentication( iv_url ) = abap_true.
|
||||
TRY.
|
||||
zcl_abapgit_proxy_auth=>run( ri_client ).
|
||||
CATCH zcx_abapgit_exception INTO lx_abapgit_exc.
|
||||
lv_error_text = lx_abapgit_exc->get_text( ).
|
||||
IF lv_error_text IS INITIAL.
|
||||
lv_error_text = `Proxy authentication error`.
|
||||
ENDIF.
|
||||
RAISE EXCEPTION TYPE zcx_abapgit_2fa_comm_error
|
||||
EXPORTING
|
||||
mv_text = lv_error_text
|
||||
previous = lx_abapgit_exc.
|
||||
ENDTRY.
|
||||
ENDIF.
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD is_2fa_required.
|
||||
rv_required = abap_false.
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD is_session_running.
|
||||
rv_running = mv_session_running.
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD raise_comm_error_from_sy.
|
||||
DATA: lv_error_msg TYPE string.
|
||||
|
||||
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
|
||||
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
|
||||
INTO lv_error_msg.
|
||||
RAISE EXCEPTION TYPE zcx_abapgit_2fa_comm_error
|
||||
EXPORTING
|
||||
mv_text = |Communication error: { lv_error_msg }|.
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD supports_url.
|
||||
rv_supported = mo_url_regex->create_matcher( text = iv_url )->match( ).
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
|
@ -1,16 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<VSEOCLASS>
|
||||
<CLSNAME>ZCL_ABAPGIT_2FA_AUTH_BASE</CLSNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>2FA base</DESCRIPT>
|
||||
<STATE>1</STATE>
|
||||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
|
@ -1,203 +0,0 @@
|
|||
"! Static registry class to find {@link ZIF_ABAPGIT_2FA_AUTHENTICATOR} instances
|
||||
CLASS zcl_abapgit_2fa_auth_registry DEFINITION
|
||||
PUBLIC
|
||||
FINAL
|
||||
CREATE PRIVATE .
|
||||
|
||||
PUBLIC SECTION.
|
||||
CLASS-METHODS:
|
||||
class_constructor,
|
||||
"! Retrieve an authenticator instance by url
|
||||
"! @parameter iv_url | Url of the repository / service
|
||||
"! @parameter ri_authenticator | Found authenticator instance
|
||||
"! @raising zcx_abapgit_2fa_unsupported | No authenticator found that supports the service
|
||||
get_authenticator_for_url IMPORTING iv_url TYPE string
|
||||
RETURNING VALUE(ri_authenticator) TYPE REF TO zif_abapgit_2fa_authenticator
|
||||
RAISING zcx_abapgit_2fa_unsupported,
|
||||
"! Check if there is a two factor authenticator available for the url
|
||||
"! @parameter iv_url | Url of the repository / service
|
||||
"! @parameter rv_supported | 2FA is supported
|
||||
is_url_supported IMPORTING iv_url TYPE string
|
||||
RETURNING VALUE(rv_supported) TYPE abap_bool,
|
||||
"! Offer to use two factor authentication if supported and required
|
||||
"! <p>
|
||||
"! This uses GUI functionality to display a popup to request the user to enter a two factor
|
||||
"! token. Also an dummy authentication request might be used to find out if two factor
|
||||
"! authentication is required for the account.
|
||||
"! </p>
|
||||
"! @parameter iv_url | Url of the repository / service
|
||||
"! @parameter cv_username | Username
|
||||
"! @parameter cv_password | Password, will be replaced by an access token if two factor
|
||||
"! authentication succeeds
|
||||
"! @raising zcx_abapgit_exception | Error in two factor authentication
|
||||
use_2fa_if_required IMPORTING iv_url TYPE string
|
||||
CHANGING cv_username TYPE string
|
||||
cv_password TYPE string
|
||||
RAISING zcx_abapgit_exception.
|
||||
|
||||
PROTECTED SECTION.
|
||||
CLASS-DATA:
|
||||
"! All authenticators managed by the registry
|
||||
gt_registered_authenticators TYPE HASHED TABLE OF REF TO zif_abapgit_2fa_authenticator
|
||||
WITH UNIQUE KEY table_line.
|
||||
|
||||
PRIVATE SECTION.
|
||||
CLASS-METHODS:
|
||||
popup_token
|
||||
RETURNING VALUE(rv_token) TYPE string
|
||||
RAISING zcx_abapgit_exception.
|
||||
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS zcl_abapgit_2fa_auth_registry IMPLEMENTATION.
|
||||
|
||||
|
||||
METHOD class_constructor.
|
||||
|
||||
DATA: lt_sub TYPE seo_relkeys,
|
||||
ls_sub LIKE LINE OF lt_sub,
|
||||
li_authenticator TYPE REF TO zif_abapgit_2fa_authenticator,
|
||||
lo_class TYPE REF TO cl_oo_class,
|
||||
lv_warning_message TYPE string.
|
||||
|
||||
|
||||
TRY.
|
||||
lo_class ?= cl_oo_class=>get_instance( 'ZCL_ABAPGIT_2FA_AUTH_BASE' ).
|
||||
lt_sub = lo_class->get_subclasses( ).
|
||||
SORT lt_sub BY clsname ASCENDING AS TEXT.
|
||||
LOOP AT lt_sub INTO ls_sub.
|
||||
CREATE OBJECT li_authenticator TYPE (ls_sub-clsname).
|
||||
INSERT li_authenticator INTO TABLE gt_registered_authenticators.
|
||||
ENDLOOP.
|
||||
|
||||
" Current 2FA approach will be removed as GitHub is deprecating the used authentication mechanism and there
|
||||
" are no other 2FA implementations. Show a warning in case someone subclassed ZCL_ABAPGIT_2FA_AUTH_BASE and
|
||||
" is using a custom 2FA implementation.
|
||||
" https://github.com/abapGit/abapGit/issues/3150
|
||||
" https://github.com/abapGit/abapGit/pull/3839
|
||||
|
||||
IF gt_registered_authenticators IS NOT INITIAL AND
|
||||
zcl_abapgit_ui_factory=>get_gui_functions( )->gui_is_available( ) = abap_true.
|
||||
lv_warning_message = 'Custom 2FA implementation found. 2FA infrastructure is marked for deletion.' &&
|
||||
' Please open an issue if you are using it: github.com/abapGit/abapGit/issues/new'.
|
||||
MESSAGE lv_warning_message TYPE 'I' DISPLAY LIKE 'W'.
|
||||
ENDIF.
|
||||
CATCH cx_class_not_existent ##NO_HANDLER.
|
||||
ENDTRY.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD get_authenticator_for_url.
|
||||
FIELD-SYMBOLS: <li_authenticator> LIKE LINE OF gt_registered_authenticators.
|
||||
|
||||
LOOP AT gt_registered_authenticators ASSIGNING <li_authenticator>.
|
||||
IF <li_authenticator>->supports_url( iv_url ) = abap_true.
|
||||
ri_authenticator = <li_authenticator>.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
|
||||
RAISE EXCEPTION TYPE zcx_abapgit_2fa_unsupported.
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD is_url_supported.
|
||||
TRY.
|
||||
get_authenticator_for_url( iv_url ).
|
||||
rv_supported = abap_true.
|
||||
CATCH zcx_abapgit_2fa_unsupported ##NO_HANDLER.
|
||||
ENDTRY.
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD popup_token.
|
||||
|
||||
DATA: lv_returncode TYPE c,
|
||||
lt_fields TYPE TABLE OF sval.
|
||||
|
||||
FIELD-SYMBOLS: <ls_field> LIKE LINE OF lt_fields.
|
||||
|
||||
|
||||
APPEND INITIAL LINE TO lt_fields ASSIGNING <ls_field>.
|
||||
<ls_field>-tabname = 'TADIR'.
|
||||
<ls_field>-fieldname = 'OBJ_NAME'.
|
||||
<ls_field>-fieldtext = 'Two factor auth. token'.
|
||||
|
||||
CALL FUNCTION 'POPUP_GET_VALUES'
|
||||
EXPORTING
|
||||
no_value_check = abap_true
|
||||
popup_title = 'Two factor auth. token'
|
||||
IMPORTING
|
||||
returncode = lv_returncode
|
||||
TABLES
|
||||
fields = lt_fields
|
||||
EXCEPTIONS
|
||||
error_in_fields = 1
|
||||
OTHERS = 2.
|
||||
IF sy-subrc <> 0.
|
||||
zcx_abapgit_exception=>raise( 'Error from POPUP_GET_VALUES' ).
|
||||
ENDIF.
|
||||
|
||||
IF lv_returncode = 'A'.
|
||||
zcx_abapgit_exception=>raise( 'Authentication cancelled' ).
|
||||
ENDIF.
|
||||
|
||||
READ TABLE lt_fields INDEX 1 ASSIGNING <ls_field>.
|
||||
ASSERT sy-subrc = 0.
|
||||
rv_token = <ls_field>-value.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD use_2fa_if_required.
|
||||
DATA: li_authenticator TYPE REF TO zif_abapgit_2fa_authenticator,
|
||||
lv_2fa_token TYPE string,
|
||||
lv_access_token TYPE string,
|
||||
lx_ex TYPE REF TO cx_root.
|
||||
|
||||
IF is_url_supported( iv_url ) = abap_false.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
|
||||
TRY.
|
||||
li_authenticator = get_authenticator_for_url( iv_url ).
|
||||
li_authenticator->begin( ).
|
||||
|
||||
" Is two factor authentication required for this account?
|
||||
IF li_authenticator->is_2fa_required( iv_url = iv_url
|
||||
iv_username = cv_username
|
||||
iv_password = cv_password ) = abap_true.
|
||||
|
||||
lv_2fa_token = popup_token( ).
|
||||
|
||||
" Delete an old access token if it exists
|
||||
li_authenticator->delete_access_tokens( iv_url = iv_url
|
||||
iv_username = cv_username
|
||||
iv_password = cv_password
|
||||
iv_2fa_token = lv_2fa_token ).
|
||||
|
||||
" Get a new access token
|
||||
lv_access_token = li_authenticator->authenticate( iv_url = iv_url
|
||||
iv_username = cv_username
|
||||
iv_password = cv_password
|
||||
iv_2fa_token = lv_2fa_token ).
|
||||
|
||||
" Use the access token instead of the password
|
||||
cv_password = lv_access_token.
|
||||
ENDIF.
|
||||
|
||||
li_authenticator->end( ).
|
||||
|
||||
CATCH zcx_abapgit_2fa_error INTO lx_ex.
|
||||
TRY.
|
||||
li_authenticator->end( ).
|
||||
CATCH zcx_abapgit_2fa_illegal_state ##NO_HANDLER.
|
||||
ENDTRY.
|
||||
|
||||
zcx_abapgit_exception=>raise( |2FA error: { lx_ex->get_text( ) }| ).
|
||||
ENDTRY.
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
|
@ -1,16 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<VSEOCLASS>
|
||||
<CLSNAME>ZCL_ABAPGIT_2FA_AUTH_REGISTRY</CLSNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>2FA registry</DESCRIPT>
|
||||
<STATE>1</STATE>
|
||||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
|
@ -79,14 +79,6 @@ CLASS ZCL_ABAPGIT_HTTP IMPLEMENTATION.
|
|||
iv_login = lv_user ).
|
||||
ENDIF.
|
||||
|
||||
" Offer two factor authentication if it is available and required
|
||||
zcl_abapgit_2fa_auth_registry=>use_2fa_if_required(
|
||||
EXPORTING
|
||||
iv_url = iv_url
|
||||
CHANGING
|
||||
cv_username = lv_user
|
||||
cv_password = lv_pass ).
|
||||
|
||||
rv_scheme = ii_client->response->get_header_field( 'www-authenticate' ).
|
||||
FIND REGEX '^(\w+)' IN rv_scheme SUBMATCHES rv_scheme.
|
||||
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
class ZCX_ABAPGIT_2FA_AUTH_FAILED definition
|
||||
public
|
||||
inheriting from ZCX_ABAPGIT_2FA_ERROR
|
||||
final
|
||||
create public .
|
||||
|
||||
public section.
|
||||
|
||||
methods CONSTRUCTOR
|
||||
importing
|
||||
!TEXTID like TEXTID optional
|
||||
!PREVIOUS like PREVIOUS optional
|
||||
!MV_TEXT type STRING optional .
|
||||
protected section.
|
||||
|
||||
methods GET_DEFAULT_TEXT
|
||||
redefinition .
|
||||
private section.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS ZCX_ABAPGIT_2FA_AUTH_FAILED IMPLEMENTATION.
|
||||
|
||||
|
||||
method CONSTRUCTOR.
|
||||
CALL METHOD SUPER->CONSTRUCTOR
|
||||
EXPORTING
|
||||
TEXTID = TEXTID
|
||||
PREVIOUS = PREVIOUS
|
||||
MV_TEXT = MV_TEXT
|
||||
.
|
||||
endmethod.
|
||||
|
||||
|
||||
METHOD get_default_text.
|
||||
rv_text = 'Authentication failed using 2FA.' .
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<VSEOCLASS>
|
||||
<CLSNAME>ZCX_ABAPGIT_2FA_AUTH_FAILED</CLSNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>Auth failed</DESCRIPT>
|
||||
<CATEGORY>40</CATEGORY>
|
||||
<STATE>1</STATE>
|
||||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
|
@ -1,39 +0,0 @@
|
|||
class ZCX_ABAPGIT_2FA_COMM_ERROR definition
|
||||
public
|
||||
inheriting from ZCX_ABAPGIT_2FA_ERROR
|
||||
final
|
||||
create public .
|
||||
|
||||
public section.
|
||||
|
||||
methods CONSTRUCTOR
|
||||
importing
|
||||
!TEXTID like TEXTID optional
|
||||
!PREVIOUS like PREVIOUS optional
|
||||
!MV_TEXT type STRING optional .
|
||||
protected section.
|
||||
|
||||
methods GET_DEFAULT_TEXT
|
||||
redefinition .
|
||||
private section.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS ZCX_ABAPGIT_2FA_COMM_ERROR IMPLEMENTATION.
|
||||
|
||||
|
||||
method CONSTRUCTOR.
|
||||
CALL METHOD SUPER->CONSTRUCTOR
|
||||
EXPORTING
|
||||
TEXTID = TEXTID
|
||||
PREVIOUS = PREVIOUS
|
||||
MV_TEXT = MV_TEXT
|
||||
.
|
||||
endmethod.
|
||||
|
||||
|
||||
METHOD get_default_text.
|
||||
rv_text = 'Communication error.' .
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<VSEOCLASS>
|
||||
<CLSNAME>ZCX_ABAPGIT_2FA_COMM_ERROR</CLSNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>comm error</DESCRIPT>
|
||||
<CATEGORY>40</CATEGORY>
|
||||
<STATE>1</STATE>
|
||||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
|
@ -1,39 +0,0 @@
|
|||
class ZCX_ABAPGIT_2FA_DEL_FAILED definition
|
||||
public
|
||||
inheriting from ZCX_ABAPGIT_2FA_ERROR
|
||||
final
|
||||
create public .
|
||||
|
||||
public section.
|
||||
|
||||
methods CONSTRUCTOR
|
||||
importing
|
||||
!TEXTID like TEXTID optional
|
||||
!PREVIOUS like PREVIOUS optional
|
||||
!MV_TEXT type STRING optional .
|
||||
protected section.
|
||||
|
||||
methods GET_DEFAULT_TEXT
|
||||
redefinition .
|
||||
private section.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS ZCX_ABAPGIT_2FA_DEL_FAILED IMPLEMENTATION.
|
||||
|
||||
|
||||
method CONSTRUCTOR.
|
||||
CALL METHOD SUPER->CONSTRUCTOR
|
||||
EXPORTING
|
||||
TEXTID = TEXTID
|
||||
PREVIOUS = PREVIOUS
|
||||
MV_TEXT = MV_TEXT
|
||||
.
|
||||
endmethod.
|
||||
|
||||
|
||||
METHOD get_default_text.
|
||||
rv_text = 'Deleting previous access tokens failed.' .
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<VSEOCLASS>
|
||||
<CLSNAME>ZCX_ABAPGIT_2FA_DEL_FAILED</CLSNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>del failed</DESCRIPT>
|
||||
<CATEGORY>40</CATEGORY>
|
||||
<STATE>1</STATE>
|
||||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
|
@ -1,59 +0,0 @@
|
|||
class ZCX_ABAPGIT_2FA_ERROR definition
|
||||
public
|
||||
inheriting from CX_STATIC_CHECK
|
||||
create public .
|
||||
|
||||
public section.
|
||||
|
||||
data MV_TEXT type STRING read-only .
|
||||
|
||||
methods CONSTRUCTOR
|
||||
importing
|
||||
!TEXTID like TEXTID optional
|
||||
!PREVIOUS like PREVIOUS optional
|
||||
!MV_TEXT type STRING optional .
|
||||
|
||||
methods IF_MESSAGE~GET_TEXT
|
||||
redefinition .
|
||||
protected section.
|
||||
|
||||
methods GET_DEFAULT_TEXT
|
||||
returning
|
||||
value(RV_TEXT) type STRING .
|
||||
private section.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS ZCX_ABAPGIT_2FA_ERROR IMPLEMENTATION.
|
||||
|
||||
|
||||
method CONSTRUCTOR.
|
||||
CALL METHOD SUPER->CONSTRUCTOR
|
||||
EXPORTING
|
||||
TEXTID = TEXTID
|
||||
PREVIOUS = PREVIOUS
|
||||
.
|
||||
me->MV_TEXT = MV_TEXT .
|
||||
endmethod.
|
||||
|
||||
|
||||
METHOD get_default_text.
|
||||
|
||||
rv_text = 'Error in two factor authentication.' .
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD if_message~get_text.
|
||||
|
||||
IF mv_text IS NOT INITIAL.
|
||||
result = mv_text.
|
||||
ELSEIF get_default_text( ) IS NOT INITIAL.
|
||||
result = get_default_text( ).
|
||||
ELSE.
|
||||
result = super->get_text( ).
|
||||
ENDIF.
|
||||
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<VSEOCLASS>
|
||||
<CLSNAME>ZCX_ABAPGIT_2FA_ERROR</CLSNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>Error</DESCRIPT>
|
||||
<CATEGORY>40</CATEGORY>
|
||||
<STATE>1</STATE>
|
||||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
|
@ -1,39 +0,0 @@
|
|||
class ZCX_ABAPGIT_2FA_GEN_FAILED definition
|
||||
public
|
||||
inheriting from ZCX_ABAPGIT_2FA_ERROR
|
||||
final
|
||||
create public .
|
||||
|
||||
public section.
|
||||
|
||||
methods CONSTRUCTOR
|
||||
importing
|
||||
!TEXTID like TEXTID optional
|
||||
!PREVIOUS like PREVIOUS optional
|
||||
!MV_TEXT type STRING optional .
|
||||
protected section.
|
||||
|
||||
methods GET_DEFAULT_TEXT
|
||||
redefinition .
|
||||
private section.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS ZCX_ABAPGIT_2FA_GEN_FAILED IMPLEMENTATION.
|
||||
|
||||
|
||||
method CONSTRUCTOR.
|
||||
CALL METHOD SUPER->CONSTRUCTOR
|
||||
EXPORTING
|
||||
TEXTID = TEXTID
|
||||
PREVIOUS = PREVIOUS
|
||||
MV_TEXT = MV_TEXT
|
||||
.
|
||||
endmethod.
|
||||
|
||||
|
||||
METHOD get_default_text.
|
||||
rv_text = 'Two factor access token generation failed.' .
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<VSEOCLASS>
|
||||
<CLSNAME>ZCX_ABAPGIT_2FA_GEN_FAILED</CLSNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>gen failed</DESCRIPT>
|
||||
<CATEGORY>40</CATEGORY>
|
||||
<STATE>1</STATE>
|
||||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
|
@ -1,39 +0,0 @@
|
|||
class ZCX_ABAPGIT_2FA_ILLEGAL_STATE definition
|
||||
public
|
||||
inheriting from ZCX_ABAPGIT_2FA_ERROR
|
||||
final
|
||||
create public .
|
||||
|
||||
public section.
|
||||
|
||||
methods CONSTRUCTOR
|
||||
importing
|
||||
!TEXTID like TEXTID optional
|
||||
!PREVIOUS like PREVIOUS optional
|
||||
!MV_TEXT type STRING optional .
|
||||
protected section.
|
||||
|
||||
methods GET_DEFAULT_TEXT
|
||||
redefinition .
|
||||
private section.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS ZCX_ABAPGIT_2FA_ILLEGAL_STATE IMPLEMENTATION.
|
||||
|
||||
|
||||
method CONSTRUCTOR.
|
||||
CALL METHOD SUPER->CONSTRUCTOR
|
||||
EXPORTING
|
||||
TEXTID = TEXTID
|
||||
PREVIOUS = PREVIOUS
|
||||
MV_TEXT = MV_TEXT
|
||||
.
|
||||
endmethod.
|
||||
|
||||
|
||||
METHOD get_default_text.
|
||||
rv_text = 'Illegal state.' .
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<VSEOCLASS>
|
||||
<CLSNAME>ZCX_ABAPGIT_2FA_ILLEGAL_STATE</CLSNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>illegal state</DESCRIPT>
|
||||
<CATEGORY>40</CATEGORY>
|
||||
<STATE>1</STATE>
|
||||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
|
@ -1,39 +0,0 @@
|
|||
class ZCX_ABAPGIT_2FA_UNSUPPORTED definition
|
||||
public
|
||||
inheriting from ZCX_ABAPGIT_2FA_ERROR
|
||||
final
|
||||
create public .
|
||||
|
||||
public section.
|
||||
|
||||
methods CONSTRUCTOR
|
||||
importing
|
||||
!TEXTID like TEXTID optional
|
||||
!PREVIOUS like PREVIOUS optional
|
||||
!MV_TEXT type STRING optional .
|
||||
protected section.
|
||||
|
||||
methods GET_DEFAULT_TEXT
|
||||
redefinition .
|
||||
private section.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS ZCX_ABAPGIT_2FA_UNSUPPORTED IMPLEMENTATION.
|
||||
|
||||
|
||||
method CONSTRUCTOR.
|
||||
CALL METHOD SUPER->CONSTRUCTOR
|
||||
EXPORTING
|
||||
TEXTID = TEXTID
|
||||
PREVIOUS = PREVIOUS
|
||||
MV_TEXT = MV_TEXT
|
||||
.
|
||||
endmethod.
|
||||
|
||||
|
||||
METHOD get_default_text.
|
||||
rv_text = 'The service is not supported for two factor authentication.' .
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<VSEOCLASS>
|
||||
<CLSNAME>ZCX_ABAPGIT_2FA_UNSUPPORTED</CLSNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>Unsupported</DESCRIPT>
|
||||
<CATEGORY>40</CATEGORY>
|
||||
<STATE>1</STATE>
|
||||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
|
@ -1,90 +0,0 @@
|
|||
"! Defines a two factor authentication authenticator
|
||||
"! <p>
|
||||
"! Authenticators support one or multiple services and are able to generate access tokens using the
|
||||
"! service's API using the users username, password and two factor authentication token
|
||||
"! (app/sms/tokengenerator). With these access tokens the user can be authenticated to the service's
|
||||
"! implementation of the git http api, just like the "normal" password would.
|
||||
"! </p>
|
||||
"! <p>
|
||||
"! {@link ZCL_ABAPGIT_2FA_AUTH_REGISTRY} can be used to find a suitable implementation for a
|
||||
"! given repository.
|
||||
"! </p>
|
||||
"! <p>
|
||||
"! Using the {@link zif_abapgit_2fa_authenticator.METH:begin} and
|
||||
"! {@link zif_abapgit_2fa_authenticator.METH.end} methods an internal session can be started and
|
||||
"! completed in which internal state necessary for multiple methods will be cached. This can be
|
||||
"! used to avoid having multiple http sessions between
|
||||
"! {@link zif_abapgit_2fa_authenticator.METH:authenticate} and
|
||||
"! {@link zif_abapgit_2fa_authenticator.METH:delete_access_tokens}.
|
||||
"! </p>
|
||||
INTERFACE zif_abapgit_2fa_authenticator PUBLIC.
|
||||
"! Generate an access token
|
||||
"! @parameter iv_url | Repository url
|
||||
"! @parameter iv_username | Username
|
||||
"! @parameter iv_password | Password
|
||||
"! @parameter iv_2fa_token | Two factor token
|
||||
"! @parameter rv_access_token | Generated access token
|
||||
"! @raising zcx_abapgit_2fa_auth_failed | Authentication failed
|
||||
"! @raising zcx_abapgit_2fa_gen_failed | Token generation failed
|
||||
METHODS authenticate
|
||||
IMPORTING
|
||||
!iv_url TYPE string
|
||||
!iv_username TYPE string
|
||||
!iv_password TYPE string
|
||||
!iv_2fa_token TYPE string
|
||||
RETURNING
|
||||
VALUE(rv_access_token) TYPE string
|
||||
RAISING
|
||||
zcx_abapgit_2fa_auth_failed
|
||||
zcx_abapgit_2fa_gen_failed
|
||||
zcx_abapgit_2fa_comm_error .
|
||||
"! Check if this authenticator instance supports the given repository url
|
||||
"! @parameter iv_url | Repository url
|
||||
"! @parameter rv_supported | Is supported
|
||||
METHODS supports_url
|
||||
IMPORTING
|
||||
!iv_url TYPE string
|
||||
RETURNING
|
||||
VALUE(rv_supported) TYPE abap_bool .
|
||||
"! Check if two factor authentication is required
|
||||
"! @parameter iv_url | Repository url
|
||||
"! @parameter iv_username | Username
|
||||
"! @parameter iv_password | Password
|
||||
"! @parameter rv_required | 2FA is required
|
||||
METHODS is_2fa_required
|
||||
IMPORTING
|
||||
!iv_url TYPE string
|
||||
!iv_username TYPE string
|
||||
!iv_password TYPE string
|
||||
RETURNING
|
||||
VALUE(rv_required) TYPE abap_bool
|
||||
RAISING
|
||||
zcx_abapgit_2fa_comm_error .
|
||||
"! Delete all previously created access tokens for abapGit
|
||||
"! @parameter iv_url | Repository url
|
||||
"! @parameter iv_username | Username
|
||||
"! @parameter iv_password | Password
|
||||
"! @parameter iv_2fa_token | Two factor token
|
||||
"! @raising zcx_abapgit_2fa_del_failed | Token deletion failed
|
||||
"! @raising zcx_abapgit_2fa_auth_failed | Authentication failed
|
||||
METHODS delete_access_tokens
|
||||
IMPORTING
|
||||
!iv_url TYPE string
|
||||
!iv_username TYPE string
|
||||
!iv_password TYPE string
|
||||
!iv_2fa_token TYPE string
|
||||
RAISING
|
||||
zcx_abapgit_2fa_del_failed
|
||||
zcx_abapgit_2fa_comm_error
|
||||
zcx_abapgit_2fa_auth_failed .
|
||||
"! Begin an authenticator session that uses internal caching for authorizations
|
||||
"! @raising zcx_abapgit_2fa_illegal_state | Session already started
|
||||
METHODS begin
|
||||
RAISING
|
||||
zcx_abapgit_2fa_illegal_state .
|
||||
"! End an authenticator session and clear internal caches
|
||||
"! @raising zcx_abapgit_2fa_illegal_state | Session not running
|
||||
METHODS end
|
||||
RAISING
|
||||
zcx_abapgit_2fa_illegal_state .
|
||||
ENDINTERFACE.
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_INTF" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<VSEOINTERF>
|
||||
<CLSNAME>ZIF_ABAPGIT_2FA_AUTHENTICATOR</CLSNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>2FA authenticator</DESCRIPT>
|
||||
<EXPOSURE>2</EXPOSURE>
|
||||
<STATE>1</STATE>
|
||||
<UNICODE>X</UNICODE>
|
||||
</VSEOINTERF>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
Loading…
Reference in New Issue
Block a user