を働いていません。私はアクセストークン(JWT実装)をhttpOnly
Cookieに保存しています。投稿リクエストに対するXSRF攻撃から身を守るために、ログインページを除くすべてのページでXSRF保護を有効にする必要があります。春のセキュリティガイドhereで、CookieCsrfTokenRepository
を有効にしました。私は、パブリックAPI(GET
)を打ったとき春のセキュリティCookieBasedCSrf私はAngular2フロントエンドとRESTfulな春のバックエンドを開発しています
しかし、XSRF-TOKENが設定されていません。また、Angular2からのログインフォームデータを送信すると、システムは「無効なcsrfトークン」エラーを表示します。
http
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.and()
.exceptionHandling()
.authenticationEntryPoint(this.authenticationEntryPoint)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers(TOKEN_REFRESH_ENTRY_POINT).permitAll() // Token refresh end-point
.antMatchers(TOKEN_CSRF_ENTRY).permitAll()
.and()
.authorizeRequests()
.antMatchers(TOKEN_BASED_AUTH_ENTRY_POINT).authenticated() // Protected API End-points
.and()
.cors()
.and()
.addFilterBefore(buildAjaxLoginProcessingFilter(), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(buildJwtTokenAuthenticationProcessingFilter(), UsernamePasswordAuthenticationFilter.class);