1. 程式人生 > >基於角色的訪問控制RBAC的mysql表設計

基於角色的訪問控制RBAC的mysql表設計

一、使用者角色表,用於儲存角色id和角色名稱,表結構如下:

create table roles(
	role_id int unsigned not null auto_increment,
	role_name varchar(50) not null,
	primary key (role_id)
);

二、許可權表,儲存許可權id和許可權描述,表結構如下:
create table permissions(
	perm_id int unsigned not null auto_increment,
	perm_desc varchar(50) not null,
	primary key (perm_id)
);
三、角色與許可權關聯表,用於儲存角色id和許可權id的關聯關係,結構如下:
create table role_perm(
	role_id int unsigned not null,
	perm_id int unsigned not null
);
四、使用者與角色關聯表,用於儲存使用者id和角色id的對應關係,結構如下:
create table user_role(
	user_id int unsigned not null,
	role_id int unsigned not null
);

通過這樣的表設計,可以新增任意個角色和許可權。同時,使用者可以有一個或多個角色,邏輯程式碼就不貼出來了。