【发布时间】:2015-04-07 15:56:06
【问题描述】:
我是 Spring Security 的新手,我已将它添加到我的项目中。一切似乎都可以完美地登录/注销,甚至可以跨屏幕导航。只有当我尝试拥有一个 ExtJS 网格并在 store 中添加一条记录然后调用 store 的 sync() 方法时,我才得到 -
Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.
我知道我需要将 _csrf 与请求一起传递,但我想从大家那里了解完成这项工作的最佳方法。请帮忙。
当调用 store 上的 sync() 方法时,如何自动通过所有 AJAX(创建/更新/删除/读取)传递这个 _csrf?
安全配置
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserService userService;
@Autowired
private BCryptPasswordEncoder encoder;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userService).passwordEncoder(encoder);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/**").access("hasRole('ROLE_ADMIN')").and().formLogin().and().csrf();
}
}
ExtJS 代码
tbar : [ '->', {
text : 'Add',
handler : function(btn) {
var grid = btn.up('grid');
var editor = grid.findPlugin('rowediting');
grid.getStore().insert(0, {});
editor.startEdit(0, 0);
}
} ],
bbar : [ '->', {
text : 'Save',
handler : function(btn) {
btn.up('grid').getStore().sync();
}
} ],
谢谢!
【问题讨论】:
标签: spring security extjs sync