美文网首页
权限管理

权限管理

作者: 个人精进成长营 | 来源:发表于2021-06-30 08:34 被阅读0次

1:权限的分类

  什么是权限?

  ORACLE的权限由系统权限、对象权限组成。

系统权限:是指对数据库系统及数据结构的操作权,例如创建/删除用户、表、同义词、索引等等,视图:dba_sys_privs

  对象权限

  是指用户对数据的操作权,如查询、更新、插入、删除、完整性约束等等,视图:dba_tab_privs

1) 系统权限

  系统权限的授予命令为GRANT,例如把创建任何表视图的权限授予weisi用户:

      GRANT create any view TO weisi;

      系统权限的回收命令为REVOKE,例如将create any view 权限从weisi用户手中收回:

      REVOKE create any view FROM weisi;

      select * from dba_sys_privs;

      select * from user_sys_privs;

2) 对象权限

每种类型的实体有与之相关的实体权限。

授予实体权限的命令举例(将EMP表上的Select和Insert权限授给weisi):

GRANT select,insert ON emp TO weisi;

回收实体权限的命令举例(将EMP表上的Select权限从weisi手中回收):

REVOKE select ON emp FROM weisi;

 3) with admin option和with grant option的区别

  3.1 with admin option 用于系统权限授权,with grant option 用于对象授权。

      create user wzx identified by wzx;

      select username,account_status,expiry_Date from dba_users;

      select * from dba_tab_privs where grantee='WZX';      --查看WZX用户拥有哪些对象权限

      grant  connect,resource to wzx with admin option;

   create user weisi identified by weisi;

      grant connect,resource to weisi;

  3.2 给一个用户授予系统权限带上with admin option 时,此用户可把此系统权限授予其他用户或角色,

      但收回这个用户的系统权限时,这个用户已经授予其他用户或角色的此系统权限不会因传播无效,如授予A系统权限create session with admin option,然后A又把create session权限授予B,但管理员收回A的create session权限时,B依然拥有create session的权限,但管理员可以显式收回B create session的权限,即直接revoke create session from B. 而with grant option用于对象授权时,被授予的用户也可把此对象权限授予其他用户或角色,不同的是但管理员收回用with grant option授权的用户对象权限时,权限会因传播而失效,如:grant select on 表名 to A with grant option;,A用户把此权限授予B,但管理员收回A的权限时,B的权限也会失效,但管理员不可以直接收回B的SELECT ON TABLE 权限。  执行授权语句报错(ora-01031,ora-01929)时,可参考一下。

      撤消带有admin option 的system privileges 时,连带的权限将保留

2、常用语句

1)、查看数据库里所用户各自拥的角色:

  select * from (select distinct connect_by_root grantee username,granted_role,admin_option

        from dba_role_privs

connect by prior granted_role =grantee ) a

where exists (select 1 from dba_users b where b.username=a.username)

        order by 1,2 ;

  2)、查看数据库所用户的系统权限:

          select d.username,d.privilege from

    (select a.username,b.privilege from

    (select distinct connect_by_root grantee username,granted_role

from dba_role_privs

connect by prior granted_role =grantee) a,

(select grantee,privilege from dba_sys_privs) b

where a.granted_role=b.grantee

union

select grantee,privilege from dba_sys_privs) d

where exists((select 1 from dba_users c where d.username=c.username))

order by 1,2;

3)、查看数据库所用户的表权限

select d.username,d.privilege,d.owner,d.table_name from

(select a.username,b.privilege,b.owner,b.table_name from

(select distinct connect_by_root grantee username,granted_role

from dba_role_privs

connect by prior granted_role =grantee) a,

(select grantee,owner,table_name,privilege from dba_tab_privs) b

where a.granted_role=b.grantee

union

select grantee,privilege,owner,table_name from dba_tab_privs) d

where exists((select 1 from dba_users c where d.username=c.username))

order by 1,2;

4)、如何查看拥DBA角色的用户?

常规做法,一般是直接查询DBA_ROLE_PRIVS视图。查询语句如下:

select grantee,granted_role from dba_role_privs where granted_role='DBA';

这会漏掉用户,测试如下:

正确的查询应如下语句查询:

select * from (select distinct connect_by_root grantee username,granted_role

from dba_role_privs

connect by prior granted_role =grantee ) a

where a.granted_role='DBA';

5)、查看拥SELECT ANY TABLE权限的用户

对于授予角色的,看看都谁查询所表的权限

select distinct rp.grantee from dba_role_privs rp ,dba_sys_privs sp

where rp.granted_role = sp.grantee

and sp.privilege like 'SELECT ANY TABLE%'

6)、查看用户有用的对象权限

select * from dba_tab_privs where grantee='WZX'; 

相关文章

网友评论

      本文标题:权限管理

      本文链接:https://www.haomeiwen.com/subject/ubilultx.html