ERROR

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method setAuthorizedClientManagerRegistrar in org.springframework.security.config.annotation.web.reactive.ReactiveOAuth2ClientConfiguration$OAuth2ClientWebFluxSecurityConfiguration required a bean of type 'org.springframework.security.config.annotation.web.reactive.ReactiveOAuth2ClientConfiguration$ReactiveOAuth2AuthorizedClientManagerRegistrar' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.security.config.annotation.web.reactive.ReactiveOAuth2ClientConfiguration$ReactiveOAuth2AuthorizedClientManagerRegistrar' in your configuration.

It's a hidden class so I cannot invoke it manually myself.

Here is my full code:

Code

@Configuration
@EnableWebFluxSecurity
//@EnableSpringWebSession
internal class DefaultSecurityConfig () {

    @Value("\${oauth2.client.registration.api-gateway.client-id}")
    private lateinit var apiGatewayClientId: String

    @Value("\${oauth2.client.registration.api-gateway.client-secret}")
    private lateinit var apiGatewayClientSecret: String

    @Value("\${gateway-url}")
    private lateinit var gatewayUrl: String

    @Value("\${authorization-url}")
    private lateinit var authorizationUrl: String

    @Bean
    fun apiGatewayServerSecurityFilterChain(
        http: ServerHttpSecurity,
    ): SecurityWebFilterChain {

        http
            // disable csrf
            .csrf { csrf -> csrf.disable() }
            // configure cords
            .cors { cors ->
                cors.configurationSource {
                    CorsConfiguration().apply {
                        // ensure this matches your Angular app URL
                        allowedOrigins = listOf("http://localhost:4200")
                        allowedMethods = listOf("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
                        allowedHeaders = listOf("Content-Type", "Authorization")
                        exposedHeaders = listOf("Content-Type", "Authorization")
                        // required if credentials (cookies, authorization headers) are involved
                        allowCredentials = true
                    }
                }
            }
            // oauth2.0 client login
            .oauth2Login { oauth2 ->
                oauth2
                    .clientRegistrationRepository(clientRegistrationRepository())
                    .authorizedClientService(authorizedClientService(clientRegistrationRepository()))
            }
            // authorizations (authenticate all end points, apart from login)
            .authorizeExchange { exchange ->
                exchange
                    .pathMatchers("/login/**").permitAll()
                    .anyExchange().authenticated()
            }

        return http.build()
    }

    @Bean
    fun clientRegistrationRepository(): InMemoryReactiveClientRegistrationRepository {
        val inHouseAuthServerRegistration = ClientRegistration
            .withRegistrationId("in-house-auth-server")
            .clientId(apiGatewayClientId)
            .clientSecret(apiGatewayClientSecret)
            .authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
            .redirectUri("$gatewayUrl/login/oauth2/code/in-house-auth-server")
            .authorizationUri("$authorizationUrl/oauth2/authorize")
            .tokenUri("$authorizationUrl/oauth2/token")
            .scope("openid")
            .issuerUri(authorizationUrl)
            .build()

        return InMemoryReactiveClientRegistrationRepository(
            inHouseAuthServerRegistration
        )
    }

    @Bean
    fun authorizedClientService(
        clientRegistrationRepository: InMemoryReactiveClientRegistrationRepository
    ): ReactiveOAuth2AuthorizedClientService {
        return InMemoryReactiveOAuth2AuthorizedClientService(
            clientRegistrationRepository
        )
    }

    @Bean
    fun authorizedClientManager(
        clientRegistrationRepository: ReactiveClientRegistrationRepository,
        authorizedClientService: ReactiveOAuth2AuthorizedClientService
    ): AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager {
        return AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager(
            clientRegistrationRepository,
            authorizedClientService
        )
    }

}

Action:

Consider defining a bean of type 'org.springframework.security.config.annotation.web.reactive.ReactiveOAuth2ClientConfiguration$ReactiveOAuth2AuthorizedClientManagerRegistrar' in your configuration.

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior.

Expected behavior A clear and concise description of what you expected to happen.

Sample

A link to a GitHub repository with a minimal, reproducible sample.

Reports that include a sample will take priority over reports that do not. At times, we may require a sample, so it is good to try and include a sample up front.

Comment From: dreamstar-enterprises

resolved. I had another class annotated with EnableWebFluxSecurity that was causing the problem

Comment From: dreamstar-enterprises

resolved

Comment From: B1az3-Basil

Im having this issue