SAP系统中,用户登陆IP,主机名,使用事物代码的审计日志记录增强

本文介绍如何在SAP系统中通过修改标准对象AUTH_CHECK_TCODE来记录用户的事务代码使用情况,并实现用户登录信息的自定义保存。

首先,这个功能有非常强大,强大到影响SAP系统每一次执行事物代码,所有一旦出现问题,可能造成全部用户的事务代码不能登陆,包括开发人员和BASIS。所以使用该功能前必须谨慎考虑。

一、改动系统标准对象:AUTH_CHECK_TCODE

在AUTH_CHECK_TCODE对象中加入自己的代码,就可以把用户的行为记录下来。


*
authority_check_tcode berücksichtigt wie der Kernel die per SE97
* pflegbaren Einträge in der Tabelle tcdcouples.
 
* Berechtigungsprüfung
  CALL 'AUTH_CHECK_TCODE'
       ID 'TCODE' FIELD tcode.                            "#EC CI_CCALL
 
  IF sy-subrc = 0.
*{   INSERT         DEVK900175                                        1
CALL FUNCTION 'Z_SAVE_LOGONINFO'
  EXPORTING
    TCODE         = tcode.
*}   INSERT
*   auth_check_tcode enthält die Prüfungen von tcode_executable,
*   daher im OK-Fall keine Aufruf nötig.
  ELSE.
    PERFORM tcode_executable USING tcode.
*   Keine Berechtigung für Transaktion &
    MESSAGE i077(s#) WITH tcode RAISING not_authorized.
  ENDIF.



二、这里,加入了一个FUNCTION 'Z_SAVE_LOGONINFO',这个FUN中我们会把用户操作信息保存到自己的表。


FUNCTION Z_SAVE_LOGONINFO.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(TCODE) LIKE  TSTC-TCODE
*"----------------------------------------------------------------------
data hostadr like uinfo-hostadr.
data hostaddr(8).
data term like uinfo-term.
data xhcount type i.
data: iptxt(15),itimes type i,itimes1 type i,hx(2).
data: result type i,resulttxt(3).
tables zlogoninfo.
call function 'TH_USER_INFO'
     importing
       hostaddr = hostadr  "like UINFO-HOSTADR
*(hex)
          terminal = term. "like UINFO-TERM
select max( xh ) into xhcount from zlogoninfo.
xhcount = xhcount + 1.
zlogoninfo-xh = xhcount.
zlogoninfo-mandt     = sy-mandt.
zlogoninfo-bname     = sy-uname.
hostaddr = hostadr.
do 4 times.
  hx = hostaddr+itimes1(2).
  itimes = 0.
  result = 0.
  do 2 times.
    case hx+itimes(1).
      when 'A'.
        if itimes = 0.
          result = result + 10 * 16.
        else.
          result = result + 10.
        endif.
      when 'B'.
        if itimes = 0.
          result = result + 11 * 16.
        else.
          result = result + 11.
        endif.
      when 'C'.
        if itimes = 0.
          result = result + 12 * 16.
        else.
          result = result + 12.
        endif.
      when 'D'.
        if itimes = 0.
          result = result + 13 * 16.
        else.
          result = result + 13.
        endif.
      when 'E'.
        if itimes = 0.
          result = result + 14 * 16.
        else.
          result = result + 14.
        endif.
      when 'F'.
        if itimes = 0.
          result = result + 15 * 16.
        else.
          result = result + 15.
        endif.
      when others.
        if itimes = 0.
          result = result + hx+itimes(1) * 16.
        else.
          result = result + hx+itimes(1).
        endif.
    endcase.
    itimes = itimes + 1.
  enddo.
  resulttxt = result.
  if iptxt <> ''.
    concatenate iptxt '.' resulttxt into iptxt.
  else.
    iptxt = resulttxt.
  endif.
  itimes1 = itimes1 + 2.
enddo.
zlogoninfo-ip = iptxt.
zlogoninfo-terminal = term.
zlogoninfo-logon_date = sy-datum.
zlogoninfo-logon_time = sy-uzeit.
zlogoninfo-UCOMM = sy-UCOMM.
zlogoninfo-tcode = TCODE.
insert into zlogoninfo client specified values
zlogoninfo.
commit work.
 
*}   INSERT
 
 
 
ENDFUNCTION.

三、自定义表的情况:







里面数据情况:





评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘欣的博客

你将成为第一个打赏博主的人!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值