-
Notifications
You must be signed in to change notification settings - Fork 0
/
Authorization.kt
49 lines (45 loc) · 1.64 KB
/
Authorization.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
package radar.spring.auth.common
import kotlinx.coroutines.runBlocking
/**
* Abstract Authorization interface to be used with a custom token [T]. See
* [radar.spring.auth.managementportal.ManagementPortalAuthorization]
*/
interface Authorization<T> {
fun authorize(
token: T,
permission: String,
entity: String,
permissionOn: PermissionOn? = PermissionOn.DEFAULT,
role: String? = null,
scopes: Array<String> = emptyArray(),
authorities: Array<String> = emptyArray(),
audiences: Array<String> = emptyArray(),
grantTypes: Array<String> = emptyArray(),
project: String? = null,
user: String? = null,
source: String? = null
): Boolean {
return runBlocking {
hasPermission(token, permission, entity, permissionOn, project, user, source) &&
hasRole(token, project, role) &&
hasScopes(token, scopes) &&
hasAuthorities(token, authorities) &&
hasAudiences(token, audiences) &&
hasGrantTypes(token, grantTypes)
}
}
fun hasPermission(
token: T,
permission: String,
entity: String,
permissionOn: PermissionOn?,
project: String?,
user: String?,
source: String?
): Boolean
fun hasRole(token: T, project: String?, role: String?): Boolean
fun hasScopes(token: T, scopes: Array<String>): Boolean
fun hasAuthorities(token: T, authorities: Array<String>): Boolean
fun hasAudiences(token: T, audiences: Array<String>): Boolean
fun hasGrantTypes(token: T, grantTypes: Array<String>): Boolean
}