oldwain随便写
===========================================================
===========================================================

问题: 来源(tiansmart )

在oracle9i中,当通过角色为某个用户赋权时,如果用户正处于连接状态,能否实时生效?

我的回答:



权限是实时起作用的,role要在重新登陆后起作用

测试:

先看权限的情况
session1:

system@O9I.US.ORACLE.COM> create user testpriv identified by testpriv;

用户已创建

system@O9I.US.ORACLE.COM> grant connect, resource to testpriv;

授权成功。


session2:

scott@O9I.US.ORACLE.COM> connect testpriv/testpriv
已连接。
scott@O9I.US.ORACLE.COM> select count(*) from scott.emp;
select count(*) from scott.emp
*
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在

session1:


system@O9I.US.ORACLE.COM> grant select on scott.emp to testpriv;

授权成功。

session2:


scott@O9I.US.ORACLE.COM> select count(*) from scott.emp;

COUNT(*)
----------
14

session1:


system@O9I.US.ORACLE.COM> revoke select on scott.emp from testpriv;

撤销成功。

session2:


scott@O9I.US.ORACLE.COM> select count(*) from scott.emp;
select count(*) from scott.emp
*
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在

可见直接授权是立即生效的, 不需要用户重新登陆.
下面看看通过角色授权的情况:
session1:


system@O9I.US.ORACLE.COM> create role testprivrole;

角色已创建

system@O9I.US.ORACLE.COM> grant select on scott.emp to testprivrole;

授权成功。

system@O9I.US.ORACLE.COM> grant testprivrole to testpriv;

授权成功。

session2:


scott@O9I.US.ORACLE.COM> select count(*) from scott.emp;
select count(*) from scott.emp
*
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在

可见,通过角色授权并未立即生效, 我们将session2断开重新登陆


scott@O9I.US.ORACLE.COM> disconnect
从Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production中断开
system@O9I.US.ORACLE.COM> connect testpriv/testpriv
已连接。
scott@O9I.US.ORACLE.COM> select count(*) from scott.emp;

COUNT(*)
----------
14

重新登陆后,通过角色授权生效了, 那么撤销授权呢?
session1:


system@O9I.US.ORACLE.COM> revoke testprivrole from testpriv;

撤销成功。


session2:

scott@O9I.US.ORACLE.COM> select count(*) from scott.emp;

COUNT(*)
----------
14


可见,即使是撤销角色,也要等到下次登陆才能生效。

再来看看,如果撤销对角色的授权的情况:

session1:


system@O9I.US.ORACLE.COM> revoke select on scott.emp from testprivrole;

撤销成功。

session2:


scott@O9I.US.ORACLE.COM> select count(*) from scott.emp;
select count(*) from scott.emp
*
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在

结论: 授予权限(privileges)总是立即生效的(无论授予用户还是角色),给用户授予角色要等到下次登陆才能生效。

Technorati Tags: , ,

(需要引用, 请注明出处: http://oldwain.itpub.net)

oldwain 发表于:2006.05.21 00:29 ::分类: ( Oracle ) ::阅读:(2578次) :: 评论 (1) ::收藏此页到365Key
re: itpub论坛回复: 授权何时生效 [回复]

smile,记住了

byfree 评论于: 2007.03.13 15:46

发表评论
标题

在此添加评论
表情符号: smile laughing tongue angry crying sad wassat wink

称呼

邮箱地址(可选)

个人主页(可选)

 authimage


自我介绍
切换风格
新闻聚合
博客日历
文章归档...
最新发表...
最新评论...
最多阅读文章...
最多评论文章...
博客统计...
Blog信息
赞助商
网站链接...
其它资源
我的网摘...