Skip to content

Commit

Permalink
Feature/oidf 15 2 (#34)
Browse files Browse the repository at this point in the history
* feat: implement entity config builder

* feat: implement subordinate relationship create

* feat: implement published entity configuration statement persistence

* feat: implement published entity configuration statement persistence

* fix: entity configuration database constraint

* feat: implement entity configuration metadata

* fix: add return on end of files

* fix: add return on end of files

* fix: return constants on errors
  • Loading branch information
jcmelati authored Aug 21, 2024
1 parent efbee24 commit f1293da
Show file tree
Hide file tree
Showing 38 changed files with 857 additions and 840 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ DATASOURCE_USER=openid-federation-db-user
DATASOURCE_PASSWORD=openid-federation-db-password
DATASOURCE_DB=openid-federation-db
APP_KEY=Nit5tWts42QeCynT1Q476LyStDeSd4xb
ROOT_IDENTIFIER=http://localhost:8080
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
networks:
- openid_network
healthcheck:
test: ["CMD-SHELL", "pg_isready -d ${DATASOURCE_DB} -U ${DATASOURCE_USER}"]
test: [ "CMD-SHELL", "pg_isready -d ${DATASOURCE_DB} -U ${DATASOURCE_USER}" ]
interval: 3s
timeout: 5s
retries: 20
Expand Down
1 change: 1 addition & 0 deletions modules/admin-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
testImplementation(libs.testcontainer.postgres)
runtimeOnly(libs.postgres)
runtimeOnly(libs.springboot.devtools)
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.11")
}

kotlin {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.sphereon.oid.fed.server.admin.controllers

import com.sphereon.oid.fed.openapi.models.CreateMetadataDTO
import com.sphereon.oid.fed.persistence.models.EntityConfigurationMetadata
import com.sphereon.oid.fed.services.EntityConfigurationMetadataService
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/accounts/{accountUsername}/metadata")
class EntityConfigurationMetadataController {
private val entityConfigurationMetadataService = EntityConfigurationMetadataService()

@GetMapping
fun get(
@PathVariable accountUsername: String
): Array<EntityConfigurationMetadata> {
return entityConfigurationMetadataService.findByAccountUsername(accountUsername)
}

@PostMapping
fun create(
@PathVariable accountUsername: String,
@RequestBody metadata: CreateMetadataDTO
): EntityConfigurationMetadata {
return entityConfigurationMetadataService.createEntityConfigurationMetadata(
accountUsername,
metadata.key,
metadata.value
)
}

@DeleteMapping("/{id}")
fun delete(
@PathVariable accountUsername: String,
@PathVariable id: Int
): EntityConfigurationMetadata {
return entityConfigurationMetadataService.deleteEntityConfigurationMetadata(accountUsername, id)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.sphereon.oid.fed.server.admin.controllers

import com.sphereon.oid.fed.openapi.models.EntityConfigurationStatement
import com.sphereon.oid.fed.services.EntityStatementService
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/accounts/{accountUsername}/entity-statement")
class EntityStatementController {
private val entityStatementService = EntityStatementService()

@GetMapping
fun getEntityStatement(@PathVariable accountUsername: String): EntityConfigurationStatement {
return entityStatementService.findByUsername(accountUsername)
}

@PostMapping
fun publishEntityStatement(@PathVariable accountUsername: String): EntityConfigurationStatement {
return entityStatementService.publishByUsername(accountUsername)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class KeyController {
@GetMapping
fun getKeys(@PathVariable accountUsername: String): List<JwkAdminDTO> {
val keys = keyService.getKeys(accountUsername)
return keys
return keys.map { it.toJwkAdminDTO() }
}

@DeleteMapping("/{keyId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.sphereon.oid.fed.server.admin.controllers

import com.sphereon.oid.fed.openapi.models.CreateSubordinateDTO
import com.sphereon.oid.fed.openapi.models.SubordinateAdminDTO
import com.sphereon.oid.fed.persistence.models.Subordinate
import com.sphereon.oid.fed.services.SubordinateService
import com.sphereon.oid.fed.services.extensions.toSubordinateAdminDTO
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

Expand All @@ -13,7 +18,16 @@ class SubordinateController {
private val subordinateService = SubordinateService()

@GetMapping
fun getSubordinates(@PathVariable accountUsername: String): List<Subordinate> {
return subordinateService.findSubordinatesByAccount(accountUsername)
fun getSubordinates(@PathVariable accountUsername: String): Array<SubordinateAdminDTO> {
return subordinateService.findSubordinatesByAccount(accountUsername).map { it.toSubordinateAdminDTO() }
.toTypedArray()
}
}

@PostMapping
fun createSubordinate(
@PathVariable accountUsername: String,
@RequestBody subordinate: CreateSubordinateDTO
): Subordinate {
return subordinateService.createSubordinate(accountUsername, subordinate)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ spring.datasource.password=${DATASOURCE_PASSWORD}
spring.datasource.driver-class-name=org.postgresql.Driver
# Mapping /actuator/health to /status
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=status
management.endpoints.web.path-mapping.health=status
Original file line number Diff line number Diff line change
@@ -1,34 +1,50 @@
package com.sphereon.oid.fed.server.federation.controllers

import com.sphereon.oid.fed.persistence.Persistence
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
import org.springframework.web.bind.annotation.RestController


@RestController
@RequestMapping()
class FederationController {
private val accountQueries = Persistence.accountQueries
private val entityConfigurationStatementQueries = Persistence.entityConfigurationStatementQueries
private val subordinateService = SubordinateService()

@GetMapping("/.well-known/openid-federation")
fun getRootEntityConfigurationStatement(): String {
throw NotImplementedError()
val account = accountQueries.findByUsername("root").executeAsOneOrNull()
?: throw IllegalArgumentException("Account not found")
val entityConfigurationStatement =
entityConfigurationStatementQueries.findLatestByAccountId(account.id).executeAsOneOrNull()
?: throw IllegalArgumentException("Entity Configuration Statement not found")

return entityConfigurationStatement.statement
}

@GetMapping("/{username}/.well-known/openid-federation")
fun getAccountEntityConfigurationStatement(@PathVariable username: String): String {
throw NotImplementedError()
val account = accountQueries.findByUsername(username).executeAsOneOrNull()
?: throw IllegalArgumentException("Account not found")
val entityConfigurationStatement =
entityConfigurationStatementQueries.findLatestByAccountId(account.id).executeAsOneOrNull()
?: throw IllegalArgumentException("Entity Configuration Statement not found")

return entityConfigurationStatement.statement
}

@GetMapping("/list")
fun getRootSubordinatesList(): List<String> {
return subordinateService.findSubordinatesByAccountAsList("root")
fun getRootSubordinatesList(): Array<String> {
return subordinateService.findSubordinatesByAccountAsArray("root")
}

@GetMapping("/{username}/list")
fun getSubordinatesList(@PathVariable username: String): List<String> {
return subordinateService.findSubordinatesByAccountAsList(username)
fun getSubordinatesList(@PathVariable username: String): Array<String> {
return subordinateService.findSubordinatesByAccountAsArray(username)
}

@GetMapping("/fetch")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ spring.datasource.username=${DATASOURCE_USER}
spring.datasource.password=${DATASOURCE_PASSWORD}
# Mapping /actuator/health to /status
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=status
management.endpoints.web.path-mapping.health=status
server.port=8080
3 changes: 2 additions & 1 deletion modules/openapi/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ kotlin {
outputDir.set("$projectDir/build/generated")
configOptions.set(
mapOf(
"dateLibrary" to "string"
"dateLibrary" to "string",
"collectionType" to "array",
)
)

Expand Down
Loading

0 comments on commit f1293da

Please sign in to comment.