Home > Database > Mysql Tutorial > body text

ORACLE中的default role,set role

WBOY
Release: 2016-06-07 15:45:49
Original
1248 people have browsed it

oracle权限体系中有个default role,比较难以理解。下面用实例说明一下作用。 我们可以给某个用户分配一些角色,比如role r1,r2,r3,r4,而其中可以将某些角色比如r1设置为default role,其他的不设置成default role,这样,当该用户登录时,自动具有default

oracle权限体系中有个default role,比较难以理解。下面用实例说明一下作用。

 

我们可以给某个用户分配一些角色,比如role r1,r2,r3,r4,而其中可以将某些角色比如r1设置为default role,其他的不设置成default role,这样,当该用户登录时,自动具有default role中所包含的权限,其他的角色所具有的权限要通过set role 角色来获得。

 

下面我们举个例子:

(1)sys用户作为sysdba登录,创建4个角色:

create role r1;

create role r2 identified by r2;

create role r3 identified by r3;

create role r4 identified by r4;

 

(2)sys用户赋予这四个角色对应的权限:

grant create session to r1;

 

grant select on hr.test to r2;(这里hr.test是我新创建的一个表,里面有ID和name两列)

 

grant update(name) on hr.test to r3;

grant insert on hr.test to r3;

 

grant delete on hr.test to r4;

 

 

(3)sys用户创建一个用户u3

create user u3 identified by u3;

 

(4)将角色r1,r2,r3,r4赋予用户u3

grant r1,r2,r3,r4 to u3;

 

在修改用户u3的默认角色前,r1,r2,r3,r4 角色均为u3的 default role,以u3用户登录,查询、增删改hr.test,都没有问题。

 

(5)现在sys用户修改用户u3的default role,仅将r1作为u3的默认角色:

alter user u3 default role r1;  --此时将覆盖原来的设置,u3 的default role =r1,仅仅有登录权限。

 

(6)用户u3 log off ,然后再log on,进去后发现,

查询、增删改hr.test都不能进行。

 

(7) 用户自己打开role权限

set role r2 identified by r2;

这时执行 select * from hr.test,发现没有问题。增删改不行。

将对应的角色打开:

set role r3 identified by r3;

此时修改和插入记录没有问题,但是select * from hr.test 确发现不行了。证明此时用户所属的角色仅仅是默认角色r1,和刚刚打开的角色r3,而r2被set role r3 identified by r3;覆盖掉了。

 

那要同时有r2,r3,r4的权限怎么办呢?

set role r2 identified by r2,r3 identified by r3,r4 identified by r4。此时就同时对hr.test可以进行查询,增删改了。

 

不过set role 的效果是临时的,只是当前session有效,其他的session无效,当结束当前session后再登录,又只有default role 的权限了。


参看:

oracle 查看 DEFAULT ROLE  谷歌


admin_option 是针对用户的每一个权限或是角色的,默认角色也是如此,在视图dba_role_privs;

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!