Xiajijian
2025-09-29 52039daeb631bc47cfd953f05c8a5c76aa199ede
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.ard.framework.security.handle;
 
import com.ard.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
@Component
public class CustomAuthenticationSuccessHandler {
 
    @Autowired
    private RedisCache redisCache;
 
    public void onAuthenticationSuccess(Long userId) {
        // 检查 Redis 中是否已有该用户登录
        String key = "login_userid:" + userId;
        if (redisCache.hasKey(key)) {
            throw new RuntimeException("用户已登录,请勿重复登录");
        }
    }
}