Monday, December 24, 2007

a fga + vpd example

DROP PACKAGE MAINKEY;
begin
DBMS_RLS.DROP_POLICY (
'TEST','UTIPOSMAINKEY','PROTECTMAINKEY');
end;
/
begin
DBMS_FGA.DROP_POLICY(
object_schema=>'TEST',
object_name=>'UTIPOSMAINKEY',
policy_name=>'AUDITMAINKEY');
end;
/

=========================

CREATE OR REPLACE PACKAGE mainkey AS
FUNCTION usercontrol (D1 VARCHAR2, D2 VARCHAR2)
RETURN VARCHAR2;
END;
/

CREATE OR REPLACE PACKAGE BODY mainkey AS
FUNCTION usercontrol (D1 VARCHAR2, D2 VARCHAR2) RETURN VARCHAR2
IS
D_predicate VARCHAR2 (2000);
BEGIN
D_predicate := 'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') = ''TEST''';
RETURN D_predicate;
END usercontrol;
END mainkey;
/


BEGIN
DBMS_RLS.ADD_POLICY (
object_schema=>'TEST',
object_name=>'UTIPOSMAINKEY',
policy_name=>'PROTECTMAINKEY',
function_schema=>'TEST',
policy_function=>'MAINKEY.USERCONTROL',
statement_types=>'SELECT, UPDATE, DELETE, INSERT, INDEX',
update_check=>TRUE,
policy_type=>DBMS_RLS.STATIC);
END;
/

begin
DBMS_FGA.ADD_POLICY(
object_schema=>'TEST',
object_name=>'UTIPOSMAINKEY',
policy_name=>'AUDITMAINKEY',
audit_condition=>'SYS_CONTEXT(''USERENV'', ''SESSION_USER'') <> ''TEST''',
statement_types=>'INSERT, UPDATE, DELETE, SELECT',
audit_trail=>DBMS_FGA.DB + DBMS_FGA.EXTENDED);
end;
/

No comments: