package com.bootdo.system.shiro;

import com.bootdo.common.config.ApplicationContextRegister;


import com.bootdo.system.service.TokenCachService;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.LogoutFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;


/**
 * 登出过滤
 * 自定义登出逻辑
 *
 * @author Mr.xiBel
 * @date 2022/4/4
 **/
public class SystemLogoutFilter extends LogoutFilter {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());


    private TokenCachService tokenCachService;



    private void init() {
        this.tokenCachService = ApplicationContextRegister.getBean(TokenCachService.class);
    }

    @Override
    protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
        init();
        Subject subject = getSubject(request, response);
        String redirectUrl = getRedirectUrl(request, response, subject);

        issueRedirect(request, response, redirectUrl);
        return false;

    }

}