Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
huangjiesen opened this issue Jan 26, 2023 · 0 comments

Comments

@huangjiesen
Copy link

huangjiesen commented Jan 26, 2023

描述 bug
image

image

  • 你是如何操作的?
   public class DoubleJWT {
    private JWTCreator.Builder builder;
    public String generateToken(String tokenType, long identity, String scope, long expire) {
        Date expireDate = DateUtil.getDurationDate(expire);
        // builder对象存在线程安全问题
        return builder
                .withClaim("type", tokenType)
                .withClaim("identity", identity)
                .withClaim("scope", scope)
                .withExpiresAt(expireDate)
                .sign(algorithm);
    }
}

如何再现
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));
            });
        }
    }
@huangjiesen huangjiesen changed the title io.github.talelin.core.token.DoubleJWT#generateToken 有线程安全问题 io.github.talelin.core.token.DoubleJWT#generateToken 有线程安全问题,登录A账号进入B账号 Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant