2017-05-04 11 views
0

のためのクッキーを削除します。私はログアウトを行うと春のセキュリティ:私は私の春のブートアプリの次のセキュリティ設定を使用して、ログアウト

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http 
     .csrf().disable() 
     .authorizeRequests() 
      .antMatchers("/login").permitAll() 
     .and() 
     .authorizeRequests() 
      .antMatchers("/signup").permitAll() 
     .and() 
     .authorizeRequests() 
      .anyRequest().authenticated() 
     .and() 
      .logout().logoutUrl("/logout").logoutSuccessUrl("/login").deleteCookies("auth_code").invalidateHttpSession(true) 
     .and() 
     // We filter the api/signup requests 
     .addFilterBefore(
      new JWTSignupFilter("/signup", authenticationManager(), 
        accountRepository, passwordEncoder), 
      UsernamePasswordAuthenticationFilter.class) 
     // We filter the api/login requests 
     .addFilterBefore(
      new JWTLoginFilter("/login", authenticationManager()), 
      UsernamePasswordAuthenticationFilter.class) 
     // And filter other requests to check the presence of JWT in 
     // header 
     .addFilterBefore(new JWTAuthenticationFilter(userDetailsServiceBean()), 
      UsernamePasswordAuthenticationFilter.class); 
} 

は、私がログイン時に設定されたクッキーを削除したいです。 deleteCookieを使用しますが、ヘッダーにはログイン時に設定されたCookieを削除するという概念はありません。どうして ?

ブラウザにCookieを削除するように教えてください。

は今のところ、レスポンスのヘッダが含まれています

Set-Cookie →JSESSIONID=E4060381B435217F7D68EAAE82903BB0;path=/;Secure;HttpOnly 

は、私は、現在の日付過去の日付にクッキーの有効期限を設定すべきか?

答えて

1

クッキーを削除する必要はありません。サーバー上でセッションが終了すると、クッキーは使用できなくなり、返された場合には置き換えられます。それは正常に期限切れにします(デフォルトでは、ブラウザが閉じられたとき)。

+0

クライアント側ではどのように 'JSESSIONID'が使用されていますか?クライアントが要求ごとにヘッダーに明示的に含める必要がありますか? –

+1

クッキーは要求のヘッダーとして自動的に送信されます。 – ThrawnCA

0

JSESSIONIDを追加します。

logout().logoutUrl("/logout").logoutSuccessUrl("/login").deleteCookies("auth_code", "JSESSIONID").invalidateHttpSession(true) 
+0

多分私は私の質問ではっきりしていなかった。私はJSESSIONIDを解除したくありません。私はそれについて気にしない。私は 'auth_code'のためにクッキーを削除したいと思います。サーバー側からクッキーを削除するには、有効期限を過去のある程度設定してから再度設定する必要がありますか?またはdeleteCookiesは十分ですか?ヘッダーには、Cookieを削除するようブラウザに指示するものはありません。 –

+1

これで十分です。 'deleteCookies'にクッキー名を設定すると、そのクッキーはレスポンスヘッダのCookieClearingLogoutHandlerによってmaxAgeが0に設定されますhttp://grepcode.com/file/repo1.maven.org/maven2/org.springframework.security/ spring-security-web/4.0.2.RELEASE/org/springframework/security/web/authentication/logout/CookieClearingLogoutHandler.java – shazin

関連する問題