conn test/test@pdb1
drop table tab1 purge;
drop sequence tab1_seq;
drop table tab2 purge;
drop sequence tab2_seq;
create table tab1 (
id number,
constraint tab1_pk primary key (id)
);
create sequence tab1_seq;
create table tab2 (
id number,
constraint tab2_pk primary key (id)
);
create sequence tab2_seq;
grant select, insert, update, delete on tab1 to test2;
grant select on tab1_seq to test2;
grant select, insert, update, delete on tab2 to test2;
grant select on tab2_seq to test2;
conn sys@pdb1 as sysdba
create audit policy test_audit_policy
actions delete on test.tab1,
insert on test.tab1,
update on test.tab1,
select on test.tab1_seq,
all on test.tab2,
select on test.tab2_seq
when 'sys_context(''userenv'', ''session_user'') = ''TEST2'''
evaluate per session
container = current;
audit policy test_audit_policy;
set linesize 200
column object_schema format a15
column object_name format a15
column object_type format a12
column audit_option format a15
column condition_eval_opt format a10
column audit_condition format a50
select object_schema,
object_name,
object_type,
audit_option,
condition_eval_opt,
audit_condition
from audit_unified_policies
where policy_name = 'TEST_AUDIT_POLICY';
OBJECT_SCHEMA OBJECT_NAME OBJECT_TYPE AUDIT_OPTION CONDITION_ AUDIT_CONDITION
--------------- --------------- ------------ --------------- ---------- --------------------------------------------------
TEST TAB1 TABLE DELETE SESSION SYS_CONTEXT('USERENV', 'SESSION_USER') = 'TEST2'
TEST TAB1 TABLE INSERT SESSION SYS_CONTEXT('USERENV', 'SESSION_USER') = 'TEST2'
TEST TAB1 TABLE UPDATE SESSION SYS_CONTEXT('USERENV', 'SESSION_USER') = 'TEST2'
TEST TAB1_SEQ SEQUENCE SELECT SESSION SYS_CONTEXT('USERENV', 'SESSION_USER') = 'TEST2'
TEST TAB2 TABLE ALL SESSION SYS_CONTEXT('USERENV', 'SESSION_USER') = 'TEST2'
TEST TAB2_SEQ SEQUENCE SELECT SESSION SYS_CONTEXT('USERENV', 'SESSION_USER') = 'TEST2'
SQL>
conn test/test@pdb1
insert into tab1 (id) values (tab1_seq.nextval);
insert into tab2 (id) values (tab2_seq.nextval);
commit;
conn test2/test2@pdb1
update test.tab1 set id = test.tab1_seq.nextval;
update test.tab2 set id = test.tab2_seq.nextval;
delete from test.tab1;
delete from test.tab2;
commit;
conn sys@pdb1 as sysdba
-- You might need to flush the audit information before it is visible.
-- EXEC DBMS_AUDIT_MGMT.flush_unified_audit_trail;
column event_timestamp format a30
column dbusername format a10
column action_name format a20
column object_schema format a10
column object_name format a20
select event_timestamp,
dbusername,
action_name,
object_schema,
object_name
from unified_audit_trail
where dbusername like 'TEST%'
order by event_timestamp;
EVENT_TIMESTAMP DBUSERNAME ACTION_NAME OBJECT_SCH OBJECT_NAME
------------------------------ ---------- -------------------- ---------- --------------------
27-JUN-2015 10:41:40.070965 TEST2 SELECT TEST TAB1_SEQ
27-JUN-2015 10:41:40.071033 TEST2 UPDATE TEST TAB1
27-JUN-2015 10:41:40.073326 TEST2 SELECT TEST TAB2_SEQ
27-JUN-2015 10:41:40.073347 TEST2 UPDATE TEST TAB2
27-JUN-2015 10:41:40.074657 TEST2 DELETE TEST TAB1
27-JUN-2015 10:41:40.076132 TEST2 DELETE TEST TAB2
SQL>
alter audit policy test_audit_policy
drop actions all on test.tab2,
select on test.tab2_seq;
set linesize 200
column object_schema format a15
column object_name format a15
column object_type format a12
column audit_option format a15
column condition_eval_opt format a10
column audit_condition format a50
select object_schema,
object_name,
object_type,
audit_option,
condition_eval_opt,
audit_condition
from audit_unified_policies
where policy_name = 'TEST_AUDIT_POLICY';
OBJECT_SCHEMA OBJECT_NAME OBJECT_TYPE AUDIT_OPTION CONDITION_ AUDIT_CONDITION
--------------- --------------- ------------ --------------- ---------- --------------------------------------------------
TEST TAB1 TABLE DELETE SESSION SYS_CONTEXT('USERENV', 'SESSION_USER') = 'TEST2'
TEST TAB1 TABLE INSERT SESSION SYS_CONTEXT('USERENV', 'SESSION_USER') = 'TEST2'
TEST TAB1 TABLE UPDATE SESSION SYS_CONTEXT('USERENV', 'SESSION_USER') = 'TEST2'
TEST TAB1_SEQ SEQUENCE SELECT SESSION SYS_CONTEXT('USERENV', 'SESSION_USER') = 'TEST2'
SQL>
noaudit policy test_audit_policy;
drop audit policy test_audit_policy;
set linesize 200
column object_schema format a15
column object_name format a15
column object_type format a12
column audit_option format a15
column condition_eval_opt format a10
column audit_condition format a50
select object_schema,
object_name,
object_type,
audit_option,
condition_eval_opt,
audit_condition
from audit_unified_policies
where policy_name = 'TEST_AUDIT_POLICY';
no rows selected
SQL>
create audit policy test_audit_policy
actions delete, insert, update, select
when 'sys_context(''userenv'', ''session_user'') = ''TEST2'''
evaluate per session
container = current;
--drop audit policy test_audit_policy;