繁体   English   中英

使用Spring Security后,$ http请求给出403?

[英]$http request giving 403 after using Spring Security?

以下是我正在使用的SecurityConfiguration类。

@SpringBootApplication
@RestController
public class WebMvcConfig {
@Configuration
protected static class SecurityConfiguration extends 
WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {


  http.authorizeRequests()
  .antMatchers("/login").permitAll()
  .antMatchers("/**").authenticated()
  .anyRequest().authenticated()
  .and()
  .formLogin().permitAll();
  }
}

启动后,一旦我点击URL( http:// localhost:8080 / TestApp / ),它将带我到默认登录页面,并在输入默认用户ID(用户)和密码(打印在控制台上)时进入,将我带到通过我的AngularJS路由由“ /” URL映射的index.html页面。 我可以在用户界面中导航,但是一旦提交任何$ http请求(我正在尝试POST请求),它就会在浏览器控制台上显示$ 403和我的$ http请求URL。

有人可以帮忙吗?

错误403表示您被禁止访问所有资源。

如果检查错误详细信息,则很可能会Expected CSRF token not found诸如Expected CSRF token not found的消息。

从v4开始, spring security默认csrf保护。 这是一个好习惯,因为csrf攻击会迫使最终用户在当前已通过身份验证的Web应用程序上执行不需要的操作。

因此,在开发环境中,添加http.csrf().disable(); 将解决您的问题。 但是,当您要移至产品环境时,应考虑添加csrf令牌。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM