Skip to content

Commit 5e5ded9

Browse files
committed
moved to protocol
1 parent 1ba0f08 commit 5e5ded9

File tree

8 files changed

+140
-0
lines changed

8 files changed

+140
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package spp.protocol.auth
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class AccessPermission(
7+
val id: String,
8+
val locationPatterns: List<String>,
9+
val type: AccessType
10+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package spp.protocol.auth
2+
3+
enum class AccessType {
4+
BLACK_LIST,
5+
WHITE_LIST
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package spp.protocol.auth
2+
3+
data class DataRedaction(
4+
val id: String,
5+
val redactionPattern: String
6+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package spp.protocol.auth
2+
3+
enum class DeveloperRole(var roleName: String, var nativeRole: Boolean) {
4+
ROLE_MANAGER("role_manager", true),
5+
ROLE_USER("role_user", true),
6+
USER("*", false);
7+
8+
companion object {
9+
fun fromString(roleName: String): DeveloperRole {
10+
val nativeRole = values().find { it.name.lowercase() == roleName.lowercase() }
11+
return if (nativeRole != null) {
12+
nativeRole
13+
} else {
14+
val user = USER
15+
user.roleName = roleName.toLowerCase().replace(' ', '_').trim()
16+
user
17+
}
18+
}
19+
}
20+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package spp.protocol.auth
2+
3+
enum class RolePermission(val manager: Boolean = true) {
4+
RESET(true),
5+
// CLEAR_LIVE_INSTRUMENTS(true),
6+
7+
//devs
8+
ADD_DEVELOPER(true),
9+
REMOVE_DEVELOPER(true),
10+
GET_DEVELOPERS(true),
11+
REFRESH_DEVELOPER_TOKEN(true),
12+
13+
//roles
14+
ADD_ROLE(true),
15+
REMOVE_ROLE(true),
16+
GET_ROLES(true),
17+
GET_DEVELOPER_ROLES(true),
18+
ADD_DEVELOPER_ROLE(true),
19+
REMOVE_DEVELOPER_ROLE(true),
20+
21+
//permissions
22+
GET_DEVELOPER_PERMISSIONS(true),
23+
GET_ROLE_PERMISSIONS(true),
24+
ADD_ROLE_PERMISSION(true),
25+
REMOVE_ROLE_PERMISSION(true),
26+
27+
//instrument access
28+
GET_ACCESS_PERMISSIONS(true),
29+
GET_DATA_REDACTIONS(true),
30+
ADD_DATA_REDACTION(true),
31+
REMOVE_DATA_REDACTION(true),
32+
ADD_ACCESS_PERMISSION(true),
33+
REMOVE_ACCESS_PERMISSION(true),
34+
35+
//instruments
36+
ADD_LIVE_BREAKPOINT(false),
37+
ADD_LIVE_LOG(false),
38+
ADD_LIVE_METER(false),
39+
GET_LIVE_INSTRUMENTS(false),
40+
GET_LIVE_BREAKPOINTS(false),
41+
GET_LIVE_LOGS(false),
42+
GET_LIVE_METERS(false),
43+
REMOVE_LIVE_INSTRUMENT(false)
44+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package spp.protocol.auth.error
2+
3+
class AccessDenied : RuntimeException {
4+
5+
private val reason: String
6+
7+
constructor(reason: String) : this(reason, "Access denied: $reason")
8+
9+
private constructor(reason: String, message: String) : super(message) {
10+
this.reason = reason
11+
}
12+
13+
fun toEventBusException(): AccessDenied {
14+
return AccessDenied(
15+
reason, "EventBusException:AccessDenied[$reason]"
16+
)
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package spp.protocol.auth.error
2+
3+
class InstrumentAccessDenied : RuntimeException {
4+
5+
private val instrumentLocation: String
6+
7+
constructor(instrumentLocation: String) : this(instrumentLocation, "Instrument access denied: $instrumentLocation")
8+
9+
private constructor(instrumentLocation: String, message: String) : super(message) {
10+
this.instrumentLocation = instrumentLocation
11+
}
12+
13+
fun toEventBusException(): InstrumentAccessDenied {
14+
return InstrumentAccessDenied(
15+
instrumentLocation, "EventBusException:InstrumentAccessDenied[$instrumentLocation]"
16+
)
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package spp.protocol.auth.error
2+
3+
import spp.protocol.auth.RolePermission
4+
5+
class PermissionAccessDenied : RuntimeException {
6+
7+
private val permission: RolePermission
8+
9+
constructor(permission: RolePermission) : this(permission, "Permission access denied: ${permission.name}")
10+
11+
private constructor(permission: RolePermission, message: String) : super(message) {
12+
this.permission = permission
13+
}
14+
15+
fun toEventBusException(): PermissionAccessDenied {
16+
return PermissionAccessDenied(permission, "EventBusException:PermissionAccessDenied[$permission]")
17+
}
18+
}

0 commit comments

Comments
 (0)