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

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.security.core.session.SessionRegistryImpl;
import org.springframework.security.web.session.ConcurrentSessionFilter;
import org.springframework.security.web.session.HttpSessionEventPublisher;

/**
 * spring-security 中涉及 session 处理的相关配置
 *
 * @author reghao
 * @date 2024-02-02 17:18:12
 */
@Configuration
public class SecuritySessionConfig {
    @Bean
    public SessionRegistry sessionRegistry() {
        return new SessionRegistryImpl();
    }

    @Bean
    public ConcurrentSessionFilter concurrentSessionFilter(SessionRegistry sessionRegistry,
                                                           SessionExpiredStrategy sessionExpiredStrategy){
        // 帐号同时登录数量超过限制时的处理类
        return new ConcurrentSessionFilter(sessionRegistry, sessionExpiredStrategy);
    }

    @Bean
    public HttpSessionEventPublisher httpSessionEventPublisher() {
        return new HttpSessionEventPublisher();
    }
}
