我使用ReactJS +春季启动/社会/安全的web应用程序内置。Spring Security中authenticated()和csrf之间有什么区别?
我要确保当我放开,我免受CSRF。我使用的是最春季安全的开箱及以下是我的基本配置()重写:
@Configuration
@Order (SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login/facebook").permitAll()
.antMatchers("/logout").permitAll()
.antMatchers("/api/**").authenticated()
.and().csrf().disable();
}
}
我的问题是,因为我所有的(/ API/**)请求到后端的只是允许通过身份验证,这是否可以保护我免受CSRF的侵害?
需要明确的是,当用户通过Spring社交插件与Facebook进行身份验证,我在后台的应用程序来处理登录成功呼叫重定向到端点(/登录/ Facebook的)。在这种方法中,我做到以下几点:
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(theUser.getFacebookId(), null, null);
SecurityContextHolder.getContext().setAuthentication(authentication);
这可以确保通过身份验证到/ API进行的任何后续请求将被识别。