角色及其权限的管理之一

在实际的生成当中,更多的是创建角色,然后把角色的权限授予给用户,进行用户权限的管理,
而不直接把数据库对象的访问等权限直接授予给用户。使用角色管理对象与用户权限,更方便。
一般的权限授权思路为:数据库对象(表、视图之类)---(权限授给)----角色----(权限授给)----用户:

---创建普通组wruser(不设置角色密码

sys@PROD>create role wruser;

Role created.

sys@PROD>

---删除角色:

sys@PROD>drop role wruser;

Role dropped.

---把组权限授予给用户:

sys@PROD>grant create session to wruser;

Grant succeeded.

 

sys@PROD>grant wruser to suxing,scott;

Grant succeeded.

 

---suxing用户查看SYS用户的mytable表:

suxing@PROD>select * from mytable;

select * from mytable

              *

ERROR at line 1:

ORA-00942: table or view does not exist

 

suxing@PROD>select * from sys.mytable; 

        ID NAME       CREATED

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

     13125 yuuu       09-NOV-16

     13126 hhss       09-NOV-16

     13127 ssuu       09-NOV-16

--Scott用户查看SYS用户的mytable表:

scott@PROD>select * from sys.mytable;

        ID NAME       CREATED

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

     13125 yuuu       09-NOV-16

     13126 hhss       09-NOV-16

     13127 ssuu       09-NOV-16

--hr用户查看SYS用户的mytable表:

hr@PROD>select * from sys.mytable;

select * from sys.mytable

                  *

ERROR at line 1:

ORA-00942: table or view does not exist

#经过3个不同用户对SYS用户对表mytable的查询,可以看到不在角色wruser里的用户是没有权限查询该表的数据。

 

---尝试使用授予角色wruser权限的suxingScott用户进行对表各插入一条数据:

--使用用户suxingSYS用户的表mytable插入一条数据并查看新数据:

suxing@PROD>insert into sys.mytable values(13128,'ttww',sysdate);

1 row created.

suxing@PROD>commit;

Commit complete.

#可知有权限插入数据并成功写入一条数据。

suxing@PROD>

suxing@PROD>select * from sys.mytable;

        ID NAME       CREATED

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

     13125 yuuu       2016-11-09 15:04:21

     13126 hhss       2016-11-09 15:04:53

     13127 ssuu       2016-11-09 16:13:37

     13128 ttww       2016-11-09 23:00:31

 

--使用用户ScottSYS用户的表mytable插入一条数据并查看新数据:

scott@PROD>insert into sys.mytable values(13129,'wwrr',sysdate);

1 row created.

scott@PROD>commit;

Commit complete.

 

scott@PROD>select * from sys.mytable;

        ID NAME       CREATED

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

     13125 yuuu       2016-11-09 15:04:21

     13126 hhss       2016-11-09 15:04:53

     13129 wwrr       2016-11-09 23:18:49

     13127 ssuu       2016-11-09 16:13:37

     13128 ttww       2016-11-09 23:00:31

从上述的测试,可以知道,只要把某个用户的表访问权限授予给某个角色,
然后把某个角色的权限授予给某些用户,那么用户就有访问那些表的权限。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31392094/viewspace-2128204/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31392094/viewspace-2128204/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值