Skip to content

Commit

Permalink
Refactor : Remove unnecessary dependencies and api (#3)
Browse files Browse the repository at this point in the history
* Remove unnecessary dependencies

* change class to interface api

* Remove unnecessary role definitions

* remove `AuthorizationHandlerInterceptor`
  • Loading branch information
Ahoo-Wang authored Nov 20, 2022
1 parent f7c8faa commit f0ddc2b
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 105 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ configure(publishProjects) {
}
}
configure<SigningExtension> {
val isInCI = null != System.getenv("CI");
val isInCI = null != System.getenv("CI")
if (isInCI) {
val signingKeyId = System.getenv("SIGNING_KEYID")
val signingKey = System.getenv("SIGNING_SECRETKEY")
Expand Down
1 change: 0 additions & 1 deletion cosec-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dependencies {
compileOnly("org.springframework:spring-expression")
api("io.projectreactor:reactor-core")
api("io.projectreactor.kotlin:reactor-kotlin-extensions")
implementation("javax.validation:validation-api")
implementation("com.fasterxml.jackson.core:jackson-databind")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
testImplementation("ognl:ognl")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ package me.ahoo.cosec.authentication.token

import me.ahoo.cosec.authentication.Credentials
import me.ahoo.cosec.principal.CoSecPrincipal
import javax.validation.constraints.NotBlank

/**
* Switch Tenant Credentials .
*
* @author ahoo wang
*/
data class SwitchTenantCredentials(
@NotBlank val targetTenantId: String,
@NotBlank val principal: CoSecPrincipal
) : Credentials
interface SwitchTenantCredentials : Credentials {
val targetTenantId: String
val principal: CoSecPrincipal
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ interface RoleCapable {
* relation:
* <pre>
* [CoSecPrincipal] 1:N [me.ahoo.cosec.tenant.Tenant]
* [me.ahoo.cosec.tenant.Tenant] 1:N [me.ahoo.cosec.role.Role]
* [CoSecPrincipal] 1:N [me.ahoo.cosec.role.Role]
* [me.ahoo.cosec.tenant.Tenant] 1:N Role
* [CoSecPrincipal] 1:N Role
</pre> *
*
* @return role ids..
Expand Down
22 changes: 0 additions & 22 deletions cosec-core/src/main/kotlin/me/ahoo/cosec/role/Role.kt

This file was deleted.

32 changes: 0 additions & 32 deletions cosec-core/src/main/kotlin/me/ahoo/cosec/role/RoleConvert.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.auth0.jwt.interfaces.JWTVerifier
import me.ahoo.cosec.context.request.RequestTenantIdParser
import me.ahoo.cosec.principal.CoSecPrincipal
import me.ahoo.cosec.principal.RoleCapable
import me.ahoo.cosec.role.RoleConvert.asString
import me.ahoo.cosec.tenant.TenantCapable
import me.ahoo.cosec.token.AccessToken
import me.ahoo.cosec.token.CompositeToken
Expand Down Expand Up @@ -58,7 +57,7 @@ class JwtTokenConverter(
.withJWTId(accessTokenId)
.withSubject(principal.id)
.withClaim(CoSecPrincipal.NAME_KEY, principal.name)
.withClaim(RoleCapable.ROLE_KEY, asString(principal.roles))
.withClaim(RoleCapable.ROLE_KEY, principal.roles.joinToString(Jwts.ROLE_DELIMITER))
.withPayload(payloadClaims)
.withIssuedAt(now)
.withExpiresAt(accessTokenExp)
Expand Down
8 changes: 5 additions & 3 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,6 @@ import me.ahoo.cosec.policy.PolicyCapable
import me.ahoo.cosec.principal.CoSecPrincipal
import me.ahoo.cosec.principal.RoleCapable
import me.ahoo.cosec.principal.SimplePrincipal
import me.ahoo.cosec.role.RoleConvert.asSet
import me.ahoo.cosec.tenant.SimpleTenant
import me.ahoo.cosec.token.SimpleAccessToken
import me.ahoo.cosec.token.SimpleTokenPrincipal
Expand All @@ -34,6 +33,7 @@ import me.ahoo.cosec.token.TokenTenantPrincipal
* @author ahoo wang
*/
object Jwts {
const val ROLE_DELIMITER = ","
const val AUTHORIZATION_KEY = "authorization"
const val TOKEN_PREFIX = "Bearer "
private val jwtParser = JWT()
Expand Down Expand Up @@ -73,10 +73,12 @@ object Jwts {
val attrs = decodedAccessToken
.claims
.filter { !isRegisteredClaim(it.key) }

val policyStr = decodedAccessToken.getClaim(PolicyCapable.POLICY_KEY).asString()
val policies = if (policyStr.isNullOrEmpty()) emptySet() else asSet(policyStr)

val policies = if (policyStr.isNullOrEmpty()) emptySet() else policyStr.split(ROLE_DELIMITER).toSet()
val rolesStr = decodedAccessToken.getClaim(RoleCapable.ROLE_KEY).asString()
val roles = if (rolesStr.isNullOrEmpty()) emptySet() else asSet(rolesStr)
val roles = if (rolesStr.isNullOrEmpty()) emptySet() else rolesStr.split(ROLE_DELIMITER).toSet()
val principal = SimplePrincipal(principalId, name, policies, roles, attrs)
val tenantId = decodedAccessToken.getClaim(RequestTenantIdParser.TENANT_ID_KEY).asString()
val tokenPrincipal = SimpleTokenPrincipal(accessTokenId, principal)
Expand Down

This file was deleted.

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=0.8.2
version=0.8.5
description=RBAC-based And Policy-based Multi-Tenant Security Framework
website=https://github.com/Ahoo-Wang/CoSec
issues=https://github.com/Ahoo-Wang/CoSec/issues
Expand Down

0 comments on commit f0ddc2b

Please sign in to comment.