iSelfSchooling.com - Copyright © 1999-2009  References  |  Job Openings  | Login (Staff | Members)
    Home  | Search more...  | Community of Sharing Knowledge (with FREE Online Video Training)
    Oracle Syntax  | Suggestions  | Private Tutoring  | Member Collaboration  | Get Translations...

  Copyright & User Agreement

    Email2aFriend  | Homepage us! |  Bookmark

Services

 Vision/Mission

 Services

 Biography

 Contact Us

 

 FREE Training

 SQL

 PL/SQL

 Forms 

 Reports

 Other TOOLS

 Fundamentals

 Performance

 OEM

 Application Server

 Grid Control

 Articles

 Prepare for OCP

 

More to know...

Acknowledgement___

 Who is who

 University Directory

 Links...

 

 

 

 

FREE Online Oracle Training for beginners and advanced - The most comprehensive Oracle tutorial

The authors do not guarantee or take any responsibility for the accuracy, or completeness of the information.

BASICS

SQL | PL/SQL

DEVELOPERS

FORMS 2 | REPORTS | Other TOOLS

DBAs

FUNDAMENTALS 2 | PERFORMANCE | OEM

ADVANCE

APPLICATION SERVER | GRID CONTROL | ARTICLES 2 3 4

Advanced - Articles I

Lesson 01 | Lesson 02 | Lesson 03 | Lesson 04 | Lesson 05 | Lesson 06 | Lesson 07 | Lesson 08 | Lesson 09 | Lesson 10 | Lesson 11 | Lesson 12 | Lesson 13 | Lesson 14 | Lesson 15 | Lesson 16 | Lesson 17 | Lesson 18 | Lesson 19 | Lesson 20 | Lesson 21 | Lesson 22 | Lesson 23 | Lesson 24 | Lesson 25 | Lesson 26 | Lesson 27 | Lesson 28 | Lesson 29 | Lesson 30 | Lesson 31 | Lesson 32 | Lesson 33 | Lesson 34 | Lesson 35 |

Lesson 15

‘It is easy enough to be friendly to one's friends. But to be friend the one who regards himself as your enemy is the quintessence of true religion. The other is mere business.’ Gandhi

Security VPD in the Oracle 10g database

Introduction

In the Oracle 10g database, there is a feature called Virtual Private Database (VPD). It enables you to build applications that enforce your security policy. When a user requests a query, the server dynamically modifies the user’s SQL statement, which is not transparent to the user. The modification is based on a WHERE clause returned by a function.

 

Hands-On #1-Implementing VPD

Connect as SYSDBA and grant dba privilege to the ISELF user.

SQL> CONNECT / AS SYSDBA

SQL> GRANT DBA TO iself;

Connect as ISELF, insert a record and grant SELECT object privilege to SCOTT.

SQL> CONNECT iself/schooling

SQL> INSERT INTO emp

VALUES

(9990, ‘SCOTT’,’CLERK’, 7698,

TO_DATE(’04-DEC-87’), 765.5, null, 30);

SQL> COMMIT;

SQL> GRANT SELECT ON emp TO scott;

Create a package that contains a procedure that it assigns the employee’s identifier to the EMPNO attribute. In this procedure, you need to use the DBM_SESSION.SET_CONTEXT procedure to set the empno attribute, and the SYS_CONTEXT function to determine the user’s name.

SQL> CREATE OR REPLACE PACKAGE my_security

AS

PROCEDURE get_empno;

END;

/

SQL> CREATE OR REPLACE PACKAGE BODY my_security

AS

 

PROCEDURE get_empno

IS

v_empno NUMBER;

BEGIN

SELECT empno INTO v_empno FROM iself.emp

WHERE ename =

SYS_CONTEXT(‘USERENV’,’SESSION_USER’);

DBMS_SESSION.SET_CONTEXT

(‘iself_context’, ‘empno’, v_empno);

END;

END my_security;

/

Then, create ISELF_CONTEXT using the MY_SECURITY package.

SQL> CREATE CONTEXT iself_context USING iself.my_security;

Create an AFTER LOGIN trigger that calls your security package if the current user is SCOTT.

SQL> CREATE OR REPLACE TRIGGER check_login

AFTER LOGON

ON DATABASE

BEGIN

IF user IN (‘SCOTT’) THEN

iself.my_security.get_empno();

END IF;

END check_login;

/

Create a package to return the ISELF predicate used by the policy.

SQL> CREATE OR REPLACE PACKAGE iself_security

AS

FUNCTION ck_empno

(x1 VARCHAR2, x2 VARCHAR2) RETURN VARCHAR2;

END;

/

SQL> CREATE OR REPLACE PACKAGE BODY iself_security

AS

FUNCTION ck_empno

(x1 VARCHAR2, x2 VARCHAR2) RETURN VARCHAR2

IS

v_predicate VARCHAR2 (2000);

BEGIN

v_predicate :=

‘empno = SYS_CONTEXT(‘’iself_context’’,’’empno’’)’;

RETURN v_predicate;

END ck_empno;

END iself_security;

/

Now, you can create a policy

SQL> BEGIN

DBMS_RLS.ADD_POLICY (

OBJECT_SCHEMA => ‘iself’,

OBJECT_NAME => ‘emp’,

POLICY_NAME => ‘iself_policy’,

FUNCTION_SCHEMA => ‘iself’,

POLICY_FUNCTION => ‘iself_security.ck_empno’,

STATEMENT_TYPES => ‘select’,

UPDATE_CHECK => false,

ENABLE => true,

STATIC_POLICY => false,

POLICY_TYPE => DBMS_RLS.DYNAMIC,

LONG_PREICATE => false,

SEC_RELEVANT_COLS => ‘SAL,COMM’);

END;

/

This policy is attached to the ISELF.EMP table, uses the iself_security.ck_empno function, is applied only for SELECT statement, is a dynamic policy, and specifies the SAL and COMM columns as the list of relevant columns.

Now, connect as the SCOTT user and execute the following SQL statements.

SQL> CONNECT SCOTT/TIGER

SQL> SELECT ename FROM iself.emp;

SQL> SELECT sal FROM iself.emp;

SQL> SELECT comm. FROM iself.emp;

 

 

 

“When you are right you cannot be too radical; when you are wrong, you cannot be too conservative.” Martin Luther King Jr.

Questions:

Questions on

Security VPD in the Oracle 10g database

Q: What is VPD in the Oracle 10g Database?

 

 

 
 
Google
 
Web web site