温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

4、Ora_Sec_创建和管理角色

发布时间:2020-07-24 18:23:06 来源:网络 阅读:421 作者:PengChonggui 栏目:数据库

创建和管理角色

角色是一组系统权限或对象权限,可以作为一个单元来授予或撤销,可以在会话中临时激活或禁用已经授予的权限。

1、创建角色并授予权限

CREATEROLE rolename;

 

案例:

SQL>createrole hr_junior;

SQL>grantcreate session to hr_junior;

SQL>grant  select on hr.regions to hr_junior;

SQL>grantselect on  hr.locations to hr_junior;

SQL>grantselect on hr.countries to hr_junior;

SQL>grantselect on hr.job_history to hr_junior;

SQL>grantselect on hr.departments to hr_junior;

SQL>grantselect on hr.jobs to hr_junior;

SQL>grantselect on hr.employees to hr_junior;

 

 

SQL>createrole hr_senior;

SQL>granthr_junior to hr_senior with admin option;

SQL>grantinsert, update, delete on hr.employees to hr_senior;

SQL>grantinsert, update, delete on hr.job_history to hr_senior;

 

 

SQL>createrole hr_manager;

SQL>granthr_senior to hr_manager with admin option;

SQL>grantall on hr.regions to hr_manager;

SQL>grantall on hr.locations to hr_manager;

SQL>grantall on hr.countries to hr_manager;

SQL>grantall on hr.departments to hr_manager;

SQL>grantall on hr.job_history to hr_manager;

SQL>grantall on hr.jobs to hr_manager;

SQL>grantall on hr.employees to hr_manager;

 

 

SQL>granthr_manager to scott;

SQL>granthr_junior to peenboo;

 

2、预定义的角色

Oracle数据库中,至少有50个预定义角色,每个DBA必须熟悉一下角色:

  1. CONNECT   (连接) --用于向后兼容,在11g中仅有CREATE SESSION权限。

  2. RESOURCE 也是用于向后兼容,此角色可以创建数据库对象(如表)和过程对象(如pl/sql过程)。该角色还包括UNLIMITED     TABLESPACE权限。

  3. DBA 拥有大多数系统权限,以及多个对象权限和角色,任何被授予DBA权限的用户几乎可以管理数据库的所有方面(启动和关闭除外)。

  4. SELECT_CATALOG_ROLE     拥有针对数据字典对象的2000多个对象权限,但没有系统权限或针对用户的权限。这对新管理员有用,这些人必须监视数据库并报告数据库情况,但看不到用户数据。

  5. SCHEDUALER_ADMIN  拥有用于管理调度服务的调度程序作业所需的系统权限。

  6. PUBLIC  此角色始终授予每个数据库用户账户。如果将某个权限授予PUBLIC,则该权限授予所有用户。

 

   SQL>GRANT select onhr.regions  to public;   --所有用户有权查询hr.regions

 

 

3、启用角色

 

SQL>select* from dba_role_privs where grantee = 'PEENBOO';

--查看已为PEENBOO授予了什么角色

 

SQL>alter user peenboo default role none;    --更改默认行为

--peenboo登录时,将不启用任何角色

 

SQL>grantconnect to peenboo;

SQL>alteruser peenboo default role connect;

SQL>select* from dba_role_privs where grantee= 'PEENBOO';

 

在应用程序中,可以嵌入软件命令来启用 HR_JUNIOR 角色。在会话中启用此角色的基本命令为:

SET  ROLE  rolename;

 

为了安全考虑,可以使用以下语法创建角色:

CREATEROLE  rolename  IDENTIFIED USING  procedure_name;

--只能在运行 procedure_name 命名的PL/SQL过程来启用此角色。此过程可以执行任意多次的检查。



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI