Spring security+;在SecurityContextunauthorized问题中未找到身份验证对象
当我尝试使用url调用swagger页面时,我得到一个错误,即在SecurityContextunauthorized问题中找不到身份验证对象。我添加了安全配置,比如Spring security+;在SecurityContextunauthorized问题中未找到身份验证对象,spring,security,Spring,Security,当我尝试使用url调用swagger页面时,我得到一个错误,即在SecurityContextunauthorized问题中找不到身份验证对象。我添加了安全配置,比如 @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override public void configure(WebSecurity web) throws
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
super.configure(web);
web.ignoring()
.antMatchers("/api/swagger-ui.html")
.antMatchers("/swagger-ui.html");
}
}
但它不起作用。有人知道如何面对这个问题吗?请参见此处“忽略”方法的说明:这是您的配置
.antMatchers(“/api/swagger ui.html”,“/swagger ui.html”).permitAll()
请检查a以了解将来的情况。
.permitAll()
是您最好的朋友:)我不想允许所有操作,只想禁用/api/swagger-ui.html的安全性:-(对于特定的api,permitAll
和禁用的安全性之间有什么区别?permitAll
可以与特定的antMatchers
一起工作,你能给我一个例子吗?检查答案:)你应该允许全部或匿名使用。当你使用WebSecurity时,你根本没有SecurityContext(跳过安全筛选器),因此您无法访问授权数据。