From fb3fc6e633c4372a0e6b7808db3163c0b27024b0 Mon Sep 17 00:00:00 2001 From: John Melati Date: Wed, 30 Oct 2024 14:27:00 +0100 Subject: [PATCH] feat: adjust federation fetch endpoint to new spec without iss param --- modules/federation-server/build.gradle.kts | 1 + .../controllers/FederationController.kt | 10 +++--- .../federation/services/SubordinateService.kt | 31 ------------------- .../com/sphereon/oid/fed/openapi/openapi.yaml | 9 +----- .../oid/fed/services/SubordinateService.kt | 12 +++++++ 5 files changed, 19 insertions(+), 44 deletions(-) delete mode 100644 modules/federation-server/src/main/kotlin/com/sphereon/oid/fed/server/federation/services/SubordinateService.kt diff --git a/modules/federation-server/build.gradle.kts b/modules/federation-server/build.gradle.kts index 757bac95..b2387ab1 100644 --- a/modules/federation-server/build.gradle.kts +++ b/modules/federation-server/build.gradle.kts @@ -19,6 +19,7 @@ dependencies { api(projects.modules.openapi) api(projects.modules.openidFederationCommon) api(projects.modules.persistence) + api(projects.modules.services) implementation(libs.springboot.actuator) implementation(libs.springboot.web) implementation(libs.springboot.data.jdbc) diff --git a/modules/federation-server/src/main/kotlin/com/sphereon/oid/fed/server/federation/controllers/FederationController.kt b/modules/federation-server/src/main/kotlin/com/sphereon/oid/fed/server/federation/controllers/FederationController.kt index a0fc42cd..61bc5e75 100644 --- a/modules/federation-server/src/main/kotlin/com/sphereon/oid/fed/server/federation/controllers/FederationController.kt +++ b/modules/federation-server/src/main/kotlin/com/sphereon/oid/fed/server/federation/controllers/FederationController.kt @@ -1,7 +1,7 @@ package com.sphereon.oid.fed.server.federation.controllers import com.sphereon.oid.fed.persistence.Persistence -import com.sphereon.oid.fed.server.federation.services.SubordinateService +import com.sphereon.oid.fed.services.SubordinateService import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.RequestMapping @@ -49,12 +49,12 @@ class FederationController { } @GetMapping("/fetch", produces = ["application/entity-statement+jwt"]) - fun getRootSubordinateStatement(@RequestParam("iss") iss: String, @RequestParam("sub") sub: String): String { - return subordinateService.fetchSubordinateStatement(iss, sub) + fun getRootSubordinateStatement(@RequestParam("sub") sub: String): String { + return subordinateService.fetchSubordinateStatementByUsernameAndSubject("root", sub) } @GetMapping("/{username}/fetch", produces = ["application/entity-statement+jwt"]) - fun getSubordinateStatement(@RequestParam("iss") iss: String, @RequestParam("sub") sub: String): String { - return subordinateService.fetchSubordinateStatement(iss, sub) + fun getSubordinateStatement(@PathVariable username: String, @RequestParam("sub") sub: String): String { + return subordinateService.fetchSubordinateStatementByUsernameAndSubject(username, sub) } } diff --git a/modules/federation-server/src/main/kotlin/com/sphereon/oid/fed/server/federation/services/SubordinateService.kt b/modules/federation-server/src/main/kotlin/com/sphereon/oid/fed/server/federation/services/SubordinateService.kt deleted file mode 100644 index b22a0a5c..00000000 --- a/modules/federation-server/src/main/kotlin/com/sphereon/oid/fed/server/federation/services/SubordinateService.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.sphereon.oid.fed.server.federation.services - -import com.sphereon.oid.fed.persistence.Persistence -import com.sphereon.oid.fed.persistence.Persistence.subordinateStatementQueries -import com.sphereon.oid.fed.persistence.models.Subordinate -import com.sphereon.oid.fed.server.federation.Constants - - -class SubordinateService { - private val accountQueries = Persistence.accountQueries - private val subordinateQueries = Persistence.subordinateQueries - - private fun findSubordinatesByAccount(accountUsername: String): Array { - val account = accountQueries.findByUsername(accountUsername).executeAsOne() - - return subordinateQueries.findByAccountId(account.id).executeAsList().toTypedArray() - } - - fun findSubordinatesByAccountAsArray(accountUsername: String): Array { - val subordinates = findSubordinatesByAccount(accountUsername) - return subordinates.map { it.identifier }.toTypedArray() - } - - fun fetchSubordinateStatement(iss: String, sub: String): String { - val subordinateStatement = subordinateStatementQueries.findByIssAndSub(iss, sub).executeAsOneOrNull() - ?: throw IllegalArgumentException(Constants.SUBORDINATE_STATEMENT_NOT_FOUND) - - return subordinateStatement.statement - } - -} diff --git a/modules/openapi/src/commonMain/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml b/modules/openapi/src/commonMain/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml index dd3c097f..c8ba18d7 100644 --- a/modules/openapi/src/commonMain/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml +++ b/modules/openapi/src/commonMain/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml @@ -175,15 +175,8 @@ paths: tags: - federation summary: Fetch Subordinate Statement - description: Fetch the Subordinate Statement issued by a specified entity `iss` for a subordinate entity `sub``. + description: Fetch the Subordinate Statement for a subordinate entity `sub``. parameters: - - name: iss - in: query - description: The issuer identifier (URI) of the entity that issues the Subordinate Statement. - required: true - schema: - type: string - format: uri - name: sub in: query description: The subject identifier (URI) of the entity for whom the Subordinate Statement is created. diff --git a/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/SubordinateService.kt b/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/SubordinateService.kt index 39b0cd39..25b429d1 100644 --- a/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/SubordinateService.kt +++ b/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/SubordinateService.kt @@ -243,4 +243,16 @@ class SubordinateService { return deletedMetadata.toSubordinateMetadataDTO() } + + fun fetchSubordinateStatementByUsernameAndSubject(username: String, sub: String): String { + val account = accountQueries.findByUsername(username).executeAsOne() + + val accountIss = accountService.getAccountIdentifier(account.username) + + val subordinateStatement = + Persistence.subordinateStatementQueries.findByIssAndSub(accountIss, sub).executeAsOneOrNull() + ?: throw IllegalArgumentException(Constants.SUBORDINATE_STATEMENT_NOT_FOUND) + + return subordinateStatement.statement + } }