package cn.reghao.oss.console.account.security.handler;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 账号注销成功后的处理, 使用此类后不再调用 logoutSuccessUrl, 在此类中直接返回给客户端
 * 账号注销的调用顺序 LogoutHandlerImpl -> LogoutSuccessHandlerImpl
 *
 * @author reghao
 * @date 2023-02-14 16:11:48
 */
@Component
public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication auth)
            throws IOException, ServletException {
        String redirectPath = "/login";
        response.sendRedirect(redirectPath);
    }
}
