From e80c3f8ccee6ca7cd17b83c2c5df3132cee877f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?yongyiduan=28=E6=AE=B5=E6=B0=B8=E5=84=84=29?= Date: Fri, 20 Sep 2024 16:00:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20openapi=20filter=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20#10679?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/openapi/config/OpenAPiConfiguration.kt | 9 +++++++++ ...{SampleApiFilterChain.kt => DefaultApiFilterChain.kt} | 9 +++------ .../impl/{SampleApiFilter.kt => AccessTokenFilter.kt} | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) rename src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/{SampleApiFilterChain.kt => DefaultApiFilterChain.kt} (88%) rename src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/impl/{SampleApiFilter.kt => AccessTokenFilter.kt} (95%) diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/config/OpenAPiConfiguration.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/config/OpenAPiConfiguration.kt index 4a5e286aab8..2fb78f1c490 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/config/OpenAPiConfiguration.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/config/OpenAPiConfiguration.kt @@ -26,7 +26,12 @@ */ package com.tencent.devops.openapi.config + +import com.tencent.devops.openapi.filter.manager.ApiFilterManagerCache +import com.tencent.devops.openapi.filter.manager.ApiFilterManagerChain +import com.tencent.devops.openapi.filter.manager.DefaultApiFilterChain import com.tencent.devops.openapi.service.op.DefaultOpAppUserService +import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -39,4 +44,8 @@ class OpenAPiConfiguration { @Bean @ConditionalOnMissingBean(name = ["opAppUserService"]) fun opAppUserService() = DefaultOpAppUserService() + + @Bean + @ConditionalOnMissingBean(ApiFilterManagerChain::class) + fun opAppUserService(@Autowired managerCache: ApiFilterManagerCache) = DefaultApiFilterChain(managerCache) } diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/SampleApiFilterChain.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/DefaultApiFilterChain.kt similarity index 88% rename from src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/SampleApiFilterChain.kt rename to src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/DefaultApiFilterChain.kt index 57f81a0e072..b388a2ff04b 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/SampleApiFilterChain.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/DefaultApiFilterChain.kt @@ -27,16 +27,13 @@ package com.tencent.devops.openapi.filter.manager +import com.tencent.devops.openapi.filter.manager.impl.AccessTokenFilter import com.tencent.devops.openapi.filter.manager.impl.ApiPathFilter import com.tencent.devops.openapi.filter.manager.impl.BlueKingApiFilter import com.tencent.devops.openapi.filter.manager.impl.NoPermissionFilter -import com.tencent.devops.openapi.filter.manager.impl.SampleApiFilter import javax.ws.rs.container.ContainerRequestContext -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Service -@Service -class SampleApiFilterChain @Autowired constructor( +class DefaultApiFilterChain( private val managerCache: ApiFilterManagerCache ) : ApiFilterManagerChain { @@ -45,7 +42,7 @@ class SampleApiFilterChain @Autowired constructor( requestContext = FilterContext(requestContext), chain = listOf( managerCache.getFilter(ApiPathFilter::class.java), - managerCache.getFilter(SampleApiFilter::class.java), + managerCache.getFilter(AccessTokenFilter::class.java), managerCache.getFilter(NoPermissionFilter::class.java), managerCache.getFilter(BlueKingApiFilter::class.java) ).iterator() diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/impl/SampleApiFilter.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/impl/AccessTokenFilter.kt similarity index 95% rename from src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/impl/SampleApiFilter.kt rename to src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/impl/AccessTokenFilter.kt index e540f8ba5c2..97d2ca41a78 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/impl/SampleApiFilter.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/filter/manager/impl/AccessTokenFilter.kt @@ -13,11 +13,11 @@ import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service @Service -class SampleApiFilter constructor( +class AccessTokenFilter constructor( private val client: Client ) : ApiFilterManager { companion object { - private val logger = LoggerFactory.getLogger(SampleApiFilter::class.java) + private val logger = LoggerFactory.getLogger(AccessTokenFilter::class.java) } @Value("\${auth.accessToken.enabled:#{null}}")