Skip to content

Commit

Permalink
Merge branch 'sirixdb:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
konketf authored Jul 13, 2023
2 parents bf1f0fc + 7577818 commit fe820ae
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class Auth(private val keycloak: OAuth2Auth, private val authz: AuthorizationPro
suspend fun handle(ctx: RoutingContext): Route {
ctx.request().pause()
val token = ctx.request().getHeader(HttpHeaders.AUTHORIZATION.toString())

if (token == null) {
ctx.fail(HttpResponseStatus.UNAUTHORIZED.code())
return ctx.currentRoute()
}

val credentials = TokenCredentials(token.substring(7))
val user = keycloak.authenticate(credentials).await()
val database = ctx.pathParam("database")
Expand All @@ -38,7 +44,7 @@ class Auth(private val keycloak: OAuth2Auth, private val authz: AuthorizationPro

if (!isAuthorized && !RoleBasedAuthorization.create(role.keycloakRole()).match(user)) {
ctx.fail(HttpResponseStatus.UNAUTHORIZED.code())
ctx.response().end()
return ctx.currentRoute()
}

ctx.put("user", user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import java.io.PrintWriter
/**
* @author Johannes Lichtenberger
*/
@Suppress("unused")
class PermissionCheckingXQuery {
private val module: Module
private var isPrettyPrint: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ class JsonGet(private val location: Path, private val keycloak: OAuth2Auth, priv
val manager = database.beginResourceSession(resource)

manager.use {
body = if (query != null && query.isNotEmpty()) {
queryResource(
databaseName, database, revision, revisionTimestamp, manager, ctx, nodeId, query,
vertxContext, user, jsonBody
)
} else {
body = if (query.isNullOrEmpty()) {
val revisions: IntArray =
Revisions.getRevisionsToSerialize(
startRevision, endRevision, startRevisionTimestamp,
endRevisionTimestamp, manager, revision, revisionTimestamp
)

serializeResource(manager, revisions, nodeId?.toLongOrNull(), ctx, vertxContext)
} else {
queryResource(
databaseName, database, revision, revisionTimestamp, manager, ctx, nodeId, query,
vertxContext, user, jsonBody
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class JsonHead(private val location: Path) {
rtx.use {
if (nodeId != null) {
if (!rtx.moveTo(nodeId.toLong())) {
throw IllegalStateException("Node with ID ${nodeId} doesn't exist.")
throw IllegalStateException("Node with ID $nodeId doesn't exist.")
}
} else if (rtx.isDocumentRoot) {
rtx.moveToFirstChild()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class JsonSerializeHelper {

rtx.use {
val hash = if (nodeId == null) {
rtx.moveToFirstChild();
rtx.moveToFirstChild()
rtx.hash
} else {
rtx.moveTo(nodeId);
rtx.moveTo(nodeId)
rtx.hash
}

Expand Down

0 comments on commit fe820ae

Please sign in to comment.