ReactJS + Spring Boot/Social/Securityを使って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 Socialプラグインを使用してFacebookで認証すると、バックエンドアプリケーションのエンドポイント(/ login/facebook)にコールをリダイレクトしてログインに成功します。この方法では、私は次の操作を行います。
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(theUser.getFacebookId(), null, null);
SecurityContextHolder.getContext().setAuthentication(authentication);
これは、認証済みとして/ APIに行われた後続の要求が認識されることを確認します。