標籤:syn 案例 對象許可權 建表 消失 connect sql命令 not tab
oracle的使用者權限和角色系統許可權
定義:指特定類型的sql命令的權利。
常見的有:
create session 串連資料庫
create table 建表
create view 建視
create public synonym 建同義字
create procedure 建過程、函數、包
create trigger 建觸發器
create cluster 建簇
如何使用select來查詢有哪些系統許可權
select * from system_privilege_map order by name;
案例:
1.建立兩個使用者並指定密碼
connect system/orcl;
create user ken identified by ken;
create user tom identified by tom;
2.給ken 授予會話,建表,建視圖的許可權
grant create session to ken with admin option【有with admin option】
grant create table to ken with admin option【有with admin option】
grant create view to ken 【無with admin option】
3.用ken 給tom賦予相同的許可權
connect ken/ken;
grant create session to tom with admin option
grant create table to tom with admin option
grant create view to tom 【報錯!!!!!】
------------------------------
報錯的原因:
許可權的流程:
system =》 ken =》 tom
如何能夠賦予他人許可權,除system擁有超級許可權外,其他使用者想要繼承賦予他人
許可權的能力,必須在system賦予許可權時加入with admin option,才能有賦予許可權
的能力,如上所示在system賦予ken許可權時只有建立視圖沒有加入with adminoption,所以他不能夠賦予他人許可權,所以報錯。
回收系統許可權
使用system回收ken [create session 許可權]
基本文法
revoke 許可權名稱 from 使用者名稱
例:
revoke create session from ken;
問題:
在回收ken的許可權之後,是否也回收曾經是被ken賦予許可權的tom的許可權。
答:不是,只回收指定的許可權
對象許可權
定義:指訪問其它方案對象的權利
oracle 給我們提供17種對象許可權,可以通過如下指令,來查看(dba 角色)
select distinct privilege from dba_tab_privs;
基本文法:
grant 對象許可權 on 方案.資料對象 to 使用者[with grant option]
grant 對象許可權 on 方案.資料對象 to 角色(角色不能擁有賦予許可權的權利)
案例:
1.monkey使用者要操作scott.emp表,則必須賦予相對應的對象許可權
(1)希望monkey可以查詢到scott.emp表中的資料?
使用scott或者system/sys使用者操作
grant select on scott.emp to monkey;
(2)希望monkey可以修改到scott.emp表中的資料?
grant update on scott.emp to monkey;
(3)希望monkey可以刪除到scott.emp表中的資料?
grant delete on scott.emp to monkey;
(4)有沒有簡單的方法,一次性賦予所有權利?
grant all on scott.emp to monkey;
2.授予moneky使用者修改scott.emp表的結構 許可權
grant alter on scott.emp to monkey;
3.授予execute許可權(概念)
如果使用者想要執行其他方案的包/過程/函數,則需要execute許可權。
4.授予monkey使用者在scott.emp表中建立索引的許可權?
connect scott/tiger;
grant index on scott.emp to monkey;
回收對象許可權:
基本文法:
revoke 對象許可權 on 方案.資料對象 from 使用者
對象許可權是級聯回收:因為引用的一個對象,一旦對象消失,就失去了引用。
scott =>>>>> blake =>>>>> jones
system操作:
create user blake identified by blake;
create user jones identified by jones;
grant create session to blake;
grant create session to jones;
使用scott登陸,授予blake查詢emp表許可權,然後
再用blake授予jones許可權,然後查詢emp表
scott操作
grant select on emp to blake;
blake操作
grant select on scott.emp to jones;
此時,兩張表都可查詢emp表
注意:
scott操作
revoke select on emp from blake; --回收許可權
此時,兩張表都不可查詢emp表
角色
定義:角色是一組許可權的集合,目的是為了簡化對許可權的管理,從而達到簡單的對使用者的管理。
角色的分類:
(1)預定義角色:
oracle提供了33種預定義角色,常用的是(connect,dba,resource);
?如何知道某個角色擁有怎樣的許可權
select * from dba_sys_privs where grantee = ‘DBA’;
?如何知道某個使用者擁有什麼樣的許可權
select * from dba_role_privs where grantee = ‘使用者名稱’;
註:角色名稱一定大寫
(2)自訂角色:
基本文法:
不帶驗證:
create role 角色名稱 not identified;
帶驗證:
create role 角色名稱 identified by 密碼;
案例:
建立角色:
create role myrole not identified;
賦予角色權利:
系統許可權:
grant create session to myrole;
對象許可權(scott.emp):
grant select on scott.emp to myrole;
grant insert on scott.emp to myrole;
grant update on scott.emp to myrole;
賦予使用者角色:
create user jerry identified by jerry;
grant myrole to jerry;
回收角色:
drop role mylore;
範圍:角色既可以包含系統角色,也可以包含自訂角色。
oracle的使用者權限和角色