通过TRIGGER 限制用户登陆时的IP地址,应用程序.加强对ORACLE用户的操作审计.
非DBA权限可以通过SYS_CONTEXT函数获取当前V$SESSION的会话信息.
SYS_CONTEXT函数的用法:SYS_CONTEXT('namespace', 'parameter' [, length ]);
通过以下语句可以查看V$SESSION部分信息.
CREATE OR REPLACE TRIGGER trg_work_log
AFTER LOGON ON DATABASE
declare
v_program_name varchar2(200);
v_username varchar2(100);
v_ip_address varchar2(18);
v_error varchar2(1000);
begin
--获取当前的连接用户信息
select username,program,SYS_CONTEXT('USERENV','IP_ADDRESS')
into v_username,v_program_name,v_ip_address
from v$session where AUDSID = SYS_CONTEXT('USERENV', 'SESSIONID');
if upper(v_username)='WOODY' then
if UPPER(v_program_name)<>'SQLNAV4.EXE' then
if v_ip_address <> ('192.168.1.101') then
RAISE_APPLICATION_ERROR(-20003,'You are not allowed to connect to the database');
end if;
ELSE
RAISE_APPLICATION_ERROR(-20003,'不能使用SQL Nav4.exe程序登陆');
end if;
else
RAISE_APPLICATION_ERROR(-20003,'You are not allowed to connect to the database');
end if;
END;
也可以根据需要加入其他的一些限制.AFTER LOGON ON DATABASE
declare
v_program_name varchar2(200);
v_username varchar2(100);
v_ip_address varchar2(18);
v_error varchar2(1000);
begin
--获取当前的连接用户信息
select username,program,SYS_CONTEXT('USERENV','IP_ADDRESS')
into v_username,v_program_name,v_ip_address
from v$session where AUDSID = SYS_CONTEXT('USERENV', 'SESSIONID');
if upper(v_username)='WOODY' then
if UPPER(v_program_name)<>'SQLNAV4.EXE' then
if v_ip_address <> ('192.168.1.101') then
RAISE_APPLICATION_ERROR(-20003,'You are not allowed to connect to the database');
end if;
ELSE
RAISE_APPLICATION_ERROR(-20003,'不能使用SQL Nav4.exe程序登陆');
end if;
else
RAISE_APPLICATION_ERROR(-20003,'You are not allowed to connect to the database');
end if;
END;
非DBA权限可以通过SYS_CONTEXT函数获取当前V$SESSION的会话信息.
SYS_CONTEXT函数的用法:SYS_CONTEXT('namespace', 'parameter' [, length ]);
通过以下语句可以查看V$SESSION部分信息.
select
SYS_CONTEXT('USERENV','LANGUAGE') language,
SYS_CONTEXT('USERENV','SESSIONID') sessionid,
SYS_CONTEXT('USERENV','INSTANCE') instance,
SYS_CONTEXT('USERENV','NLS_TERRITORY') nls_territory,
SYS_CONTEXT('USERENV','NLS_CURRENCY') nls_currency,
SYS_CONTEXT('USERENV','NLS_CALENDAR') nls_calendar,
SYS_CONTEXT('USERENV','NLS_DATE_FORMAT') nls_date_format,
SYS_CONTEXT('USERENV','NLS_DATE_LANGUAGE') nls_date_language,
SYS_CONTEXT('USERENV','CURRENT_USER') current_user,
SYS_CONTEXT('USERENV','CURRENT_USERID') current_userid,
SYS_CONTEXT('USERENV','SESSION_USER') session_user,
SYS_CONTEXT('USERENV','SESSION_USERID') session_userid,
SYS_CONTEXT('USERENV','HOST') host,
SYS_CONTEXT('USERENV','OS_USER') os_user,
SYS_CONTEXT('USERENV','EXTERNAL_NAME') external_name,
SYS_CONTEXT('USERENV','IP_ADDRESS') ip_address,
SYS_CONTEXT('USERENV','NETWORK_PROTOCOL') network_protocol
from dual
非法登陆的错误如下:SYS_CONTEXT('USERENV','LANGUAGE') language,
SYS_CONTEXT('USERENV','SESSIONID') sessionid,
SYS_CONTEXT('USERENV','INSTANCE') instance,
SYS_CONTEXT('USERENV','NLS_TERRITORY') nls_territory,
SYS_CONTEXT('USERENV','NLS_CURRENCY') nls_currency,
SYS_CONTEXT('USERENV','NLS_CALENDAR') nls_calendar,
SYS_CONTEXT('USERENV','NLS_DATE_FORMAT') nls_date_format,
SYS_CONTEXT('USERENV','NLS_DATE_LANGUAGE') nls_date_language,
SYS_CONTEXT('USERENV','CURRENT_USER') current_user,
SYS_CONTEXT('USERENV','CURRENT_USERID') current_userid,
SYS_CONTEXT('USERENV','SESSION_USER') session_user,
SYS_CONTEXT('USERENV','SESSION_USERID') session_userid,
SYS_CONTEXT('USERENV','HOST') host,
SYS_CONTEXT('USERENV','OS_USER') os_user,
SYS_CONTEXT('USERENV','EXTERNAL_NAME') external_name,
SYS_CONTEXT('USERENV','IP_ADDRESS') ip_address,
SYS_CONTEXT('USERENV','NETWORK_PROTOCOL') network_protocol
from dual