Skip to content

Commit dcbd601

Browse files
committed
initial rbac schema
1 parent 9946b62 commit dcbd601

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ A collection of sample databases for PostgreSQL.
1010
* Pagila - Movie rental database with actors, ratings, payments, etc.
1111
* USDA - food database
1212
* World - city, country, language for the world
13+
* Role Based Access Control - authentication solution

role-based-access-control/rbac.sql

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Create Tables
3+
*/
4+
drop table rbac_permissions, rbac_rolepermissions, rbac_roles, rbac_userroles;
5+
6+
create table if not exists rbac_permissions (
7+
id serial primary key,
8+
lft integer not null,
9+
rght integer not null,
10+
title text not null,
11+
description text not null
12+
);
13+
create index on rbac_permissions (lft);
14+
create index on rbac_permissions (rght);
15+
create index on rbac_permissions (title);
16+
17+
create table if not exists rbac_rolepermissions (
18+
role_id integer not null,
19+
permission_id integer not null,
20+
assignment_date timestamptz not null,
21+
primary key (role_id, permission_id)
22+
);
23+
24+
create table if not exists rbac_roles (
25+
id serial primary key,
26+
lft integer not null,
27+
rght integer not null,
28+
title varchar not null,
29+
description text not null
30+
);
31+
create index on rbac_roles (lft);
32+
create index on rbac_roles (rght);
33+
create index on rbac_roles (title);
34+
35+
create table if not exists rbac_userroles (
36+
user_id integer not null,
37+
role_id integer not null,
38+
assignment_date timestamptz not null,
39+
primary key (user_id, role_id)
40+
);
41+
42+
/*
43+
* Insert Initial Table Data
44+
*/
45+
insert into rbac_permissions (id, lft, rght, title, description)
46+
values (1, 0, 1, 'root', 'root');
47+
48+
insert into rbac_rolepermissions (role_id, permission_id, assignment_date)
49+
values (1, 1, current_timestamp);
50+
51+
insert into rbac_roles (id, lft, rght, title, description)
52+
values (1, 0, 1, 'root', 'root');
53+
54+
insert into rbac_userroles (user_id, Role_id, assignment_date)
55+
values (1, 1, current_timestamp);

role-based-access-control/readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Role Based Access Control
2+
3+
An implementation of [NIST level 2 RBAC](http://csrc.nist.gov/groups/SNS/rbac/)
4+
Hierarchical RBAC
5+
6+
Work in progress, contributions welcome
Binary file not shown.

0 commit comments

Comments
 (0)