jeecgboot/JeecgBoot · error · AuthenticationException

用户不存在!

Error message

用户不存在!

What it means

Thrown by ShiroRealm.checkUserTokenIsEffect() when TokenUtils.getLoginUser() returns null — the username extracted from the JWT does not correspond to any user in the database (or Redis cache). This means the user was deleted, never existed, or the username claim in the token is malformed.

Source

Thrown at jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroRealm.java:136

    /**
     * 校验token的有效性
     *
     * @param token
     */
    public LoginUser checkUserTokenIsEffect(String token) throws AuthenticationException {
        // 解密获得username,用于和数据库进行对比
        String username = JwtUtil.getUsername(token);
        if (username == null) {
            throw new AuthenticationException("Token非法无效!");
        }

        // 查询用户信息
        log.debug("———校验token是否有效————checkUserTokenIsEffect——————— "+ token);
        LoginUser loginUser = TokenUtils.getLoginUser(username, commonApi, redisUtil);
        //LoginUser loginUser = commonApi.getUserByName(username);
        if (loginUser == null) {
            throw new AuthenticationException("用户不存在!");
        }
        // 判断用户状态
        if (loginUser.getStatus() != 1) {
            throw new AuthenticationException("账号已被锁定,请联系管理员!");
        }
        // 校验token是否超时失效 & 或者账号密码是否错误
        if (!jwtTokenRefresh(token, username, loginUser.getPassword())) {
            // 用户登录Token过期提示信息
            String userLoginTokenErrorMsg = oConvertUtils.getString(redisUtil.get(CommonConstant.PREFIX_USER_TOKEN_ERROR_MSG + token));
            throw new AuthenticationException(oConvertUtils.isEmpty(userLoginTokenErrorMsg)? CommonConstant.TOKEN_IS_INVALID_MSG: userLoginTokenErrorMsg);
        }
        // 代码逻辑说明: 校验用户的tenant_id和前端传过来的是否一致
        String userTenantIds = loginUser.getRelTenantIds();
        if(MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL && oConvertUtils.isNotEmpty(userTenantIds)){
            String contextTenantId = TenantContext.getTenant();
            log.debug("登录租户:" + contextTenantId);
            log.debug("用户拥有那些租户:" + userTenantIds);
             //登录用户无租户,前端header中租户ID值为 0

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Have the user re-authenticate — if the account was deleted, they cannot log in and should contact the administrator.
  2. If the account was accidentally deleted, restore it from backup and have the user log in again.
  3. Verify the username claim in the JWT matches an existing user in sys_user table.
  4. Check for data migration issues that may have orphaned user records.

Example fix

// No code fix — the token references a non-existent user.
// Investigation:
//   SELECT * FROM sys_user WHERE username = '<username-from-jwt>'
// If deleted, restore the record. Then user logs in again for a fresh token.
Defensive patterns

Strategy: try-catch

Validate before calling

// Cannot validate client-side — user existence is server-authoritative.
// Front-end: just handle 401 by redirecting to login.

Try / catch

// Handled by JwtFilter / JeecgBootExceptionHandler — returns 401
// After admin deletes a user, proactively clear their Redis token cache:
// redis-cli DEL "PREFIX_USER_TOKEN:<deleted-user-token>"

Prevention

When it happens

Trigger: User account was deleted after the token was issued; username in the JWT refers to a user that exists in a different tenant or database; token was forged with a fabricated username; user table query returned null due to a data inconsistency.

Common situations: Admin deletes a user account while that user's session is still active; database migration or cleanup removed user records; multi-tenant isolation means the user exists in one tenant's database but not another; test/staging token used against a production database.

Related errors


AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14). Data as JSON: /api/errors/53c617a156244d87. Report an issue: GitHub.