Java 구성에서 Spring Security 3.2.0.RC2를 사용하고 있습니다. /v1/**에서 기본 인증을 요청하는 간단한 HttpSecurity 구성을 설정했습니다. GET 요청이 작동하지만 POST 요청은 실패 :Java 구성을 사용하는 Spring-Security에서 httpBasic POST가 csrf 토큰을 원하는 이유는 무엇입니까?
이HTTP Status 403 - Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.
내 보안 설정은 다음과 같습니다이에
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Resource
private MyUserDetailsService userDetailsService;
@Autowired
//public void configureGlobal(AuthenticationManagerBuilder auth)
public void configure(AuthenticationManagerBuilder auth)
throws Exception {
StandardPasswordEncoder encoder = new StandardPasswordEncoder();
auth.userDetailsService(userDetailsService).passwordEncoder(encoder);
}
@Configuration
@Order(1)
public static class RestSecurityConfig
extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/v1/**").authorizeRequests()
.antMatchers("/v1/**").authenticated()
.and().httpBasic();
}
}
}
어떤 도움이 크게 감사합니다.
당신은 추가 할 수 있습니다 (이 이유가 있기 때문에) CSRF를 비활성화 할 dan't 경우 csrf-value가있는 숨겨진 필드와 starmandeluxe와 같은 값을 추가하면 허용 된 게시물에 제안됩니다. 이것은 내게 잘 작동했지만, csrf를 비활성화하지 않고 – Xtroce
@Xtroce가 맞다. 제 경우에는 Ajax 포스트 * 헤더에'X-CSRF-TOKEN '을 추가해야했습니다. (아약스 게시물 * parameters *에'_csrf'를 추가하는 것은 효과가 없었습니다.) – inanutshellus
@Xtroce 주석에 덧붙이면, 템플릿으로 thymeleaf를 사용하면