@@ -27,6 +27,7 @@ import org.keycloak.representations.idm.authorization.PermissionRequest
27
27
import org.keycloak.representations.idm.authorization.ResourceRepresentation
28
28
import org.keycloak.representations.idm.authorization.ScopeRepresentation
29
29
import java.net.URL
30
+ import java.time.Instant
30
31
import java.util.concurrent.TimeUnit
31
32
32
33
object KeycloakUtils {
@@ -142,18 +143,21 @@ object KeycloakUtils {
142
143
return existingResources.get(resourceSpec.name) {
143
144
var resource = authzClient.protection().resource().findByNameAnyOwner(resourceSpec.name)
144
145
if (resource != null ) return @get resource
145
- val protection = (
146
- if (resourceSpec.type.ownerManaged) {
147
- owner?.let { authzClient.protection(owner.token) }
148
- } else {
149
- null
150
- }
151
- ) ? : authzClient.protection()
146
+ // val protection = owner?.let { authzClient.protection(owner.token) }
147
+ // ?.takeIf { resourceSpec.type.createByUser }
148
+ // ?: authzClient.protection()
149
+ val protection = authzClient.protection()
152
150
resource = ResourceRepresentation ().apply {
153
151
name = resourceSpec.name
154
152
scopes = resourceSpec.type.scopes.map { ScopeRepresentation (it.name) }.toSet()
155
153
type = resourceSpec.type.name
156
- if (resourceSpec.type.ownerManaged) ownerManagedAccess = true
154
+ // if (resourceSpec.type.createByUser) ownerManagedAccess = true
155
+ if (resourceSpec.type.createByUser) {
156
+ attributes = mapOf (
157
+ " created-by" to listOfNotNull(owner?.subject, owner?.getClaim(" email" )?.asString()),
158
+ " creation-timestamp" to listOf (Instant .now().epochSecond.toString())
159
+ )
160
+ }
157
161
}
158
162
resource = protection.resource().create(resource)
159
163
permissionCache.invalidateAll()
@@ -191,7 +195,7 @@ data class KeycloakResource(val name: String, val type: KeycloakResourceType) {
191
195
192
196
}
193
197
194
- data class KeycloakResourceType (val name : String , val scopes : Set <KeycloakScope >, val ownerManaged : Boolean = false ) {
198
+ data class KeycloakResourceType (val name : String , val scopes : Set <KeycloakScope >, val createByUser : Boolean = false ) {
195
199
fun createInstance (resourceName : String ) = KeycloakResource (this .name + " /" + resourceName, this )
196
200
197
201
companion object {
0 commit comments