Spring Security拒绝客户端的所有请求

时间:2016-11-29 10:29:46

标签: java spring reactjs spring-security spring-rest

我正在使用ReactJS和Spring REST以及Spring Security,当我做类似的事情时:

var myInit = {
  method: 'GET',
  headers: myHeaders,
  mode: 'cors',
  cache: 'default'
};

fetch("http://localhost:8080/api/employees", myInit)
  .then(function (response) {
      console.log(response.json());
    }
  )
  .catch(function (error) {
    console.log('There has been a problem with your fetch operation: ' + error.message);
  });

浏览器在Unexpected token < in JSON at position 0处发布了<!DOCTYPE..。 我确定这个问题是我的WebSecurityConfig的结果:

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
      .antMatchers("/login", "/css/**", "/built/**").permitAll()
      .anyRequest().authenticated()
      .and()
      .formLogin()
      .loginPage("/login")
      .usernameParameter("username").passwordParameter("password")
      .defaultSuccessUrl("/", true)
      .and()
      .httpBasic()
      .and()
      .logout()
      .logoutUrl("/logout")
      .logoutSuccessUrl("/login?logout")
      .and()
      .exceptionHandling().accessDeniedPage("/403")
      .and()
      .csrf();
  }

当我删除anyRequest.authenticated时。它再次起作用,但我不知道如何解决。

0 个答案:

没有答案