Skip to content

Commit 6368a35

Browse files
committed
feat(core): add evers configuration for auditing
1 parent 32be8e0 commit 6368a35

File tree

11 files changed

+331
-66
lines changed

11 files changed

+331
-66
lines changed

schema.sql

Lines changed: 221 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,65 @@
11

2-
alter table jwt_tokens
2+
alter table jwt_tokens
33
drop constraint FKhy6n4wirmw0ryw2wdmy9cx2mn;
44

5-
alter table roles_permissions
5+
ALTER TABLE jwt_tokens_aud
6+
DROP CONSTRAINT FK6jp64i8dvuahfik6kui8prbjd;
7+
8+
ALTER TABLE permissions_aud
9+
DROP CONSTRAINT FKbcjh1knyfnk51nv2cllrct4iw;
10+
11+
ALTER TABLE roles_aud
12+
DROP CONSTRAINT FKt0mnl3rej2p0h9gxnbalf2kdd;
13+
14+
alter table roles_permissions
615
drop constraint FKeqt383nibym26cjj8we4uar8h;
716

8-
alter table roles_permissions
17+
alter table roles_permissions
918
drop constraint FKqi9odri6c1o81vjox54eedwyh;
1019

11-
alter table users_roles
20+
ALTER TABLE roles_permissions_aud
21+
DROP CONSTRAINT FKnofx22xg9kko3i1geh4jikive;
22+
23+
ALTER TABLE users_aud
24+
DROP CONSTRAINT FKc4vk4tui2la36415jpgm9leoq;
25+
26+
alter table users_roles
1227
drop constraint FKa62j07k5mhgifpp955h37ponj;
1328

14-
alter table users_roles
29+
alter table users_roles
1530
drop constraint FK2o0jvgh89lemvvo17cbqvdxaa;
1631

32+
ALTER TABLE users_roles_aud
33+
DROP CONSTRAINT FKktxqr55ntd0j2i228uj8sq6j9;
34+
1735
drop table if exists jwt_tokens cascade;
1836

37+
DROP TABLE IF EXISTS jwt_tokens_aud CASCADE;
38+
1939
drop table if exists permissions cascade;
2040

41+
DROP TABLE IF EXISTS permissions_aud CASCADE;
42+
43+
DROP TABLE IF EXISTS revinfo CASCADE;
44+
2145
drop table if exists roles cascade;
2246

47+
DROP TABLE IF EXISTS roles_aud CASCADE;
48+
2349
drop table if exists roles_permissions cascade;
2450

51+
DROP TABLE IF EXISTS roles_permissions_aud CASCADE;
52+
2553
drop table if exists users cascade;
2654

55+
DROP TABLE IF EXISTS users_aud CASCADE;
56+
2757
drop table if exists users_roles cascade;
2858

59+
DROP TABLE IF EXISTS users_roles_aud CASCADE;
60+
61+
DROP SEQUENCE hibernate_sequence;
62+
2963
drop sequence sequence_jwt_tokens;
3064

3165
drop sequence sequence_permissions;
@@ -34,6 +68,8 @@
3468

3569
drop sequence sequence_users;
3670

71+
CREATE SEQUENCE hibernate_sequence START 1 INCREMENT 1;
72+
3773
create sequence sequence_jwt_tokens start 1 increment 1;
3874

3975
create sequence sequence_permissions start 1 increment 1;
@@ -43,97 +79,229 @@
4379
create sequence sequence_users start 1 increment 1;
4480

4581
create table jwt_tokens (
46-
id int8 not null,
47-
uuid varchar(255) not null,
48-
version int8,
49-
active boolean not null,
50-
expiration_date timestamp not null,
51-
invalidated boolean not null,
52-
invalidation_date timestamp,
53-
ip_adress varchar(39) not null,
54-
user_id int8,
82+
id int8 not null,
83+
uuid varchar(255) not null,
84+
version int8,
85+
created_by INT8,
86+
created_date TIMESTAMP NOT NULL,
87+
updated_by INT8,
88+
updated_date TIMESTAMP,
89+
active boolean not null,
90+
expiration_date timestamp not null,
91+
invalidated boolean not null,
92+
invalidation_date timestamp,
93+
ip_adress varchar(39) not null,
94+
user_id int8,
5595
primary key (id)
5696
);
5797

98+
CREATE TABLE jwt_tokens_aud (
99+
id INT8 NOT NULL,
100+
rev INT4 NOT NULL,
101+
revtype INT2,
102+
uuid VARCHAR(255),
103+
created_by INT8,
104+
created_date TIMESTAMP,
105+
updated_by INT8,
106+
updated_date TIMESTAMP,
107+
active BOOLEAN,
108+
expiration_date TIMESTAMP,
109+
invalidated BOOLEAN,
110+
invalidation_date TIMESTAMP,
111+
ip_adress VARCHAR(39),
112+
user_id INT8,
113+
PRIMARY KEY (id, rev)
114+
);
115+
58116
create table permissions (
59-
id int8 not null,
60-
uuid varchar(255) not null,
61-
version int8,
62-
name varchar(64) not null,
117+
id int8 not null,
118+
uuid varchar(255) not null,
119+
version int8,
120+
created_by INT8,
121+
created_date TIMESTAMP NOT NULL,
122+
updated_by INT8,
123+
updated_date TIMESTAMP,
124+
name varchar(64) not null,
63125
primary key (id)
64126
);
65127

128+
CREATE TABLE permissions_aud (
129+
id INT8 NOT NULL,
130+
rev INT4 NOT NULL,
131+
revtype INT2,
132+
uuid VARCHAR(255),
133+
created_by INT8,
134+
created_date TIMESTAMP,
135+
updated_by INT8,
136+
updated_date TIMESTAMP,
137+
name VARCHAR(64),
138+
PRIMARY KEY (id, rev)
139+
);
140+
141+
CREATE TABLE revinfo (
142+
rev INT4 NOT NULL,
143+
revtstmp INT8,
144+
PRIMARY KEY (rev)
145+
);
146+
66147
create table roles (
67-
id int8 not null,
68-
uuid varchar(255) not null,
69-
version int8,
70-
name varchar(64) not null,
148+
id int8 not null,
149+
uuid varchar(255) not null,
150+
version int8,
151+
created_by INT8,
152+
created_date TIMESTAMP NOT NULL,
153+
updated_by INT8,
154+
updated_date TIMESTAMP,
155+
name varchar(64) not null,
71156
primary key (id)
72157
);
73158

159+
CREATE TABLE roles_aud (
160+
id INT8 NOT NULL,
161+
rev INT4 NOT NULL,
162+
revtype INT2,
163+
uuid VARCHAR(255),
164+
created_by INT8,
165+
created_date TIMESTAMP,
166+
updated_by INT8,
167+
updated_date TIMESTAMP,
168+
name VARCHAR(64),
169+
PRIMARY KEY (id, rev)
170+
);
171+
74172
create table roles_permissions (
75173
role_id int8 not null,
76174
permissions_id int8 not null,
77175
primary key (role_id, permissions_id)
78176
);
79177

178+
CREATE TABLE roles_permissions_aud (
179+
rev INT4 NOT NULL,
180+
role_id INT8 NOT NULL,
181+
permissions_id INT8 NOT NULL,
182+
revtype INT2,
183+
PRIMARY KEY (rev, role_id, permissions_id)
184+
);
185+
80186
create table users (
81-
id int8 not null,
82-
uuid varchar(255) not null,
83-
version int8,
84-
email varchar(250) not null,
85-
enabled boolean not null,
86-
expired boolean not null,
87-
first_name varchar(120) not null,
88-
last_name varchar(120) not null,
89-
locked boolean not null,
90-
password varchar(64) not null,
91-
username varchar(250) not null,
187+
id int8 not null,
188+
uuid varchar(255) not null,
189+
version int8,
190+
created_by INT8,
191+
created_date TIMESTAMP NOT NULL,
192+
updated_by INT8,
193+
updated_date TIMESTAMP,
194+
email varchar(250) not null,
195+
enabled boolean not null,
196+
expired boolean not null,
197+
first_name varchar(120) not null,
198+
last_name varchar(120) not null,
199+
locked boolean not null,
200+
password varchar(64) not null,
201+
username varchar(250) not null,
92202
primary key (id)
93203
);
94204

205+
CREATE TABLE users_aud (
206+
id INT8 NOT NULL,
207+
rev INT4 NOT NULL,
208+
revtype INT2,
209+
uuid VARCHAR(255),
210+
created_by INT8,
211+
created_date TIMESTAMP,
212+
updated_by INT8,
213+
updated_date TIMESTAMP,
214+
email VARCHAR(250),
215+
enabled BOOLEAN,
216+
expired BOOLEAN,
217+
first_name VARCHAR(120),
218+
last_name VARCHAR(120),
219+
locked BOOLEAN,
220+
password VARCHAR(64),
221+
username VARCHAR(250),
222+
PRIMARY KEY (id, rev)
223+
);
224+
95225
create table users_roles (
96226
user_id int8 not null,
97227
roles_id int8 not null,
98228
primary key (user_id, roles_id)
99229
);
100230

101-
alter table permissions
231+
CREATE TABLE users_roles_aud (
232+
rev INT4 NOT NULL,
233+
user_id INT8 NOT NULL,
234+
roles_id INT8 NOT NULL,
235+
revtype INT2,
236+
PRIMARY KEY (rev, user_id, roles_id)
237+
);
238+
239+
alter table permissions
102240
add constraint UK_pnvtwliis6p05pn6i3ndjrqt2 unique (name);
103241

104-
alter table roles
242+
alter table roles
105243
add constraint UK_ofx66keruapi6vyqpv6f2or37 unique (name);
106244

107-
alter table roles_permissions
245+
alter table roles_permissions
108246
add constraint UK_oll9subcln0cdjt31bp72a3uv unique (permissions_id);
109247

110-
alter table users
248+
alter table users
111249
add constraint UK_r43af9ap4edm43mmtq01oddj6 unique (username);
112250

113-
alter table users_roles
251+
alter table users_roles
114252
add constraint UK_60loxav507l5mreo05v0im1lq unique (roles_id);
115253

116-
alter table jwt_tokens
117-
add constraint FKhy6n4wirmw0ryw2wdmy9cx2mn
118-
foreign key (user_id)
254+
alter table jwt_tokens
255+
add constraint FKhy6n4wirmw0ryw2wdmy9cx2mn
256+
foreign key (user_id)
119257
references users;
120258

121-
alter table roles_permissions
122-
add constraint FKeqt383nibym26cjj8we4uar8h
123-
foreign key (permissions_id)
259+
ALTER TABLE jwt_tokens_aud
260+
ADD CONSTRAINT FK6jp64i8dvuahfik6kui8prbjd
261+
FOREIGN KEY (rev)
262+
REFERENCES revinfo;
263+
264+
ALTER TABLE permissions_aud
265+
ADD CONSTRAINT FKbcjh1knyfnk51nv2cllrct4iw
266+
FOREIGN KEY (rev)
267+
REFERENCES revinfo;
268+
269+
ALTER TABLE roles_aud
270+
ADD CONSTRAINT FKt0mnl3rej2p0h9gxnbalf2kdd
271+
FOREIGN KEY (rev)
272+
REFERENCES revinfo;
273+
274+
alter table roles_permissions
275+
add constraint FKeqt383nibym26cjj8we4uar8h
276+
foreign key (permissions_id)
124277
references roles;
125278

126-
alter table roles_permissions
127-
add constraint FKqi9odri6c1o81vjox54eedwyh
128-
foreign key (role_id)
279+
alter table roles_permissions
280+
add constraint FKqi9odri6c1o81vjox54eedwyh
281+
foreign key (role_id)
129282
references roles;
130283

131-
alter table users_roles
132-
add constraint FKa62j07k5mhgifpp955h37ponj
133-
foreign key (roles_id)
284+
ALTER TABLE roles_permissions_aud
285+
ADD CONSTRAINT FKnofx22xg9kko3i1geh4jikive
286+
FOREIGN KEY (rev)
287+
REFERENCES revinfo;
288+
289+
ALTER TABLE users_aud
290+
ADD CONSTRAINT FKc4vk4tui2la36415jpgm9leoq
291+
FOREIGN KEY (rev)
292+
REFERENCES revinfo;
293+
294+
alter table users_roles
295+
add constraint FKa62j07k5mhgifpp955h37ponj
296+
foreign key (roles_id)
134297
references roles;
135298

136-
alter table users_roles
137-
add constraint FK2o0jvgh89lemvvo17cbqvdxaa
138-
foreign key (user_id)
299+
alter table users_roles
300+
add constraint FK2o0jvgh89lemvvo17cbqvdxaa
301+
foreign key (user_id)
139302
references users;
303+
304+
ALTER TABLE users_roles_aud
305+
ADD CONSTRAINT FKktxqr55ntd0j2i228uj8sq6j9
306+
FOREIGN KEY (rev)
307+
REFERENCES revinfo;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.shardis.config
2+
3+
import com.shardis.security.support.SecurityUtils
4+
import org.springframework.context.annotation.Bean
5+
import org.springframework.context.annotation.Configuration
6+
import org.springframework.data.domain.AuditorAware
7+
import org.springframework.data.jpa.repository.config.EnableJpaAuditing
8+
9+
@Configuration
10+
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
11+
open class JpaConfig {
12+
13+
@Bean(name = arrayOf("auditorProvider"))
14+
open fun auditorProvider(): AuditorAware<Long?> {
15+
return AuditorAware { SecurityUtils.getLoggedUser()?.userId }
16+
}
17+
}

0 commit comments

Comments
 (0)