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

时间:2015-08-05 12:10:38

标签: spring-security

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

@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());
    }

我可以将get-request发送到以" / auth"开头的链接,但无法在不进行身份验证的情况下发送请求。如果我删除关注代码,一切正常:

.authorizeRequests()
.antMatchers("/**").authenticated()
.anyRequest().permitAll()

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

1 个答案:

答案 0 :(得分:3)

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

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

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers(HttpMethod.POST, "/auth/**");
}

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

相关问题