实验二:安全性语言实验

实验二:安全性语言实验

实验目的:
掌握自主存取控制权限的定义和维护方法

实验内容:
一、定义用户、角色
二、分配权限给用户、角色,回收权限
三、以相应的用户名登录数据库、验证权限分配是否正确

实验过程与要求:
1.选择一个应用场景,使用自主存取控制截止设计权限分配,可以采用两种方案
方案一:采用SYSTEM超级用户登录数据库,完成所有权限分配工作,然后用相应用户名登录数据可以验证权限分配的正确性
方案二:采用SYSTEM用户登录数据库创建三个部门经理用户,并分配相应的权限,然后分别用三个经理用户名登录数据库,创建相应部门的USER、ROLE,并分配相应权限。

实验重点与难点
实验重点:定义角色,分配权限和回收权限
实验难点:实验方案二实小权限的再分配和回收

实验场景:
设有一个企业,包括采购、销售和客户管理等三个部门,采购部门经理David,采购员Jeffery,销售部门经理Tom,销售员Jane;客户管理部门尽力Kathy,职员Mike。该企业一个信息系统覆盖采购、销售和客户管理等三个部门的业务,起数据库模式为TPCH的Sales。针对此应用场景,使用自主存取控制机制设计一个具体的权限分配方案
实验过程:

1.创建客户
(1)为采购、销售和客户管理等三个部门的经理创建用户标识,要求具有创建用户或角色的权利。
(2)为采购、销售和客户管理等三个部门的职员创建用户标识和用户口令
2.创建角色并分配权限
(1)为每个部门分别创建一个查询角色,并分配相应的查询权限。
(2)为各个部门分别创建一个职员角色,对本部门信息具有查看、插入权限。
(3)为各部门创建一个经理角色,相应角色对本部门的信息具有完全控制权限,对其他部门的信息具有查询权。经理有权给本部门职员分配权限。
3.给用户分配权限
(1)给各部门经理分配权限
(2)给各部门职员分配权限
4.回收角色或用户权限
(1)回收客户经理角色的销售信息查看权
(2)回收Mike的客户部门职员权限
5.验证权限分配的正确性
(1)以David用户名登录数据库,验证采购经理的权限。
(2)回收Mike的客户部门职员权限

参考:

1.创建客户
(1).为采购、销售和客户管理等三个部门的经理创建用户标识,要求具有创建用户或角色的权利
 create user 'david'@'localhost' identified by 'david'; 
create user 'tom'@'localhost' identified by 'tom'; 
create user 'kathy'@'localhost' identified by 'kathy'; 
----------------------------------------------------
grant create on *.* to 'david'@localhost;
grant create on *.* to 'tom'@localhost;
grant create on *.* to 'kathy'@localhost;
----------------------------------------------------
(2).为采购、销售和客户管理等三个部门的职员创建用户标识和用户口令
create user 'jeffery'@'localhost' identified by 'jeffery'; 
create user 'jane'@'localhost' identified by 'jane'; 
create user 'mike'@'localhost' identified by 'mike'; 
----------------------------------------------------
2.创建角色并分配权限
(1).为每个部门分别创建一个查询角色,并分配相应的查询权限
create role 'PurchaseQueryRole';
create role 'SaleQueryRole';
create role 'CustomerQueryRole';
----------------------------------------------------
 grant select on sales.part to PurchaseQueryRole;
 grant select on sales.supplier to PurchaseQueryRole;
 grant select on sales.partsupp to PurchaseQueryRole;
-----------------------------------------------------
 grant select on sales.orders to SaleQueryRole;
 grant select on sales.lineitem  to SaleQueryRole;
----------------------------------------------------
 grant select on sales.customer to CustomerQueryRole;
 grant select on sales.nation to CustomerQueryRole;
 grant select on sales.region to CustomerQueryRole;2)为各个部门分别创建一个职员角色,对本部门信息具有查看、插入权限。
create role 'PurchaseEmployeeRole';
create role 'SaleEmployeeRole';
create role 'CustomerEmployeeRole';
------------------------------------------------------------
 grant select,insert on sales.part to PurchaseEmployeeRole;
 grant select,insert on sales.supplier to PurchaseEmployeeRole;
 grant select,insert on sales.partsupp to PurchaseEmployeeRole;
----------------------------------------------------------
 grant select,insert on sales.orders to SaleEmployeeRole;
 grant select,insert on sales.lineitem to SaleEmployeeRole;
---------------------------------------------------------
 grant select,insert on sales.customer to CustomerEmployeeRole;
 grant select,insert on sales.nation to CustomerEmployeeRole;
 grant select,insert on sales.region to CustomerEmployeeRole;3)为各部门创建一个经理角色,相应角色对本部门的信息具有完全控制权限,
对其他部门的信息具有查询权。【经理有权给本部门职员分配权限】。
create role 'PurchaseManagerRole';
create role 'SaleManagerRole';
create role 'CustomerManagerRole';
-----------------------------------------------------------
grant all on sales.part to 'PurchaseManagerRole';
grant all on  sales.supplier to 'PurchaseManagerRole';
grant all on  sales.partsupp to 'PurchaseManagerRole';
----------------------------------------------------
grant all on sales.orders to 'SaleManagerRole';
grant all on sales.lineitem to  'SaleManagerRole';
----------------------------------------------------
grant all on sales.customer to 'CustomerManagerRole';
grant all on sales.nation to 'CustomerManagerRole';
grant all on sales.region to 'CustomerManagerRole';
------------------------------------------------------------
grant  'SaleQueryRole' to 'PurchaseManagerRole';
grant 'CustomerQueryRole' to 'PurchaseManagerRole';
----------------------------------------------------
grant  'PurchaseQueryRole' to 'SaleManagerRole';
grant   'CustomerQueryRole' to'SaleManagerRole';
----------------------------------------------------
grant 'PurchaseQueryRole'  to 'CustomerManagerRole';
grant 'SaleQueryRole'  to 'CustomerManagerRole';
-----------------------------------------------------------

3.给用户分配权限
(1)给各部门经理分配权限
grant 'PurchaseManagerRole' to 'david'@localhost;
grant 'SaleManagerRole' to 'tom'@localhost;
grant 'CustomerManagerRole' to 'kathy'@localhost;
----------------------------------------------------2)给各部门职员分配权限
grant PurchaseEmployeeRole to 'jeffery'@localhost;
grant SaleEmployeeRole to 'jane'@localhost;
grant CustomerEmployeeRole to 'mike'@localhost;
----------------------------------------------------
激活:
set default role all to david;
set default role all to tom
set default role all to kathy;
set default role all to jeffery;
set default role all to jane
set default role all to mike;

自动激活角色:
show global variables like 'activate_all_roles_on_login';
set global activate_all_roles_on_login=ON;
----------------------------------------------------
4.回收角色或用户权限
(1)回收客户经理角色的销售信息查看权
revoke  'SaleQueryRole'   from 'CustomerManagerRole';2)回收Mike的客户部门职员权限
revoke 'CustomerEmployeeRole' from 'mike';
 

猜你喜欢

转载自blog.csdn.net/weixin_46220576/article/details/124322727