Skip to content

Commit

Permalink
refactor: Unified Extended Claim Type (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang authored Mar 24, 2023
1 parent 29d1af0 commit bb83ab6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 37 deletions.
33 changes: 0 additions & 33 deletions cosec-jwt/src/main/kotlin/me/ahoo/cosec/jwt/ClaimAttributeValue.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class JwtTokenConverter(
!Jwts.isRegisteredClaim(it.key)
}
.map {
it.key to it.value.value
it.key to it.value.asString()
}
.toMap()

Expand All @@ -60,6 +60,7 @@ class JwtTokenConverter(
.withPayload(payloadClaims)
.withIssuedAt(now)
.withExpiresAt(accessTokenExp)

if (principal is TenantCapable) {
val tenantCapable = principal as TenantCapable
accessTokenBuilder
Expand Down
4 changes: 2 additions & 2 deletions cosec-jwt/src/main/kotlin/me/ahoo/cosec/jwt/Jwts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import me.ahoo.cosec.api.principal.RoleCapable
import me.ahoo.cosec.api.tenant.Tenant.Companion.TENANT_ID_KEY
import me.ahoo.cosec.api.token.TokenPrincipal
import me.ahoo.cosec.api.token.TokenTenantPrincipal
import me.ahoo.cosec.jwt.ClaimAttributeValue.Companion.asClaimAttributeValue
import me.ahoo.cosec.principal.ObjectAttributeValue.Companion.asAttributeValue
import me.ahoo.cosec.principal.SimplePrincipal
import me.ahoo.cosec.tenant.SimpleTenant
import me.ahoo.cosec.token.SimpleAccessToken
Expand Down Expand Up @@ -70,7 +70,7 @@ object Jwts {
.claims
.asSequence()
.filter { !isRegisteredClaim(it.key) }
.associateBy({ it.key }, { it.value.asClaimAttributeValue() })
.associateBy({ it.key }, { it.value.asString().asAttributeValue() })

val policyClaim = decodedAccessToken.getClaim(PolicyCapable.POLICY_KEY)
val policies = if (policyClaim.isMissing) emptySet() else policyClaim.asList(String::class.java).toSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ internal class JwtTokenConverterTest {
setOf("roleId"),
mapOf(
"attr_string" to "attr_string_value".asAttributeValue(),
"attr_number" to 1.asAttributeValue(),
"attr_list" to listOf("attr_list_value").asAttributeValue()
)
)
Expand All @@ -53,6 +54,10 @@ internal class JwtTokenConverterTest {
val verified = jwtTokenVerifier.verify<TokenPrincipal>(token)
assertThat(verified.id, equalTo(principal.id))
assertThat(verified.attributes["attr_string"]!!.asString(), equalTo("attr_string_value"))
assertThat(verified.attributes["attr_number"]!!.asString(), equalTo("1"))
assertThat(verified.attributes["attr_number"]!!.asObject(Int::class.java), equalTo(1))
assertThat(verified.attributes["attr_list"]!!.asObject(List::class.java), equalTo(listOf("attr_list_value")))
val token2 = jwtTokenConverter.asToken(verified)
assertThat(token2, notNullValue())
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# limitations under the License.
#
group=me.ahoo.cosec
version=1.16.4
version=1.16.5
description=RBAC-based And Policy-based Multi-Tenant Reactive Security Framework
website=https://github.com/Ahoo-Wang/CoSec
issues=https://github.com/Ahoo-Wang/CoSec/issues
Expand Down

0 comments on commit bb83ab6

Please sign in to comment.