首页 > 解决方案 > 为什么我的 spring 安全配置不起作用?

问题描述

如果我使用浏览器导航到 /toQuestion 的 url,它将成功打开。

但是,通过使用 js 代码:

window.location.href = "/toQuestion";

我将被重定向回 /chief 的登录页面,我是这样配置的:

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

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

我已向任何未经身份验证的用户授予“/toQuestion”权限。我需要设置任何其他配置吗?

标签: spring-bootspring-mvcspring-security

解决方案


OK.我解决了。在我更改包org.springframework.security的级别调试细节后,我意识到我没有实现AuthenticationProvider的supports方法来指示这个AuthenticationProvider支持哪个Authentication Object。


推荐阅读