package com.ruoyi.framework.shiro.web.filter.embed;

import java.io.IOException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.shiro.web.filter.authc.UserFilter;
import org.apache.shiro.web.util.WebUtils;

/**
 * 未登录跳转登录页时保留 embed=1，避免 iframe 内丢失嵌入态后反复 LOGIN_READY。
 */
public class EmbedAwareUserFilter extends UserFilter
{
    @Override
    protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException
    {
        String loginUrl = getLoginUrl();
        if (EmbedRequestUtils.isEmbed(request))
        {
            loginUrl = EmbedRequestUtils.withEmbedParams(loginUrl);
        }
        WebUtils.issueRedirect(request, response, loginUrl);
    }
}
