Hi guys, I'm experimenting with the production rea...
# spring
l
Hi guys, I'm experimenting with the production ready parts of Kotlin DSL for Springboot. I'm obtaining great results, from a design perspective. Doing TDD is much more simples! But now I'm trying to introduce spring security, also with DSL (following this https://www.baeldung.com/kotlin/spring-security-dsl and this https://spring.io/blog/2020/03/04/spring-tips-kotlin-and-spring-security). When I introduce the
spring-boot-starter-security
then all the tests of the endpoints fail with 401. Do any of you knows which is the suggested approach to test DSL-defined endpoints when security is in place? Disabling security with annotations doesn't work, as also the tests doesn't use the usual @SpringBootTest annotation, but instead starts the application programmatically. I was searching for a command line argument that disables security, but without any luck :(
n
sorry, i’m not a spring security user myself 😬
l
do you secure your endpoints in some other way? Or maybe in your domain you just don't need it?
n
well, i’m not a consultant anymore so yolo 😂
🤟 1
l
for the sake of knowledge, this does the trick
Copy code
bean{
   val http: ServerHttpSecurity = ref()
   http.authorizeExchange().anyExchange().permitAll()
   http.csrf().disable()
   http.build()
}
in webflux
val http: *HttpSecurity* = ref
for spring-boot instead
k
I am curious what do you mean be starting app programmatically?
as far as I know when you include security, it will by default protect your endpoints with http basic with password printed when app starts
👍 1
l
I mean starting spring like this in tests
where
start
is
Copy code
fun start(serverPort: ServerPort = FixedServerPort(8080), args: Array<String> = emptyArray(), contextInitializer: ((ServerPort) -> BeanDefinitionDsl)? = null): ConfigurableApplicationContext {
    val arguments = arrayOf("--server.port=${serverPort.value}") + args
    return runApplication<TohExposedApplication>(*arguments){
        addInitializers(contextInitializer?.invoke(serverPort)
            ?: initializeContext())
    }
}
instead of using annotations
selecting modules to enable become much more simple
k
interesting thx
👍 1