question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot intercept /v2/api-docs ?

See original GitHub issue

springfox 2.9.2 springboot 2.0.3 I want intercept /v2/api-docs, The code is as follows, But,the code no entry into force ! why?why?why?

@Component
public   class Swagger2WebMvcConfigurerAdapter extends WebMvcConfigurerAdapter{
   @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getSwaggerInterceptor()).addPathPatterns("/v2/api-docs");
        super.addInterceptors(registry);
    }
    @Bean
    public HandlerInterceptor getSwaggerInterceptor() {
        return new Swagger2Interceptor();
    }
}
public class Swagger2Interceptor extends HandlerInterceptorAdapter{
 @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
     // I want to do something.
    return super.preHandle(request, response, handler);
     }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
JoseCarlosAlcommented, Nov 6, 2019

I have the same problem. Are there any solution without spring security? Same version 2.9.2

1reaction
Cejkis-zzcommented, Jan 10, 2019

I solved this by Spring security (this code is in kotlin but doesnt matter). Perhaps it might help you

Eventually I solved this by spring security, as @UsamaAmjad proposed. 

    open class SecurityInitializer : AbstractSecurityWebApplicationInitializer()

    @Configuration
    @EnableWebSecurity
    open class SecurityConfig : WebSecurityConfigurerAdapter() {
    
    
        @Throws(Exception::class)
        override fun configure(http: HttpSecurity) {
            http.antMatcher("/docs/swagger/v2/api-docs").addFilter(myFilter())
        }
    
        open fun myFilter() = object : FilterSecurityInterceptor() {
            override fun doFilter(request: ServletRequest?, response: ServletResponse?, chain: FilterChain?) {
                
                if (do your stuff here) {
                    chain!!.doFilter(request,response) // continue with other filters
                } else {
                    super.doFilter(request, response, chain) // filter this request
                }
            }
        }
    }
<dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>5.1.1.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>5.1.1.RELEASE</version>
        </dependency>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to configure Spring Security to allow ... - Stack Overflow
Main issue: Not able to access swagger URL at http://localhost:8080/api/v2/api-docs. It says Missing or invalid Authorization header. Screenshot ...
Read more >
Spring Boot 2.3.1 available now
This release includes 127 bug fixes, enhancements, documentation improvements, and dependency upgrades. Thanks to all those who have contributed ...
Read more >
swagger-ui - npm
Function to intercept try-it-out responses. ... XMLHttpRequest cannot load http://sad.server.com/v2/api-docs.
Read more >
Spring Boot run Error :: Application - Google Groups
After successful build when I run spring boot command I get below error. Attached is log. PLease help. C:\MyWork\shopizer\ ...
Read more >
How to disable the custom atlassian spring boot interceptors ...
You can skip this interceptor by setting an @IgnoreJwt annotation to the controller ... Or is there another solution for this problem?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found