1
스프링 보안에서 AJAX 요청을 처리하는 데 어려움이 있습니다.요청 방법 'POST'가 스프링 보안에서 지원되지 않습니다.
스프링 보안 설정은 (자바 설정)입니다 :
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/themes/**").permitAll()
.anyRequest().access("hasRole('ROLE_USER')")
.antMatchers("/offerings/**").access("hasRole('ROLE_ADMIN')")
.antMatchers("/users").access("hasRole('ROLE_ADMIN')")
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/login?logout")
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)
.permitAll()
.and()
.csrf();
}
AJAX 핸들이
@RequestMapping(value = "/user/edit", method = RequestMethod.POST)
public ModelAndView edit(@RequestParam Map<String, String> allRequestParams) {
...
}
그리고 AJAX JS 코드는 내가하지 않으면
$.ajax({
url: '/user/edit',
type: 'POST',
...
});
모든 것이 잘 작동합니다입니다 csrf
은 다음과 같이 구성됩니다. csrf().disable()
. 따라서 csrf
이 활성화되어있을 때 AJAX 요청을 처리하는 방법.
+1, 아약스 요청에서 csrf 토큰을 설명하는 것이 좋습니다 .... 여기에서 찾았습니다 http://docs.spring.io/spring-security/site/docs/3.2.0.CI-SNAPSHOT/reference/html /csrf.html –