系統權限與對象權限的revoke差別

作者:西方經濟學

 

下面談談關於系統權限與對象權限的revoke差別。

1、系統權限的撤銷:

收回系統權限時,沒有級聯效果。什麼是級聯效果呢?就是當我(sys)將某一系統權限(create table)授予給用戶test1後(使用with admin option,這樣的話test1可以將此權限再授予第三個用戶),test1又將此權限授予給第三者(test2),這不同於sys直接對test2授予create table。當我們收回test1create table權限時,test1以前創建的表仍然存在,但無法創建新表,而test仍然用於create table的權限。下面來看看這個過程:

創建用戶test1,並授予基本的權限,然後授予將權限create table授予給其他用戶的with admin option權限。

SQL> create user test1 identified by test1 default tablespace data;

用戶已創建

SQL> grant create session,unlimited tablespace to test1;

授權成功。

SQL> grant create table to test1 with admin option;

授權成功。

SQL> create user test2 identified by test2 default tablespace data;

用戶已創建

SQL> grant create session,unlimited tablespace to test2;

授權成功。

SQL> conn test1/test1@company;

已連接。

SQL> create table t1(id number);

表已創建。

SQL> grant create table to test2;

授權成功。

SQL> conn test2/test2@company;

已連接。

SQL> create table t2(id number);

表已創建。

SQL> conn sys/oracle@company as sysdba

已連接。

SQL> revoke create table from test1;

撤銷成功。

SQL> conn test1/test1@company;

已連接。

SQL> select table_name from user_tables;

TABLE_NAME                                                                     

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

T1                                                                             

SQL> create table t3(id number);

create table t3(id number)

*

ERROR 位於第 1 :

ORA-01031: insufficient privileges

SQL> insert into t1 values(1);

已創建 1 行。

SQL> commit;

提交完成。

SQL> select * from session_privs;

PRIVILEGE                                                                      

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

CREATE SESSION                                                                  

UNLIMITED TABLESPACE     

SQL> conn test2/test2@company;

已連接。

SQL> select table_name from user_tables;

TABLE_NAME                                                                     

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

T2                                                                             

SQL> create table t4 as select * from t2;

表已創建。

SQL> insert into t2 values(1);

已創建 1 行。

SQL> select * from session_privs;

PRIVILEGE                                                                       

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

CREATE SESSION                                                                 

UNLIMITED TABLESPACE                                                            

CREATE TABLE                                                                   

 

總結:系統權限的回收不存在級聯關係,只能回收直接授權的。                                               

 

2、對象權限的撤銷:

   回收對象權限時,存在級聯操作。先看過程:

SQL> show user;

USER "TEST1"

SQL> conn sys/oracle@company as sysdba

已連接。

SQL> grant dba to scott;

授權成功。

SQL> conn scott/tiger@company;

已連接。                                                                

SQL> select count(*) from test_pk;

  COUNT(*)                                                                     

----------                                                                      

      1000                                                                     

SQL> grant select on test_pk to test1 with admin option;

grant select on test_pk to test1 with admin option

                                      *

ERROR 位於第 1 :

ORA-00993: missing GRANT keyword

注意此處與系統權限不一樣!系統權限是with admin option

對象權限是with grant option

SQL> grant select on test_pk to test1 with grant option;

授權成功。

SQL> conn test1/test1@company;

已連接。

SQL> select count(*) from scott.test_pk;

  COUNT(*)                                                                      

----------                                                                     

      1000                                                                     

SQL> conn test2/test2@company;

已連接。

SQL> select count(*) from scott.test_pk;

select count(*) from scott.test_pk

                           *

ERROR 位於第 1 :

ORA-00942: table or view does not exist   ————此時還沒有授權,報錯正常。

test1test2授予查看scott.test_pk的權限。

SQL> conn test1/test1@company;

已連接。

SQL> grant select on scott.test_pk to test2;

授權成功。

SQL> conn test2/test2@company;

已連接。

SQL> select count(*) from scott.test_pk;

  COUNT(*)                                                                     

----------                                                                      

      1000                                                                     

SQL> conn scott/tiger@company;

已連接。

SQL> revoke select on test_pk from test1;

撤銷成功。

SQL> conn test1/test1@company;

已連接。

SQL> select count(*) from test1;

select count(*) from test1

                     *

ERROR 位於第 1 :

ORA-00942: table or view does not exist    -----這個權限已經回收,所以報錯!

SQL> conn test2/test2@company;

已連接。

SQL> select count(*) from scott.test_pk;

select count(*) from scott.test_pk

                           *

ERROR 位於第 1 :

ORA-00942: table or view does not exist    -----這個權限也被級聯回收,所以報錯!

SQL> select * from v$version;

BANNER                                                                         

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

Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production                     

PL/SQL Release 9.2.0.4.0 - Production                                          

CORE  9.2.0.3.0   Production                                                       

TNS for Linux: Version 9.2.0.4.0 - Production                                  

NLSRTL Version 9.2.0.4.0 - Production           

 

總結:在回收對象權限時,存在級聯回收!也就是說如果用戶scott將查看test_pk表的權限授予給test1用戶,並且授予其可以再將此權限授予給其他用戶的權限,也就是with grant option。此時test1將查看test_pk表的權限授予給test2用戶。當scott回收test1查看test_pk表的權限時,test2查看test_pk表的權限同時被回收。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章