简体   繁体   中英

.antMatchers(“/swagger-ui.html”).permitAll() Doesn't work

I want to open the swagger ui on my browser. This is my code

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/swagger-ui.html").permitAll()                .anyRequest().authenticated().and().httpBasic().and().csrf().disable();
    }

But it doesn't work. I still need to enter basic auth provided by httpBasic()

So I add the following code found by others

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/v2/api-docs",
                "/configuration/ui",
                "/swagger-resources/**",
                "/configuration/security",
                "/swagger-ui.html",
                "/webjars/**");
    }

Now, I can access localhost:8080/swagger-ui.html but the httpBasic window still pops up. I can click cancel to close the window and continue to use the swagger ui. But I don't know what causes the issue

从哪个控制器调用这个 swagger-ui.html 将该控制器 URL 放入 .antMatchers()。

Try this-

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
        .antMatchers("/v2/api-docs", "/configuration/ui", 
                     "/swagger-resources", "/configuration/security", 
                     "/swagger-ui.html", "/webjars/**", "/swagge‌​r-ui.html",
                     "/swagger-resources/configuration/ui", 
                     "/swagger-resources/configuration/security").permitAll() 
        .anyRequest().authenticated()
        .and().httpBasic()
        .and().csrf().disable();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM