Javascript 为什么可以';我不能重定向到具有spring security的页面吗?
这太简单了。 如果我在浏览器中输入/toQuestion的url,我将成功重定向到我想要的页面。 但是,根据我的js代码:Javascript 为什么可以';我不能重定向到具有spring security的页面吗?,javascript,java,spring,spring-boot,spring-security,Javascript,Java,Spring,Spring Boot,Spring Security,这太简单了。 如果我在浏览器中输入/toQuestion的url,我将成功重定向到我想要的页面。 但是,根据我的js代码: window.location.href = "/toQuestion"; 我将返回到我配置的登录页面: http.authorizeRequests( authorizeRequests -> authorizeRequests .mvcMatchers(
window.location.href = "/toQuestion";
我将返回到我配置的登录页面:
http.authorizeRequests(
authorizeRequests -> authorizeRequests
.mvcMatchers(
"/js/**",
"/css/**",
"/chief",
"/toQuestion").permitAll()
.anyRequest().authenticated()
)
.formLogin(
form -> form
.loginPage("/chief")
.permitAll()
)
是否需要设置任何配置?看起来您只允许经过身份验证的用户,这就是它重定向的原因。对于非用户身份验证,您必须执行以下操作:
...http.authorizeRequests(authorizeRequests -> authorizeRequests
"/toQuestion").permitAll();...
您可以将包org.springframework.security的日志级别更改为debug并查看重定向到登录页的原因。好的。我解决了它。因为我没有实现AuthenticationProvider的supports方法来指示此AuthenticationProvider支持的身份验证对象。我已授予了“/toQuestion”权限给任何未经身份验证的用户。好的。我解决了它。因为我没有实现AuthenticationProvider的supports方法来指示此AuthenticationProvider支持哪个身份验证对象。