国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > Oracle > 正文

ORACLE 的Virtual Private Database的全新體驗(yàn)

2024-08-29 13:31:12
字體:
供稿:網(wǎng)友



oracle 的virtual private database的全新體驗(yàn)

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

歡迎大家同我交流:小白  [email protected]

歡迎轉(zhuǎn)載,請(qǐng)保留本聲明,謝謝!

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

   在開始對(duì)oracle的virtual private database的介紹之前,筆者想就row-rule control(行記錄級(jí)訪問控制)的概念簡單地說幾句。

行記錄級(jí)訪問控制問題的提出和意義?

企業(yè)的應(yīng)用系統(tǒng)都離不開數(shù)據(jù)庫系統(tǒng),數(shù)據(jù)庫系統(tǒng)的權(quán)限控制是很重要的一個(gè)環(huán)節(jié),大型數(shù)據(jù)庫系統(tǒng)(oracle、db2、sybase、ms sqlserver)都提供完善的用戶管理機(jī)制,從而可以嚴(yán)密地控制數(shù)據(jù)庫對(duì)象(表、視圖、函數(shù)、存儲(chǔ)過程、程序包等等)的訪問。但是,這往往是對(duì)象級(jí)別的。

隨著商務(wù)需求地不斷地提出,出現(xiàn)了對(duì)于行記錄控制的要求:

1)        數(shù)據(jù)查詢和報(bào)表輸出數(shù)據(jù)需要能夠進(jìn)行有效地隔離,如在一個(gè)簡單地銷售數(shù)據(jù)統(tǒng)計(jì)應(yīng)用中,大區(qū)經(jīng)理、地區(qū)經(jīng)理和銷售員查詢的數(shù)據(jù)就不同。

2)        asp(應(yīng)用服務(wù)供應(yīng)商)系統(tǒng)出現(xiàn),在系統(tǒng)結(jié)構(gòu)上,就出現(xiàn)了許多企業(yè)用戶的數(shù)據(jù)都會(huì)存放在同一個(gè)數(shù)據(jù)庫種,但是系統(tǒng)需要能夠有效地隔離。

為了滿足這樣的需求,在業(yè)務(wù)數(shù)據(jù)表需要中加上一些字段來進(jìn)行控制,應(yīng)用的開發(fā)往往會(huì)另行開發(fā)很多代碼來實(shí)現(xiàn)行記錄控制。但是,隨著業(yè)務(wù)的變化,我們會(huì)發(fā)現(xiàn)開發(fā)和維護(hù)這種管理需求的成本越來越高。

我們需要尋找一種新的解決方案,能夠使應(yīng)用系統(tǒng)的架構(gòu)設(shè)計(jì)簡單,擴(kuò)展性強(qiáng),管理和維護(hù)的成本很低。

oracle8i的一個(gè)新特性virtual private database

oracle 8i提供了一個(gè)新的特性,來實(shí)現(xiàn)行級(jí)規(guī)則的控制,稱之為virtual private database。充分利用8i提供的virtual private database技術(shù),可以實(shí)現(xiàn),一個(gè)數(shù)據(jù)庫schema的數(shù)據(jù)同時(shí)給多個(gè)數(shù)據(jù)庫用戶訪問,但是又能很好地隔離各自的數(shù)據(jù)內(nèi)容。顯然,這已經(jīng)不是原來的對(duì)象級(jí)的控制的概念。

下面是筆者的體驗(yàn),寫下來,供大家參考。我先通過一個(gè)簡單的例子,來說明oracle 8i的這個(gè)新特性(需oracle 8i的企業(yè)版才支持)。

環(huán)境:windows 2000 server + oracle 8.1.7(enterprise edition)

在scott用戶下,有一個(gè)customers表,記錄著客戶資料,以后為每個(gè)客戶分配一個(gè)oracle數(shù)據(jù)庫登陸賬號(hào),客戶可以登陸,查詢自己的訂單情況。那么,我們需要做的就是能夠把每個(gè)登陸賬號(hào)和客戶代碼對(duì)應(yīng)起來。就是說要實(shí)現(xiàn)一個(gè)映射關(guān)系,當(dāng)然,通過自己建關(guān)系映射表,寫代碼做,也可以實(shí)現(xiàn),但是oracle 8i把這一切變地非常簡單(我接下來的介紹都會(huì)圍繞著oracle 8i這項(xiàng)技術(shù)是我們的工作如何更加簡單,如何更加容易控制,請(qǐng)記住,這是筆者寫這篇文章的目的)。

--建立一個(gè)secusr的賬號(hào),用于權(quán)限控制用

connect system/[email protected];

create user secusr identified by secusr;

grant connect,resource,dba to secusr;

--把customers的查詢權(quán)利賦予secusr

connect scott/[email protected];

grant select on "customers" to secusr;

--連接到secusr用戶

connect secusr/[email protected];

--創(chuàng)建上下文

create context customer_context using secusr.customer_security_context;

--創(chuàng)建程序包c(diǎn)ustomer_security_context

create or replace package

secusr.customer_security_context is

procedure set_customerid;

end;

 

create or replace package body

secusr.customer_security_context is

procedure set_customerid is

begin

if sys_context('userenv','session_user')='scott' then

   dbms_session.set_context('customer_context','customerid','alfki');

end if;

end;

end;

 

--授權(quán)

grant execute on secusr.customer_security_context to public;

oracle 8i中提供了context(連接上下文)的概念,類似于asp中的session,你可以為當(dāng)前這個(gè)連接設(shè)置多個(gè)全局變量,記錄信息,這個(gè)信息一直保持到連接被釋放。上面的代碼,就是為用scott賬號(hào)登陸的連接,進(jìn)行了一次客戶代碼的映射(scott->alfki),而且,隨時(shí)可以sys_context來查詢。

具體代碼如下:

sql> connect scott/[email protected];

已連接。

sql> execute secusr.customer_security_context.set_customerid;

pl/sql 過程已成功完成。

sql> select sys_context('customer_context','customerid') from dual;

sys_context('customer_context','customerid')

--------------------------------------------------------------------------------

alfki

但是,我覺的還不夠,能夠做到每個(gè)連接建立的時(shí)候,就自動(dòng)完成這種映射,令人高興的是,oracle 8i提供了系統(tǒng)級(jí)的觸發(fā)器,讓我輕松地實(shí)現(xiàn)。

--scott用戶登陸觸發(fā)器

connect system/[email protected]

create or replace trigger scott.tg_set_usr_context

after logon on database

begin

secusr.customer_security_context.set_customerid;

end;

--斷掉connection,重新登陸

oracle8i enterprise edition release 8.1.7.0.0 - production

with the partitioning option

jserver release 8.1.7.0.0 - production

 

sql> connect scott/[email protected]

已連接。

sql> select sys_context('customer_context','customerid') from dual;

sys_context('customer_context','customerid')

--------------------------------------------------------------------------------

alfki

sql>

好了,夠簡單吧。

采用virtual private database如何達(dá)到sql dml上的數(shù)據(jù)控制訪問要求呢?

virtual private database技術(shù)可以對(duì)一張表的記錄設(shè)置dml操作的過濾策略。oracle8i提供了policy的概念,并且為此配備了一套系統(tǒng)程序包,來完成設(shè)置。下面,我來介紹一下:

connect secusr/[email protected]

--做一個(gè)函數(shù),返回對(duì)應(yīng)的過濾條件

create or replace package secusr.customer_security is

function customer_sec

return varchar2;

end;

 

create or replace package body secusr.customer_security

is

function customer_sec(d1 varchar2,d2 varchar2)

return varchar2

is

begin

if sys_context('userenv','session_user') in ('sys','system','secusr') then

   return null;

else

   return 'customerid='''|| sys_context('customer_context','customerid') || '''';

end if;

end;

end;

 

--設(shè)置表數(shù)據(jù)的分割過濾

execute dbms_rls.add_policy('scott','"customers"','customers_sec_policy',

'secusr',

'customer_security.customer_sec',

'select,update,delete');

customer_security程序包的customer_sec函數(shù)實(shí)現(xiàn)了,根據(jù)但前的context中customerid的內(nèi)容,來返回一個(gè)過濾的策略,函數(shù)的參數(shù)形式是固定的。通過dbms_rls程序包的add_policy過程,把策略條件同表綁定以來,以后,每次select,update,delete都會(huì)自動(dòng)應(yīng)用這個(gè)策略。

好了,現(xiàn)在我們來測試一下

--用scott登陸,只能看到自己的信息

sql> connect scott/[email protected];

已連接。

sql> select customerid,city from "customers";

 

customerid city

---------- ------------------------------

alfki      berlin

--用system登陸,可以看到所有的

sql> connect system/[email protected];

已連接。

sql> select customerid,city from "scott"."customers";

customerid city

---------- ------------------------------

alfki      berlin

anatr      méxico d.f.

anton      méxico d.f.

arout      london

bergs      lule?   d.f.

blaus      mannheim

blonp      strasbourg

bolid      madrid

bonap      marseille

bottm      tsawassen

bsbev      london

非常好,完全滿足了要求,現(xiàn)在可以放心地把scott賬號(hào)給客戶(alfki)了,客戶可以查詢自己的訂單情況,當(dāng)然只能是自己的。

sql> select a.orderid,a.customerid,a.orderdate,

  2  sum(c.unitprice*c.quantity*(1-c.discount)) as totalmoney

  3  from "orders" a,"customers" b ,"order details" c

  4  where a.customerid=b.customerid and a.orderid=c.orderid

  5  group by a.orderid,a.customerid,a.orderdate;

 

   orderid customerid orderdate  totalmoney

---------- ---------- ---------- ----------------------------------------

     10643 alfki      25-8月 -97      814.5

     10692 alfki      03-10月-97        878

     10702 alfki      13-10月-97        330

     10835 alfki      15-1月 -98      845.8

     10952 alfki      16-3月 -98      471.2

     11011 alfki      09-4月 -98      933.5

已選擇6行。

下面,讓我總結(jié)一下virtual private database的優(yōu)點(diǎn):

l         提供了一種可行的、可靠的、對(duì)用戶完全透明的行規(guī)則控制方案

同自己建立一套用戶控制權(quán)限不同,virtual private database對(duì)用戶是透明的,你的應(yīng)用程序不用去考慮這點(diǎn),你的應(yīng)用程序需要的是更加集中于你的業(yè)務(wù)處理過程的實(shí)現(xiàn),而不要讓數(shù)據(jù)隔離控制,成為你業(yè)務(wù)處理的一個(gè)過程。你可以完全先開發(fā)功能應(yīng)用,然后再加上數(shù)據(jù)隔離的控制,而這種控制,是基于后臺(tái)數(shù)據(jù)庫系統(tǒng)的,這種變動(dòng)與現(xiàn)有的應(yīng)用程序完全兼容,不會(huì)引起現(xiàn)有的程序不能運(yùn)行

l         控制更加嚴(yán)密,不僅對(duì)于業(yè)務(wù)系統(tǒng)才有效

由于采取的是后臺(tái)數(shù)據(jù)庫技術(shù),所以這種控制,對(duì)所有的應(yīng)用(除了業(yè)務(wù)系統(tǒng),數(shù)據(jù)庫管理工具等等)都起到了控制作用。相比之下,采用自己的權(quán)限控制的應(yīng)用中,只能做到在業(yè)務(wù)系統(tǒng)的應(yīng)用中有效,而其他(sqlplus,sqlplus worksheet等等)就完全沒有效果。而且大多系統(tǒng)都采用使用一個(gè)數(shù)據(jù)庫賬號(hào)登陸到系統(tǒng)的方案,在這種情況下,這個(gè)賬號(hào)對(duì)于業(yè)務(wù)數(shù)據(jù)庫一般來說操作權(quán)限很高,而這個(gè)賬號(hào)一旦泄漏,攻擊者利用sqlplus工具可以方遍地竊取數(shù)據(jù)。

l         和用應(yīng)用程序自己實(shí)現(xiàn)的方法相比,這種技術(shù)更加靈活,而且便于管理,同時(shí)開發(fā)成本也是最低的。

采用了這種行記錄控制技術(shù),不需要通過應(yīng)用程序?qū)崿F(xiàn),大大地簡化了應(yīng)用系統(tǒng)地復(fù)雜性,同時(shí)也讓你的系統(tǒng)的結(jié)構(gòu)很清晰,而出現(xiàn)錯(cuò)誤的可能性就更低了。當(dāng)然,你自己建立的控制系統(tǒng)也可以做到oracle 8i的功能,但是會(huì)大大加大開發(fā)成本。

l         對(duì)于asp(應(yīng)用服務(wù)供應(yīng)商)系統(tǒng),滿足了用戶數(shù)據(jù)存放在一起,但又能夠獨(dú)立分開訪問的要求。筆者覺得,這項(xiàng)技術(shù),對(duì)于構(gòu)建asp應(yīng)用系統(tǒng)的用戶特別有用,充分利用oracle提供的新技術(shù),讓你的系統(tǒng)更加安全、可靠。

總之,virtual private database是一個(gè)功能強(qiáng)大的行級(jí)規(guī)則控制技術(shù),是oracle8i提供給我們的一個(gè)強(qiáng)有力的特性,充分地應(yīng)用,可以大大節(jié)省軟件開發(fā)成本。

筆者認(rèn)為virtual private database技術(shù)是一個(gè)非常有用的技術(shù),而在sql server 2000和sybase ase 12.5中,沒有看到類似的技術(shù)。

 

 

 

 

 
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 吉木乃县| 黎川县| 白水县| 奉化市| 湘潭县| 蕲春县| 景洪市| 澜沧| 海伦市| 孟州市| 东光县| 克东县| 宁都县| 双城市| 杨浦区| 罗源县| 新余市| 大兴区| 晋宁县| 东兴市| 内丘县| 黔江区| 城市| 绥宁县| 永兴县| 赫章县| 宽甸| 奉化市| 营口市| 临汾市| 抚宁县| 旬邑县| 兴安县| 界首市| 永胜县| 慈溪市| 葫芦岛市| 区。| 巍山| 兴海县| 定边县|