我使用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進行的任何後續請求將被識別。