公众号:架构师与哈苏
关注公众号进入it交流群! 公众号:架构师与哈苏 不定时都会推送一些实用的干货。。。

HttpSessionConfig.java

package com.meeno.common.session;

import com.meenoframework.common.filter.SessionUser;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Configuration
public class HttpSessionConfig {

    private static final Map<Long, HttpSession> sessions = new ConcurrentHashMap<>();

    public static List<HttpSession> getActiveSessions() {
        return new ArrayList<>(sessions.values());
    }

    public static void add(Long userId, HttpSession session){
        sessions.put(userId, session);
    }

    public static void delete(Long userId){
        HttpSession httpSession = sessions.get(userId);
        if(httpSession != null){
            sessions.remove(userId);
            httpSession.invalidate();
        }
    }

}

退出登录

HttpSessionConfig.delete(baseUser.getId());
posted on 2021-01-05 15:45  公众号/架构师与哈苏  阅读(857)  评论(0编辑  收藏  举报