允许获取请求,但不允许后期请求(Spring Security)

ann*_*irq 3 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());
    }
Run Code Online (Sandbox Code Playgroud)

我可以发送get-request链接以“ / auth”开头,但是如果没有身份验证就无法发送后请求。如果删除跟随代码,一切正常:

.authorizeRequests()
.antMatchers("/**").authenticated()
.anyRequest().permitAll()
Run Code Online (Sandbox Code Playgroud)

但是我需要在除“ / auth **”之外的任何页面上进行身份验证

Pet*_*erS 5

答案很晚,但是像大多数人一样,我讨厌没有答案的问题。我认为您在问如何阻止对/ auth **的身份验证。

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

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

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