如何解决当禁用CSRF时,Spring Security仍禁止js提取请求
我正在使用Spring Security将身份验证添加到后端使用Spring Boot的网页。当用户身份验证成功时,用户将被重定向到具有jQuery数据表的主页。数据表尝试从服务器获取其数据,但是Ajax请求获得403响应。我已禁用CSRF,所以为什么请求被禁止?
这是我的安全配置:
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login","/resource/**").permitAll()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.GET,"/*").hasRole("USER")
.and()
.authorizeRequests()
.antMatchers(HttpMethod.POST,"/*").hasRole("USER")
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.successForwardUrl("/xgateUI")
.failureUrl("/error")
.and()
.logout()
.logoutUrl("/doLogout")
.logoutSuccessUrl("/logout")
.permitAll()
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID")
.and()
.csrf().disable();
}
这是数据表的Ajax部分
var table = $("#filesTable").DataTable({
sAjaxSource: "/getAllRows",...
});
用户通过身份验证
class CustomAuthenticationProvider implements AuthenticationProvider.
List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
grantedAuthorities.add(new SimpleGrantedAuthority("USER"));
日志显示用户已成功通过身份验证。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。