-
Notifications
You must be signed in to change notification settings - Fork 1
/
webauth.kt
111 lines (93 loc) · 3.41 KB
/
webauth.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Copyright (c) 2016.
*
* This file is part of ProcessManager.
*
* ProcessManager is free software: you can redistribute it and/or modify it under the terms of version 3 of the
* GNU Lesser General Public License as published by the Free Software Foundation.
*
* ProcessManager is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with ProcessManager. If not,
* see <http://www.gnu.org/licenses/>.
*/
package uk.ac.bournemouth.ac.db.darwin.webauth
import io.github.pdvrieze.kotlinsql.ddl.Database
import io.github.pdvrieze.kotlinsql.ddl.MutableTable
/**
* Code definition of the webauth database.
*/
const val EXTRACONF="ENGINE=InnoDB CHARSET=utf8"
object WebAuthDB: Database(1) {
object users: MutableTable(EXTRACONF) {
val user by VARCHAR("user", 30) { NOT_NULL; BINARY }
val fullname by VARCHAR("fullname", 80)
val alias by VARCHAR("alias", 80)
val password by VARCHAR("password", 40) { BINARY }
val resettoken by VARCHAR("resettoken", 20) { BINARY }
val resettime by DATETIME("resettime")
override fun init() {
PRIMARY_KEY(user)
}
}
object roles: MutableTable(EXTRACONF) {
val role by VARCHAR("role", 30) { NOT_NULL }
val description by VARCHAR("description", 120) { NOT_NULL }
override fun init() {
PRIMARY_KEY(role)
}
}
object user_roles: MutableTable(EXTRACONF) {
val user by VARCHAR("user", 30) { NOT_NULL; BINARY }
val role by VARCHAR("role", 30) { NOT_NULL }
override fun init() {
PRIMARY_KEY(user, role)
FOREIGN_KEY(user).REFERENCES(users.user)
FOREIGN_KEY(role).REFERENCES(roles.role)
}
}
object tokens: MutableTable(EXTRACONF) {
val tokenid by INT("tokenid") { NOT_NULL; AUTO_INCREMENT }
val user by reference(users.user) { NOT_NULL; BINARY}
val ip by VARCHAR("ip", 45) { NOT_NULL }
val keyid by reference(pubkeys.keyid)
val token by VARCHAR("token", 45) { NOT_NULL; BINARY }
val epoch by BIGINT("epoch") { NOT_NULL }
override fun init() {
PRIMARY_KEY(tokenid)
FOREIGN_KEY(user).REFERENCES(users.user)
FOREIGN_KEY(keyid).REFERENCES(pubkeys.keyid)
}
}
object app_perms: MutableTable(EXTRACONF) {
val user by reference(users.user) { NOT_NULL; BINARY }
val app by VARCHAR("app", 50) { NOT_NULL }
override fun init() {
PRIMARY_KEY (user, app)
FOREIGN_KEY (`user`).REFERENCES(users.user)
}
}
object pubkeys: MutableTable(EXTRACONF) {
val keyid by INT("keyid") { NOT_NULL; AUTO_INCREMENT }
val user by reference(users.user) { NOT_NULL; BINARY }
val appname by VARCHAR("appname", 80)
val pubkey by MEDIUMTEXT("pubkey") { BINARY; NOT_NULL }
val lastUse by BIGINT("lastUse")
override fun init() {
PRIMARY_KEY(keyid)
FOREIGN_KEY(user).REFERENCES(users.user)
}
}
object challenges: MutableTable(EXTRACONF) {
val keyid by reference(pubkeys.keyid) { NOT_NULL }
val challenge by VARCHAR("challenge", 100) { NOT_NULL; BINARY }
val requestip by VARCHAR("requestip", 45) { NOT_NULL }
val epoch by BIGINT("epoch")
override fun init() {
PRIMARY_KEY(keyid, requestip)
FOREIGN_KEY(keyid).REFERENCES(pubkeys.keyid)
}
}
}