Skip to Main Content
  • Questions
  • meta-date information on security policies

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Ved.

Asked: June 08, 2011 - 11:11 pm UTC

Last updated: June 21, 2011 - 2:11 pm UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi Tom,
I would like to extract all the meta-data information about a policy attached to security policies on the synonyms, tables, or views. Please let me know how to get that information.

Thanks

and Tom said...

dbms_metadata.get_dependent_ddl can do this easily:

ops$tkyte%ORA11GR2> create function my_security_function( p_schema in varchar2,
  2                                        p_object in varchar2 ) return varchar2
  3  as
  4  begin
  5      if ( user = 'RLS_ADMIN' ) then
  6          return '';
  7      else
  8          return 'owner = USER';
  9      end if;
 10  end;
 11  /

Function created.

ops$tkyte%ORA11GR2> 
ops$tkyte%ORA11GR2> create table my_table
  2  (  data        varchar2(30),
  3     OWNER       varchar2(30) default USER
  4  )
  5  /

Table created.

ops$tkyte%ORA11GR2> begin
  2     dbms_rls.add_policy
  3     ( object_schema   => user,
  4       object_name     => 'MY_TABLE',
  5       policy_name     => 'MY_POLICY',
  6       function_schema => user,
  7       policy_function => 'My_Security_Function',
  8       statement_types => 'select, insert, update, delete' ,
  9       update_check    => TRUE );
 10  end;
 11  /

PL/SQL procedure successfully completed.

ops$tkyte%ORA11GR2> 
ops$tkyte%ORA11GR2> select dbms_metadata.get_dependent_ddl( 'RLS_POLICY', 'MY_TABLE' ) from dual;

DBMS_METADATA.GET_DEPENDENT_DDL('RLS_POLICY','MY_TABLE')
--------------------------------------------------------------------------------

  BEGIN DBMS_RLS.ADD_GROUPED_POLICY('"OPS$TKYTE"','"MY_TABLE"','"SYS_DEFAULT"','
"MY_POLICY"','"OPS$TKYTE"','MY_SECURITY_FUNCTION','DELETE,UPDATE,INSERT,SELECT',
TRUE,TRUE,FALSE,dbms_rls.DYNAMIC,FALSE,'',NULL); END;




Unless you were just asking how to query the data dictionary?


ops$tkyte%ORA11GR2> select * from user_policies
  2  ;

OBJECT_NAME                    POLICY_GROUP
------------------------------ ------------------------------
POLICY_NAME                    PF_OWNER
------------------------------ ------------------------------
PACKAGE                        FUNCTION                       SEL INS UPD DEL
------------------------------ ------------------------------ --- --- --- ---
IDX CHK ENA STA POLICY_TYPE              LON
--- --- --- --- ------------------------ ---
MY_TABLE                       SYS_DEFAULT
MY_POLICY                      OPS$TKYTE
                               MY_SECURITY_FUNCTION           YES YES YES YES
NO  YES YES NO  DYNAMIC                  NO




Is this answer out of date? If it is, please let us know via a Comment

More to Explore

Security

All of the vital components for a secure database are covered in the Security guide.