8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

spring-boot-starter-securityでログアウト前に処理を入れたい

Last updated at Posted at 2017-01-26

お仕事でログアウト前に事前処理を入れる必要があったので、
対応した時のちょっとしたメモ。

##実装

SampleConfiguration.java
public class SampleConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    private MyLogoutHandler myLogoutHandler;

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
            .logout()
            .logoutUrl("/auth/logout")
            .logoutSuccessUrl("/auth/")
            .addLogoutHandler(myLogoutHandler)
            .invalidateHttpSession(true)
            .deleteCookies("JSESSIONID", "SESSION", "remember-me")
            .permitAll();
       }
}
MyLogoutHandler.java
@Component
public class MyLogoutHandler implements LogoutHandler{
	@Override
	public void logout(HttpServletRequest request, HttpServletResponse response,
			Authentication authentication){
        // 何かの処理
                // authentication.getName() でログインIDが取れる
	}
}

##結果
どうにか出来ないかと思って、LogoutFilterのソース読んでたら、
そもそも複数受け入れるように出来てたってオチ。
LogoutHandlerもInterfaceだったので、意外とサクッと対応できてよかった。

8
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?