TaleLin / lin-cms-spring-boot

🔨 基于SpringBoot的CMS/DMS/管理系统开发框架
http://doc.cms.talelin.com/
MIT License
912 stars 255 forks source link

io.github.talelin.core.token.DoubleJWT#generateToken 有线程安全问题,登录A账号进入B账号 #324

Open huangjiesen opened 1 year ago

huangjiesen commented 1 year ago

描述 bug image

image

如何再现

image
    @Autowired
    private DoubleJWT jwt;

    @Test
    public void test() throws Exception {
        ExecutorService executorService = new ThreadPoolExecutor(8, 20,100L, TimeUnit.SECONDS,new LinkedBlockingQueue<>());

        for (int i = 0; i < 300; i++) {
            executorService.execute(() -> {
                long userId = IdWorker.getId();
                String token = jwt.generateAccessToken(userId);

                Map<String, Claim> map = jwt.decodeAccessToken(token);
                Long identity = map.get("identity").asLong();

                assertTrue("线程安全问题,userId:" + userId + ",identity:" + identity, identity.equals(userId));
            });
        }
    }