ima*_*ban 5 spring-mvc spring-security basic-authentication
我有一个使用基本身份验证以Spring Security运行的Spring Boot应用程序。提供正确的基本身份验证凭据后,将调用控制器方法,但是对于不正确的身份验证凭据,我收到的是404 Not Found而不是401 Unauthorized。
这是我的Spring Security Config
@Configuration
public static class ApiSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/useradmin/api")
.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic().authenticationEntryPoint(authenticationEntryPoint()).and().csrf().disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("default").password("password").roles("USER");
}
}
Run Code Online (Sandbox Code Playgroud)
我已经用无效的凭据将基本身份验证重定向到/ error审查了Spring Security,并且如果我ErrorMvcAutoConfiguration.class从自动配置类中排除,则会得到401。但是,如果我将其保留为自动配置,则只会得到404,实际上它没有/error像前面提到的问题一样被重定向到说。
我创建了自己的实现BasicErrorController,我在getError方法上设置了一个断点,但从未实现过此点,因此我认为有其他事情正在捕获响应并将其状态从401更改为404。
还有什么可能是这个问题的根源?
| 归档时间: |
|
| 查看次数: |
853 次 |
| 最近记录: |