作者:西方经济学

 

下面谈谈关于系统权限与对象权限的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表的权限同时被回收。