{"record":{"id":"53c617a156244d87","repo":"jeecgboot/JeecgBoot","slug":"error-53c617","errorCode":null,"errorMessage":"用户不存在!","messagePattern":"用户不存在!","errorType":"exception","errorClass":"AuthenticationException","httpStatus":401,"severity":"error","filePath":"jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroRealm.java","lineNumber":136,"sourceCode":"\n    /**\n     * 校验token的有效性\n     *\n     * @param token\n     */\n    public LoginUser checkUserTokenIsEffect(String token) throws AuthenticationException {\n        // 解密获得username，用于和数据库进行对比\n        String username = JwtUtil.getUsername(token);\n        if (username == null) {\n            throw new AuthenticationException(\"Token非法无效!\");\n        }\n\n        // 查询用户信息\n        log.debug(\"———校验token是否有效————checkUserTokenIsEffect——————— \"+ token);\n        LoginUser loginUser = TokenUtils.getLoginUser(username, commonApi, redisUtil);\n        //LoginUser loginUser = commonApi.getUserByName(username);\n        if (loginUser == null) {\n            throw new AuthenticationException(\"用户不存在!\");\n        }\n        // 判断用户状态\n        if (loginUser.getStatus() != 1) {\n            throw new AuthenticationException(\"账号已被锁定,请联系管理员!\");\n        }\n        // 校验token是否超时失效 & 或者账号密码是否错误\n        if (!jwtTokenRefresh(token, username, loginUser.getPassword())) {\n            // 用户登录Token过期提示信息\n            String userLoginTokenErrorMsg = oConvertUtils.getString(redisUtil.get(CommonConstant.PREFIX_USER_TOKEN_ERROR_MSG + token));\n            throw new AuthenticationException(oConvertUtils.isEmpty(userLoginTokenErrorMsg)? CommonConstant.TOKEN_IS_INVALID_MSG: userLoginTokenErrorMsg);\n        }\n        // 代码逻辑说明: 校验用户的tenant_id和前端传过来的是否一致\n        String userTenantIds = loginUser.getRelTenantIds();\n        if(MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL && oConvertUtils.isNotEmpty(userTenantIds)){\n            String contextTenantId = TenantContext.getTenant();\n            log.debug(\"登录租户：\" + contextTenantId);\n            log.debug(\"用户拥有那些租户：\" + userTenantIds);\n             //登录用户无租户，前端header中租户ID值为 0","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroRealm.java#L118-L154","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Have the user re-authenticate — if the account was deleted, they cannot log in and should contact the administrator.","If the account was accidentally deleted, restore it from backup and have the user log in again.","Verify the username claim in the JWT matches an existing user in sys_user table.","Check for data migration issues that may have orphaned user records."],"exampleFix":"// No code fix — the token references a non-existent user.\n// Investigation:\n//   SELECT * FROM sys_user WHERE username = '<username-from-jwt>'\n// If deleted, restore the record. Then user logs in again for a fresh token.","handlingStrategy":"try-catch","validationCode":"// Cannot validate client-side — user existence is server-authoritative.\n// Front-end: just handle 401 by redirecting to login.","typeGuard":null,"tryCatchPattern":"// Handled by JwtFilter / JeecgBootExceptionHandler — returns 401\n// After admin deletes a user, proactively clear their Redis token cache:\n// redis-cli DEL \"PREFIX_USER_TOKEN:<deleted-user-token>\"","preventionTips":["When deleting a user account, also invalidate their JWT token from Redis.","Regularly audit for orphaned tokens pointing to deleted users.","Handle 401 responses gracefully in the front-end."],"tags":["shiro","jwt","authentication","user","data-integrity"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}