All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bybutter.sisyphus.starter.webflux.CorsConfigurationSourceRegistrar.kt Maven / Gradle / Ivy

There is a newer version: 2.1.22
Show newest version
package com.bybutter.sisyphus.starter.webflux

import com.bybutter.sisyphus.spring.BeanUtils
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory
import org.springframework.beans.factory.support.BeanDefinitionBuilder
import org.springframework.beans.factory.support.BeanDefinitionRegistry
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
import org.springframework.web.cors.reactive.CorsConfigurationSource
import org.springframework.web.cors.reactive.CorsWebFilter
import org.springframework.web.server.WebFilter

class CorsConfigurationSourceRegistrar : BeanDefinitionRegistryPostProcessor {
    override fun postProcessBeanFactory(beanFactory: ConfigurableListableBeanFactory) {
    }

    override fun postProcessBeanDefinitionRegistry(registry: BeanDefinitionRegistry) {
        val definitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(WebFilter::class.java) {
            val corsConfigSource = BeanUtils.getSortedBeans(
                registry as ConfigurableListableBeanFactory,
                CorsConfigurationSource::class.java
            ).values
            CorsWebFilter(DelegatingCorsConfigurationSource(corsConfigSource))
        }
        registry.registerBeanDefinition("corsConfiguration", definitionBuilder.beanDefinition)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy