2009-08-19 44 views
73

我需要查看Oracle數據庫上的所有授權。如何列出用戶收到的所有贈款?

我用蟾蜍功能比較模式,但它並沒有顯示不是Temptable補助等。所以是我的問題:

如何列出一個Oracle數據庫的所有授權?

回答

99

如果你需要的不僅僅是直接表補助更多(例如,通過角色授予,系統特權,比如選擇任何表等),這裏有一些額外的查詢:

系統權限的用戶:

SELECT PRIVILEGE 
    FROM sys.dba_sys_privs 
WHERE grantee = <theUser> 
UNION 
SELECT PRIVILEGE 
    FROM dba_role_privs rp JOIN role_sys_privs rsp ON (rp.granted_role = rsp.role) 
WHERE rp.grantee = <theUser> 
ORDER BY 1; 

直接授予表/視圖:

SELECT owner, table_name, select_priv, insert_priv, delete_priv, update_priv, references_priv, alter_priv, index_priv 
    FROM table_privileges 
WHERE grantee = <theUser> 
ORDER BY owner, table_name; 

間接補助表/視圖:

SELECT DISTINCT owner, table_name, PRIVILEGE 
    FROM dba_role_privs rp JOIN role_tab_privs rtp ON (rp.granted_role = rtp.role) 
WHERE rp.grantee = <theUser> 
ORDER BY owner, table_name; 
+1

您可能沒有權限查看sys.dba_sys_privs表。 – Hannes 2014-03-24 10:04:23

+1

絕對正確。查看你的DBA。如果他們拒絕,他們可能會對安全問題合法化。看到這些視圖的內容會給用戶提供他們無法擁有的信息。 – DCookie 2014-03-26 16:26:13

+2

將'role_role_privs'表加入'role_role_privs'表,然後'CONNECT BY PRIOR granted_role = role'將遞歸到可傳遞的角色權限中將會很有趣...... – 2014-10-09 08:25:51

27

假設要列出所有對象特定的用戶已經收到補助

select * from all_tab_privs_recd where grantee = 'your user' 

這將不返回用戶所擁有的對象。如果您需要這些,請使用all_tab_privs視圖。

4
select distinct 'GRANT '||privilege||' ON '||OWNER||'.'||TABLE_NAME||' TO '||RP.GRANTEE 
from DBA_ROLE_PRIVS RP join ROLE_TAB_PRIVS RTP 
on (RP.GRANTED_ROLE = RTP.role) 
where (OWNER in ('YOUR USER') --Change User Name 
    OR RP.GRANTEE in ('YOUR USER')) --Change User Name 
and RP.GRANTEE not in ('SYS', 'SYSTEM') 
; 
+5

有些解釋會幫助這個答案,因爲其他人來找到它時。 – 2012-09-28 08:56:00

12

對不起球員,但是從all_tab_privs_recd選擇,其中持證=「用戶」不會,如果你從不同的(讓我們說,SYS)用戶運行選擇給任何輸出,除了公共資助和當前用戶授權。由於文件說,

ALL_TAB_PRIVS_RECD介紹以下類型的補助:

Object grants for which the current user is the grantee 
Object grants for which an enabled role or PUBLIC is the grantee 

所以,如果你是一個DBA和希望列出所有對象授予特定(不SYS本身)用戶,您不能使用該系統視圖。

在這種情況下,您必須執行更復雜的查詢。這裏是一個蟾蜍取(跟蹤)選擇所有對象授予特定用戶:

select tpm.name privilege, 
     decode(mod(oa.option$,2), 1, 'YES', 'NO') grantable, 
     ue.name grantee, 
     ur.name grantor, 
     u.name owner, 
     decode(o.TYPE#, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER', 
         4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 
         7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE', 
         11, 'PACKAGE BODY', 12, 'TRIGGER', 
         13, 'TYPE', 14, 'TYPE BODY', 
         19, 'TABLE PARTITION', 20, 'INDEX PARTITION', 21, 'LOB', 
         22, 'LIBRARY', 23, 'DIRECTORY', 24, 'QUEUE', 
         28, 'JAVA SOURCE', 29, 'JAVA CLASS', 30, 'JAVA RESOURCE', 
         32, 'INDEXTYPE', 33, 'OPERATOR', 
         34, 'TABLE SUBPARTITION', 35, 'INDEX SUBPARTITION', 
         40, 'LOB PARTITION', 41, 'LOB SUBPARTITION', 
         42, 'MATERIALIZED VIEW', 
         43, 'DIMENSION', 
         44, 'CONTEXT', 46, 'RULE SET', 47, 'RESOURCE PLAN', 
         66, 'JOB', 67, 'PROGRAM', 74, 'SCHEDULE', 
         48, 'CONSUMER GROUP', 
         51, 'SUBSCRIPTION', 52, 'LOCATION', 
         55, 'XML SCHEMA', 56, 'JAVA DATA', 
         57, 'EDITION', 59, 'RULE', 
         62, 'EVALUATION CONTEXT', 
         'UNDEFINED') object_type, 
     o.name object_name, 
     '' column_name 
     from sys.objauth$ oa, sys.obj$ o, sys.user$ u, sys.user$ ur, sys.user$ ue, 
      table_privilege_map tpm 
     where oa.obj# = o.obj# 
      and oa.grantor# = ur.user# 
      and oa.grantee# = ue.user# 
      and oa.col# is null 
      and oa.privilege# = tpm.privilege 
      and u.user# = o.owner# 
      and o.TYPE# in (2, 4, 6, 9, 7, 8, 42, 23, 22, 13, 33, 32, 66, 67, 74, 57) 
    and ue.name = 'your user' 
    and bitand (o.flags, 128) = 0 
union all -- column level grants 
select tpm.name privilege, 
     decode(mod(oa.option$,2), 1, 'YES', 'NO') grantable, 
     ue.name grantee, 
     ur.name grantor, 
     u.name owner, 
     decode(o.TYPE#, 2, 'TABLE', 4, 'VIEW', 42, 'MATERIALIZED VIEW') object_type, 
     o.name object_name, 
     c.name column_name 
from sys.objauth$ oa, sys.obj$ o, sys.user$ u, sys.user$ ur, sys.user$ ue, 
    sys.col$ c, table_privilege_map tpm 
where oa.obj# = o.obj# 
    and oa.grantor# = ur.user# 
    and oa.grantee# = ue.user# 
    and oa.obj# = c.obj# 
    and oa.col# = c.col# 
    and bitand(c.property, 32) = 0 /* not hidden column */ 
    and oa.col# is not null 
    and oa.privilege# = tpm.privilege 
    and u.user# = o.owner# 
    and o.TYPE# in (2, 4, 42) 
    and ue.name = 'your user' 
    and bitand (o.flags, 128) = 0; 

這將列出你的(指定)用戶的所有對象權限(包括列補助金)。如果您不希望列級別授權,則刪除以'union'子句開頭的所有選擇部分。

UPD:學習的文檔我發現了另一個觀點,即列出了更簡單的方式,所有補助:

select * from DBA_TAB_PRIVS where grantee = 'your user'; 

請記住,有在Oracle中沒有 DBA_TAB_PRIVS_RECD視圖。

7

最全面,最可靠的方法,我知道是仍可以使用DBMS_METADATA

select dbms_metadata.get_granted_ddl('SYSTEM_GRANT', :username) from dual; 
select dbms_metadata.get_granted_ddl('OBJECT_GRANT', :username) from dual; 
select dbms_metadata.get_granted_ddl('ROLE_GRANT', :username) from dual; 

有趣的答案,但。

相關問題