我在我的web应用程序中使用了下面的代码来限制put、delete和选项请求,但是测试响应显示200 OK。
有什么建议吗?
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.and().formLogin().loginPage("/login").permitAll()
.and().logout().logoutSuccessHandler(customLogOutHandler()).permitAll();
http.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/**").denyAll()
.antMatchers(HttpMethod.PUT, "/**").denyAll()
.antMatchers(HttpMethod.DELETE, "/**").denyAll();
super.configure(http);
http.cors();
}发布于 2019-08-18 08:57:38
删除super.configure(http);,它将用下面的方法覆盖您的配置,而denyAll()将不会拒绝使用方法的请求
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin().and()
.httpBasic();
}发布于 2019-08-16 08:39:38
尝试配置Security,以便根据用于访问URL模式的HTTP方法不同地保护对特定URL模式的访问。
http.authorizeRequests().antMatchers(HttpMethod.OPTIONS,"/path/to/deny").denyAll();
http.authorizeRequests().antMatchers(HttpMethod.DELETE,"/you/can/alsoSpecifyAPath").denyAll();
http.authorizeRequests().antMatchers(HttpMethod.PUT,"/and/can/haveWildcards/*").denyAll();https://stackoverflow.com/questions/57519676
复制相似问题