RAFJR
RAFJR

Reputation: 432

How to bypass Authorization in Swagger UI using springfox

I need to bypass spring security when the request is coming from Swagger-UI, test environment. This is so we can test quickly without having to generate a new token every time since the data is test anyway.

My application is running on Spring Boot. I implemented Spring security so that user will have to provide a valid access token (header) in order to get a valid response, otherwise the application will return HTTP 401. It works well with Spring Fox but I need a way to turn off or at least provide a static token in Authorization so tester won't have to do it for every request.

I tried going through their documentation hoping to find a switch to turn it off specifically when the request is coming from Swagger UI.

I'm using: -Springboot 2.0.3 -springfox 2.8.0

Upvotes: 0

Views: 1538

Answers (1)

kumar
kumar

Reputation: 497

using this one ....

@SpringBootApplication(exclude = {SecurityAutoConfiguration.class })

or else

@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
    http.authorizeExchange().anyExchange().permitAll();
    return http.build();
}

Upvotes: 1

Related Questions