package com.ruoyi.framework.config;

import javax.servlet.DispatcherType;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import com.ruoyi.framework.web.filter.SessionCookieRewriteFilter;

/**
 * 注册会话 Cookie 改写过滤器（须早于 Shiro，才能包住 Set-Cookie）
 */
@Configuration
public class SessionCookieFilterConfig
{
    @Bean
    public FilterRegistrationBean<SessionCookieRewriteFilter> sessionCookieRewriteFilterRegistration()
    {
        FilterRegistrationBean<SessionCookieRewriteFilter> registration = new FilterRegistrationBean<>();
        registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE);
        registration.setFilter(new SessionCookieRewriteFilter());
        registration.addUrlPatterns("/*");
        registration.setName("sessionCookieRewriteFilter");
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 20);
        return registration;
    }
}
