summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine A <>2023-10-17 13:00:43 +0000
committerAntoine A <>2023-10-17 13:00:43 +0000
commit059c62f86ac618ee2231141926d8e920b9de0e5f (patch)
tree6d0cfb73067a2c3b3092e7310add21796705eb75
parent5c671b88781678b01937a3893438c97d6f2fd5dd (diff)
downloadlibeufin-059c62f86ac618ee2231141926d8e920b9de0e5f.tar.gz
libeufin-059c62f86ac618ee2231141926d8e920b9de0e5f.tar.bz2
libeufin-059c62f86ac618ee2231141926d8e920b9de0e5f.zip
Restrict admin rightv0.9.3-dev.25
-rw-r--r--bank/src/main/kotlin/tech/libeufin/bank/Authentication.kt3
-rw-r--r--bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt8
-rw-r--r--bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt4
-rw-r--r--bank/src/test/kotlin/CoreBankApiTest.kt2
4 files changed, 9 insertions, 8 deletions
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Authentication.kt b/bank/src/main/kotlin/tech/libeufin/bank/Authentication.kt
index 2b63d523..bc4399ce 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/Authentication.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/Authentication.kt
@@ -14,10 +14,11 @@ suspend fun ApplicationCall.authAdmin(db: Database, scope: TokenScope) {
if (login != "admin") {
throw unauthorized("Only administrator allowed")
}
+
}
/** Authenticate and check access rights */
-suspend fun ApplicationCall.authCheck(db: Database, scope: TokenScope, withAdmin: Boolean = true, requireAdmin: Boolean = false): Pair<String, Boolean> {
+suspend fun ApplicationCall.authCheck(db: Database, scope: TokenScope, withAdmin: Boolean = false, requireAdmin: Boolean = false): Pair<String, Boolean> {
// TODO when all endpoints use this function we can use an optimized database request that only query the customer login
val authLogin = authenticateBankRequest(db, scope) ?: throw unauthorized("Bad login")
val login = accountLogin()
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt
index fb039f86..371f88b2 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt
@@ -290,7 +290,7 @@ fun Routing.coreBankAccountsMgmtApi(db: Database, ctx: BankApplicationContext) {
call.respond(HttpStatusCode.Created)
}
delete("/accounts/{USERNAME}") {
- val (login, _) = call.authCheck(db, TokenScope.readwrite, requireAdmin = ctx.restrictAccountDeletion)
+ val (login, _) = call.authCheck(db, TokenScope.readwrite, withAdmin = true, requireAdmin = ctx.restrictAccountDeletion)
// Not deleting reserved names.
if (reservedAccounts.contains(login)) throw conflict(
"Cannot delete reserved accounts",
@@ -313,7 +313,7 @@ fun Routing.coreBankAccountsMgmtApi(db: Database, ctx: BankApplicationContext) {
}
}
patch("/accounts/{USERNAME}") {
- val (login, isAdmin) = call.authCheck(db, TokenScope.readwrite)
+ val (login, isAdmin) = call.authCheck(db, TokenScope.readwrite, withAdmin = true)
// admin is not allowed itself to change its own details.
if (login == "admin") throw forbidden("admin account not patchable")
// authentication OK, go on.
@@ -402,7 +402,7 @@ fun Routing.coreBankAccountsMgmtApi(db: Database, ctx: BankApplicationContext) {
}
}
get("/accounts/{USERNAME}") {
- val (login, _) = call.authCheck(db, TokenScope.readonly)
+ val (login, _) = call.authCheck(db, TokenScope.readonly, withAdmin = true)
val customerData = db.customerGetFromLogin(login) ?: throw notFound(
"Customer '$login' not found in the database.",
talerEc = TalerErrorCode.TALER_EC_END
@@ -472,7 +472,7 @@ fun Routing.coreBankTransactionsApi(db: Database, ctx: BankApplicationContext) {
)
}
post("/accounts/{USERNAME}/transactions") {
- val (login, _ ) = call.authCheck(db, TokenScope.readwrite, withAdmin = false)
+ val (login, _ ) = call.authCheck(db, TokenScope.readwrite)
val tx = call.receive<BankAccountTransactionCreate>()
val subject = tx.payto_uri.message ?: throw badRequest("Wire transfer lacks subject")
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt
index a8262a3a..e1cfd897 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt
@@ -43,7 +43,7 @@ fun Routing.wireGatewayApi(db: Database, ctx: BankApplicationContext) {
}
post("/accounts/{USERNAME}/taler-wire-gateway/transfer") {
- val (login, _) = call.authCheck(db, TokenScope.readwrite, withAdmin = false)
+ val (login, _) = call.authCheck(db, TokenScope.readwrite)
val req = call.receive<TransferRequest>()
if (req.amount.currency != ctx.currency)
throw badRequest(
@@ -126,7 +126,7 @@ fun Routing.wireGatewayApi(db: Database, ctx: BankApplicationContext) {
}
post("/accounts/{USERNAME}/taler-wire-gateway/admin/add-incoming") {
- val (login, _) = call.authCheck(db, TokenScope.readwrite, withAdmin = false)
+ val (login, _) = call.authCheck(db, TokenScope.readwrite) // TODO authAdmin ?
val req = call.receive<AddIncomingRequest>()
if (req.amount.currency != ctx.currency)
throw badRequest(
diff --git a/bank/src/test/kotlin/CoreBankApiTest.kt b/bank/src/test/kotlin/CoreBankApiTest.kt
index d144fe2e..b373fa97 100644
--- a/bank/src/test/kotlin/CoreBankApiTest.kt
+++ b/bank/src/test/kotlin/CoreBankApiTest.kt
@@ -480,7 +480,7 @@ class CoreBankTransactionsApiTest {
"amount" to "KUDOS:0.3"
}
- authRoutine("/accounts/merchant/transactions", withAdmin = false)
+ authRoutine("/accounts/merchant/transactions")
// Check OK
client.post("/accounts/merchant/transactions") {