首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在springboot中限制put、delete和options请求

在springboot中限制put、delete和options请求
EN

Stack Overflow用户
提问于 2019-08-16 06:14:53
回答 2查看 830关注 0票数 0

我在我的web应用程序中使用了下面的代码来限制put、delete和选项请求,但是测试响应显示200 OK。

有什么建议吗?

代码语言:javascript
运行
复制
@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();

    }
EN

回答 2

Stack Overflow用户

发布于 2019-08-18 08:57:38

删除super.configure(http);,它将用下面的方法覆盖您的配置,而denyAll()将不会拒绝使用方法的请求

代码语言:javascript
运行
复制
protected void configure(HttpSecurity http) throws Exception {

        http
            .authorizeRequests()
                .anyRequest().authenticated()
                .and()
            .formLogin().and()
            .httpBasic();
    }
票数 0
EN

Stack Overflow用户

发布于 2019-08-16 08:39:38

尝试配置Security,以便根据用于访问URL模式的HTTP方法不同地保护对特定URL模式的访问。

代码语言:javascript
运行
复制
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();
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57519676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档