2

I need to disable spring-security in my integration test. I'm using Spring boot 2.2.0 and in this version, I didn't find some methods to do it.

@EnableAutoConfiguration(exclude = {SecurityAutoConfiguration.class, SecurityFilterAutoConfiguration.class}) // not working

@EnableAutoConfiguration(exclude = { SecurityAutoConfiguration.class, ManagementSecurityAutoConfiguration.class }) // not working too.

how can I do it?

John
  • 833
  • 6
  • 23
  • 1
    Does this answer your question? [Disable security for unit tests with spring boot](https://stackoverflow.com/questions/31169720/disable-security-for-unit-tests-with-spring-boot) – Fateh Dec 12 '19 at 14:42
  • @Fateh no, these not working for me! I've read this post earlier. – John Dec 12 '19 at 14:43

2 Answers2

0

you could play this game via profile

@ActiveProfiles(value = "IntegrationTest")
public class myTest {
Fateh
  • 291
  • 1
  • 6
  • 25
  • it is not working for me. Can you give me more description of how to do it? – John Dec 12 '19 at 14:50
  • if you could the answer with **42 up vote** in this link https://stackoverflow.com/questions/31169720/disable-security-for-unit-tests-with-spring-boot – Fateh Dec 12 '19 at 14:54
0

You and I must have been banging our heads against the same thing at the same time it seems.

I was able to make @AutoConfigureMockMvc(secure=false) do exactly what I wanted--disable all security for my unit tests. However, it was immediately marked deprecated in my IDE because I was using Spring Boot 2.1.6. I don't like using deprecated things so I tried and tried to get the exclude attribute to work, but it never did.

I was about to give up on it and suffer with the deprecation warning because at least my unit tests worked with it.

On a whim, I tried upgrading Spring Boot in my project from 2.1.6 to 2.2.2. To my horror, the secure attribute was no longer deprecated--it was removed altogether! I gave the unit test a spin with the attribute gone, but with the exclude attribute populated exactly as you show in your question and it worked!

TL;DR? Upgrade to Spring Boot 2.2.2

Community
  • 1
  • 1
bmauter
  • 2,831
  • 4
  • 19
  • 23