Skip to content

Commit

Permalink
feat: Added mapping for trust chain and categorize entity statement
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmathew committed Jul 25, 2024
1 parent 6dcd541 commit a3fef17
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 17 deletions.
48 changes: 34 additions & 14 deletions modules/openapi/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

plugins {
kotlin("multiplatform") version "2.0.0"
kotlin("plugin.serialization") version "2.0.0"
id("org.openapi.generator") version "7.7.0"
id("maven-publish")
}
Expand All @@ -23,11 +24,26 @@ repositories {

kotlin {
tasks {
// Temporary fix for this issue: https://github.com/OpenAPITools/openapi-generator/issues/17658
register<Copy>("fixOpenApiGeneratorIssue") {
from(
"$projectDir/build/generated/src/commonMain/kotlin/com/sphereon/oid/fed/openapi"
)
into(
"$projectDir/build/copy/src/commonMain/kotlin/com/sphereon/oid/fed/openapi"
)
filter { line: String ->
line.replace(
"kotlin.collections.Map<kotlin.String, kotlin.Any>",
"kotlinx.serialization.json.JsonObject")
}
}

withType<KotlinCompileCommon> {
dependsOn("openApiGenerate")
dependsOn("fixOpenApiGeneratorIssue")
}
named("sourcesJar") {
dependsOn("openApiGenerate")
dependsOn("fixOpenApiGeneratorIssue")
}
}
jvm {
Expand Down Expand Up @@ -58,19 +74,23 @@ kotlin {
}
}

named<KotlinJvmCompile>("compileKotlinJvm") {
named<Copy>("fixOpenApiGeneratorIssue") {
dependsOn("openApiGenerate")
}

named<KotlinJvmCompile>("compileKotlinJvm") {
dependsOn("fixOpenApiGeneratorIssue")
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}

named("jvmSourcesJar") {
dependsOn("openApiGenerate")
dependsOn("fixOpenApiGeneratorIssue")
}

named<Jar>("jvmJar") {
dependsOn("compileKotlinJvm")
dependsOn("fixOpenApiGeneratorIssue")
archiveBaseName.set("openapi")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(configurations.kotlinCompilerClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
Expand All @@ -82,10 +102,10 @@ kotlin {
js {
tasks {
named("compileKotlinJs") {
dependsOn("openApiGenerate")
dependsOn("fixOpenApiGeneratorIssue")
}
named("jsSourcesJar") {
dependsOn("openApiGenerate")
dependsOn("fixOpenApiGeneratorIssue")
}
}
nodejs()
Expand All @@ -94,37 +114,37 @@ kotlin {
iosX64 {
tasks {
named("compileKotlinIosX64") {
dependsOn("openApiGenerate")
dependsOn("fixOpenApiGeneratorIssue")
}
named("iosX64SourcesJar") {
dependsOn("openApiGenerate")
dependsOn("fixOpenApiGeneratorIssue")
}
}
}
iosArm64 {
tasks {
named("compileKotlinIosArm64") {
dependsOn("openApiGenerate")
dependsOn("fixOpenApiGeneratorIssue")
}
named("iosArm64SourcesJar") {
dependsOn("openApiGenerate")
dependsOn("fixOpenApiGeneratorIssue")
}
}
}
iosSimulatorArm64 {
tasks {
named("compileKotlinIosSimulatorArm64") {
dependsOn("openApiGenerate")
dependsOn("fixOpenApiGeneratorIssue")
}
named("iosSimulatorArm64SourcesJar") {
dependsOn("openApiGenerate")
dependsOn("fixOpenApiGeneratorIssue")
}
}
}

sourceSets {
val commonMain by getting {
kotlin.srcDir("build/generated/src/commonMain/kotlin")
kotlin.srcDir("build/copy/src/commonMain/kotlin")
dependencies {
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kotlin.code.style=official
profiles=models-only
#profiles=models-only
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.sphereon.oid.fed.common.logic

import com.sphereon.oid.fed.openapi.models.EntityStatement

class EntityLogic {

fun getEntityType(entityStatement: EntityStatement): EntityType {
if (isFederationListEndpointPresent(entityStatement) == true && isAuthorityHintPresent(entityStatement) == false) {
return EntityType.TRUST_ANCHOR
} else if (isFederationListEndpointPresent(entityStatement) == true && isAuthorityHintPresent(entityStatement) == true) {
return EntityType.INTERMEDIATE
} else if (isFederationListEndpointPresent(entityStatement) == false && isAuthorityHintPresent(entityStatement) == true) {
return EntityType.LEAF
} else {
return EntityType.UNDEFINED
}
}

private fun isAuthorityHintPresent(entityStatement: EntityStatement): Boolean {
return entityStatement.authorityHints?.isEmpty() == false
}

private fun isFederationListEndpointPresent(entityStatement: EntityStatement): Boolean {
return entityStatement.metadata?.federationEntity?.federationListEndpoint?.isNotEmpty() == true
}
}

enum class EntityType {
LEAF,
INTERMEDIATE,
TRUST_ANCHOR,
UNDEFINED
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlinx.serialization.json.decodeFromJsonElement
class JsonMapper {

/*
* Used for mapping JWT token to EntityStatement object
* Used for mapping JWT token to EntityStatement object
*/
fun mapEntityStatement(jwtToken: String): EntityStatement? {
val data = decodeJWTComponents(jwtToken)
Expand All @@ -17,4 +17,15 @@ class JsonMapper {
null
}
}

/*
* Used for mapping trust chain
*/
fun mapTrustChain(jwtTokenList: List<String>): List<EntityStatement?> {
val list: MutableList<EntityStatement?> = mutableListOf()
jwtTokenList.forEach { jwtToken ->
list.add(mapEntityStatement(jwtToken))
}
return list
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ import kotlinx.serialization.SerialName
data class JWTHeader(
@SerialName("alg") val alg: String, // RS256
@SerialName("kid") val kid: String, // B6EB8488CC84C41017134BC77F4132A0467CCC0E
@SerialName("typ") val typ: String // entity-statement+jwt
@SerialName("typ") val typ: String? = null, // entity-statement+jwt
@SerialName("trust_chain") val trustChain: List<String>? = null // ["eyJhbGciOiJSUzI1NiIsImtpZCI6IlpXRlRRbWhmVFdaSVRuRlRZM0ZTV2pKdU5HMWZWV05hZWxkNmNtUjFRa0pEYlhaWlRYQm1hM1JWUVEiLCJ0eXAiOiJlbnRpdHktc3RhdGVtZW50K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