【问题标题】:Why can't I redirect to an page with spring security?为什么我不能重定向到具有弹簧安全性的页面?
【发布时间】:2021-01-09 06:47:26
【问题描述】:

太简单了。 如果我在浏览器中输入/toQuestion的url,我会成功重定向到我想要的页面。 但是,通过我的 js 代码:

window.location.href = "/toQuestion";

我会回到我配置的登录页面:

http.authorizeRequests(
                authorizeRequests -> authorizeRequests
                        .mvcMatchers(
                                "/js/**",
                                "/css/**",
                                "/chief",
                                "/toQuestion").permitAll()
                        .anyRequest().authenticated()

        )
.formLogin(
                        form -> form
                                .loginPage("/chief")
                                .permitAll()
                )

我需要设置什么配置吗?

【问题讨论】:

    标签: javascript java spring spring-boot spring-security


    【解决方案1】:

    您可以更改包org.springframework.security的日志级别来调试,看看重定向到登录页面的原因。

    【讨论】:

    • OK。我解决了。因为我没有实现AuthenticationProvider的supports方法来指示这个AuthenticationProvider支持哪个Authentication Object。
    【解决方案2】:

    看起来您只允许经过身份验证的用户,这就是它重定向的原因。对于非用户身份验证,您必须执行以下操作:

    ...http.authorizeRequests(authorizeRequests -> authorizeRequests
    "/toQuestion").permitAll();...
    

    【讨论】:

    • 我已将“/toQuestion”权限授予任何未经身份验证的用户。
    【解决方案3】:

    好的。我解决了。因为我没有实现AuthenticationProvider的supports方法来指示这个AuthenticationProvider支持哪个Authentication Object。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-12
      • 2014-03-06
      • 2016-09-29
      • 2019-10-07
      • 2015-09-04
      • 2020-06-29
      • 2018-09-14
      • 2016-10-06
      相关资源
      最近更新 更多