java - spring security 和 basic auth 只有一个 entryPoint:如何管理另一个端点上的错误
问题描述
我只需要在我的控制器方法之一中添加基本身份验证其他方法没有身份验证,但仍然有一个@PreAuthorize
以检查参数是否有效。
我的问题是,httpbasic 转换 preAuthorize 在 401 中抛出的所有异常(有些应该是 403 等)。我觉得我的所有端点都在基本身份验证之下,而不仅仅是我使用的那些@Secured
我怎样才能避免这种情况?
我的代码:
@Controller
class MyController {
@Secured("BASIC_AUTHENTIFIED")
public void someMethodOnlyForAuthentified(){...}
@PreAuthorize("check(parameters)")
public void someMethodForEveryone(List<String> parameters){...}
}
在我的安全配置中:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser(login).password(password).roles("BASIC_AUTHENTIFIED");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.authorizeRequests().antMatchers("/**").permitAll()
.anyRequest().authenticated()
.and().httpBasic()
.and().csrf().disable();
}
解决方案
推荐阅读
- asp.net - 下拉列表数据库
- css - 如何使 div 可滚动且高度不会导致父元素溢出?
- angular - 更改 html 表数据取决于另一个组件角度 8 的下拉值
- laravel-livewire - Laravel livewire 脚本完整路径
- spring - OpenAPI 使用“oneof”属性从 swagger 生成 spring
- sql - 如何汇总 BigQuery 中排除窗口的列中的所有值,然后将结果设置到此排除窗口中?
- r - 如何迭代rep()中的变量
- python - .pop() 不会为双端队列对象执行
- jquery - 根据 CORS 预检响应 ajax django 中的标头“Access-Control-Allow-Headers”,标头“access-control-allow-credentials”是不允许的
- java - android 6.0以后可以去掉wifi网络吗?