Skip to content

Commit

Permalink
fix(authz): avoid core context duplications in authz API
Browse files Browse the repository at this point in the history
  • Loading branch information
bobeal committed Apr 26, 2024
1 parent 0cf25a9 commit 1f9c342
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fun addCoreContextIfMissing(contexts: List<String>): List<String> =
/**
* Utility but basic method to find if given contexts can resolve a known term from the core context.
*/
private fun canExpandJsonLdKeyFromCore(contexts: List<String>): Boolean {
internal fun canExpandJsonLdKeyFromCore(contexts: List<String>): Boolean {
val expandedType = JsonLdUtils.expandJsonLdTerm("datasetId", contexts)
return expandedType == NGSILD_DATASET_ID_PROPERTY
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.egm.stellio.shared.util
import arrow.core.*
import com.egm.stellio.shared.model.*
import com.egm.stellio.shared.util.AuthContextModel.AUTHORIZATION_COMPOUND_CONTEXT
import com.egm.stellio.shared.util.AuthContextModel.AUTHORIZATION_CONTEXT
import com.egm.stellio.shared.util.AuthContextModel.AUTHORIZATION_ONTOLOGY
import com.egm.stellio.shared.util.AuthContextModel.AUTH_REL_CAN_ADMIN
import com.egm.stellio.shared.util.AuthContextModel.AUTH_REL_CAN_READ
Expand Down Expand Up @@ -158,7 +159,10 @@ enum class AccessRight(val attributeName: String) {
fun getAuthzContextFromLinkHeaderOrDefault(httpHeaders: HttpHeaders): Either<APIException, List<String>> =
getContextFromLinkHeader(httpHeaders.getOrEmpty(HttpHeaders.LINK))
.map {
if (it != null) listOf(it).plus(AUTHORIZATION_COMPOUND_CONTEXT)
if (it != null)
if (canExpandJsonLdKeyFromCore(listOf(it)))
listOf(it, AUTHORIZATION_CONTEXT)
else listOf(it, AUTHORIZATION_COMPOUND_CONTEXT)
else listOf(AUTHORIZATION_COMPOUND_CONTEXT)
}

Expand Down

0 comments on commit 1f9c342

Please sign in to comment.