.antMatchers( "/swagger-ui.html" ).permitAll() 不起作用



我想在浏览器上打开swagger ui。这是我的代码

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

但它不起作用。我仍然需要输入httpBasic((提供的基本身份验证

所以我添加了其他发现的以下代码

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

现在,我可以访问localhost:8080/swagger-ui.html,但httpBasic窗口仍然弹出。我可以单击"取消"关闭窗口并继续使用swagger ui。但我不知道问题的原因

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

试试这个-

@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();
}

最新更新