Skip to content

Commit

Permalink
[skip ci] Move KubernetesAuthenticationUtils to save-cloud-common
Browse files Browse the repository at this point in the history
  • Loading branch information
petertrr committed Oct 20, 2022
1 parent 86dd0a9 commit e390516
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ spring-boot = { module = "org.springframework.boot:spring-boot" }
spring-boot-autoconfigure = { module = "org.springframework.boot:spring-boot-autoconfigure" }
spring-boot-configuration-processor = { module = "org.springframework.boot:spring-boot-configuration-processor", version.ref = "spring-boot" }
spring-security-core = { module = "org.springframework.security:spring-security-core" }
spring-security-web = { module = "org.springframework.security:spring-security-web" }
spring-security-oauth2-client = { module = "org.springframework.security:spring-security-oauth2-client" }
spring-security-test = { module = "org.springframework.security:spring-security-test" }
spring-boot-gradle-plugin = { module = "org.springframework.boot:spring-boot-gradle-plugin", version.ref = "spring-boot" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ package com.saveourtool.save.backend.configs

import com.saveourtool.save.backend.utils.ConvertingAuthenticationManager
import com.saveourtool.save.backend.utils.CustomAuthenticationBasicConverter
import com.saveourtool.save.backend.utils.ServiceAccountAuthenticatingManager
import com.saveourtool.save.backend.utils.ServiceAccountTokenExtractorConverter
import com.saveourtool.save.domain.Role
import com.saveourtool.save.spring.security.KubernetesAuthenticationUtils
import com.saveourtool.save.spring.security.ServiceAccountAuthenticatingManager
import com.saveourtool.save.spring.security.ServiceAccountTokenExtractorConverter
import com.saveourtool.save.v1
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Import
import org.springframework.context.annotation.Profile
import org.springframework.core.annotation.Order
import org.springframework.http.HttpStatus
Expand All @@ -36,6 +38,7 @@ import javax.annotation.PostConstruct
@EnableWebFluxSecurity
@EnableReactiveMethodSecurity
@Profile("secure")
@Import(KubernetesAuthenticationUtils::class)
@Suppress("MISSING_KDOC_TOP_LEVEL", "MISSING_KDOC_CLASS_ELEMENTS", "MISSING_KDOC_ON_FUNCTION")
class WebSecurityConfig(
private val authenticationManager: ConvertingAuthenticationManager,
Expand Down
2 changes: 2 additions & 0 deletions save-cloud-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ kotlin {
dependencies {
implementation(project.dependencies.platform(libs.spring.boot.dependencies))
implementation(libs.spring.security.core)
implementation(libs.spring.security.web)
implementation(libs.spring.web)
implementation(libs.spring.webflux)
implementation(libs.spring.boot)
Expand All @@ -56,6 +57,7 @@ kotlin {
implementation(libs.commons.compress)
implementation(libs.validation.api)
implementation(libs.swagger.annotations)
implementation(libs.fabric8.kubernetes.client)
}
}
val jvmTest by getting {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.saveourtool.save.backend.utils
package com.saveourtool.save.spring.security

import com.saveourtool.save.utils.debug
import com.saveourtool.save.utils.getLogger
Expand All @@ -8,6 +8,8 @@ import io.fabric8.kubernetes.client.utils.Serialization
import org.intellij.lang.annotations.Language
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform
import org.springframework.boot.cloud.CloudPlatform
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import
import org.springframework.security.authentication.BadCredentialsException
import org.springframework.security.authentication.ReactiveAuthenticationManager
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
Expand All @@ -20,6 +22,10 @@ import reactor.core.publisher.Mono
import reactor.kotlin.core.publisher.switchIfEmpty
import reactor.kotlin.core.publisher.toMono

@Configuration
@Import(ServiceAccountTokenExtractorConverter::class, ServiceAccountAuthenticatingManager::class)
open class KubernetesAuthenticationUtils

@Component
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
class ServiceAccountTokenExtractorConverter : ServerAuthenticationConverter {
Expand All @@ -38,7 +44,7 @@ class ServiceAccountTokenExtractorConverter : ServerAuthenticationConverter {
@Component
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
class ServiceAccountAuthenticatingManager(
val kubernetesClient: KubernetesClient,
private val kubernetesClient: KubernetesClient,
) : ReactiveAuthenticationManager {
override fun authenticate(authentication: Authentication): Mono<Authentication> {
return authentication.toMono()
Expand Down

0 comments on commit e390516

Please sign in to comment.