首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >允许get-request但不允许post-request (Spring Security)

允许get-request但不允许post-request (Spring Security)
EN

Stack Overflow用户
提问于 2015-08-05 20:10:38
回答 1查看 4.8K关注 0票数 5

我尝试配置Spring Security。我有以下配置:

代码语言:javascript
复制
@Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                    .antMatchers("/auth**").permitAll()
                .and()
                .authorizeRequests()
                    .antMatchers("/**").authenticated()
                    .anyRequest().permitAll()
                .and()
                    .httpBasic()
                .and()
                    .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                    .userDetailsService(userDetailsService());
    }

我可以向以"/auth“开头的链接发送get-request,但没有身份验证就不能发送post-request。如果我删除了下面的代码,一切都是正常的:

代码语言:javascript
复制
.authorizeRequests()
.antMatchers("/**").authenticated()
.anyRequest().permitAll()

但我需要对任何页面进行身份验证,除了"/auth**“

EN

回答 1

Stack Overflow用户

发布于 2017-04-12 00:34:22

一个非常晚的答案,但像大多数人一样,我讨厌没有答案的问题。我想您是在问如何防止对/auth**进行身份验证。

您应该覆盖其他配置方法:

代码语言:javascript
复制
@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers(HttpMethod.POST, "/auth/**");
}

这将不会对该URL执行任何身份验证。换句话说,它是一个公共URL,例如,人们可以通过它发布一个提醒密码请求。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31832148

复制
相关文章

相似问题

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