Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring security+;在SecurityContextunauthorized问题中未找到身份验证对象_Spring_Security - Fatal编程技术网

Spring security+;在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

当我尝试使用url调用swagger页面时,我得到一个错误,即在SecurityContextunauthorized问题中找不到身份验证对象。我添加了安全配置,比如

 @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(跳过安全筛选器),因此您无法访问授权数据。