【问题标题】:Allow get-request but not post-request (Spring Security)允许 get-request 但不允许 post-request (Spring Security)
【发布时间】:2015-08-05 12:10:38
【问题描述】:

我尝试配置 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”开头的链接,但不能在没有身份验证的情况下发送 post-request。如果我删除跟随代码一切正常:

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

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

【问题讨论】:

    标签: spring-security


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 谢谢!这救了我??
    猜你喜欢
    • 2022-10-24
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 2019-05-31
    • 1970-01-01
    • 2019-02-13
    • 1970-01-01
    • 2015-07-22
    相关资源
    最近更新 更多