View Javadoc
1   package cn.home1.oss.lib.security.internal.preauth;
2   
3   import cn.home1.oss.lib.security.api.GenericUser;
4   import cn.home1.oss.lib.webmvc.api.TypeSafeCookie;
5   
6   import lombok.NonNull;
7   import lombok.Setter;
8   
9   import org.springframework.beans.factory.annotation.Autowired;
10  import org.springframework.beans.factory.annotation.Qualifier;
11  import org.springframework.security.core.Authentication;
12  import org.springframework.security.web.authentication.logout.LogoutHandler;
13  
14  import javax.servlet.http.HttpServletRequest;
15  import javax.servlet.http.HttpServletResponse;
16  
17  /**
18   * see: {@link org.springframework.security.web.authentication.logout.LogoutFilter}.
19   *
20   * <p>Created by zhanghaolun on 16/7/6.</p>
21   */
22  public class PreAuthTokenCookieClearingLogoutHandler implements LogoutHandler {
23  
24    @Qualifier(GenericUser.GENERIC_USER_COOKIE)
25    @Autowired(required = false)
26    @Setter
27    @NonNull
28    private TypeSafeCookie<GenericUser> cookie;
29  
30    @Override
31    public void logout( //
32      final HttpServletRequest request, //
33      final HttpServletResponse response, //
34      final Authentication authentication //
35    ) {
36      if (this.cookie != null) {
37        this.cookie.clearCookie(request, response);
38      }
39    }
40  }