{"record":{"id":"c58d3fd68530bcbf","repo":"elunez/eladmin","slug":"error-c58d3f","errorCode":null,"errorMessage":"账号未激活！","messagePattern":"账号未激活！","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java","lineNumber":53,"sourceCode":"@Slf4j\n@RequiredArgsConstructor\n@Service(\"userDetailsService\")\npublic class UserDetailsServiceImpl implements UserDetailsService {\n    private final UserService userService;\n    private final RoleService roleService;\n    private final DataService dataService;\n    private final UserCacheManager userCacheManager;\n\n    @Override\n    public JwtUserDto loadUserByUsername(String username) {\n        JwtUserDto jwtUserDto = userCacheManager.getUserCache(username);\n        if(jwtUserDto == null){\n            UserDto user = userService.getLoginData(username);\n            if (user == null) {\n                throw new BadRequestException(\"用户不存在\");\n            } else {\n                if (!user.getEnabled()) {\n                    throw new BadRequestException(\"账号未激活！\");\n                }\n                // 获取用户的权限\n                List<AuthorityDto> authorities = roleService.buildPermissions(user);\n                // 初始化JwtUserDto\n                jwtUserDto = new JwtUserDto(user, dataService.getDeptIds(user), authorities);\n                // 添加缓存数据\n                userCacheManager.addUserCache(username, jwtUserDto);\n            }\n        }\n        return jwtUserDto;\n    }\n}\n","sourceCodeStart":35,"sourceCodeEnd":66,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java#L35-L66","documentation":"Thrown by UserDetailsServiceImpl.loadUserByUsername (line 53) when the user row exists but user.getEnabled() is false. eladmin treats the enabled flag as the account-activation switch; a disabled account passes the existence check but is rejected before authorities are built. Note the check only runs on a cache miss — an already-cached JwtUserDto bypasses it until UserCacheManager evicts the entry.","triggerScenarios":"Logging in with an account whose sys_user.is_enabled = 0 (e.g. deactivated by an admin in the user management screen); a freshly seeded user inserted with enabled missing (defaults off); admin disables a user mid-session and the user re-authenticates after cache eviction (default 1 hour via UserCacheManager).","commonSituations":"New rows inserted by hand into sys_user without setting is_enabled = 1; admin deactivates a leaver's account and the leaver's next login fails; stale Redis/user cache still authenticating a disabled user until eviction, creating confusion about whether the disable worked.","solutions":["UPDATE sys_user SET is_enabled = 1 WHERE username = '<user>' then retry login.","If the account should stay disabled, inform the user — no code fix is needed; this is intended behavior.","If disabling must take effect immediately, also clear the user cache (UserCacheManager.cleanCache / eviction) after toggling enabled, not just on next miss.","Check the admin UI user list: the status toggle writes the enabled field; verify it persisted."],"exampleFix":"// after an admin disables a user, keep auth consistent:\n// before\nuser.setEnabled(false);\nuserRepository.save(user);\n// after\nuser.setEnabled(false);\nuserRepository.save(user);\nuserCacheManager.cleanCache(user.getUsername()); // drop cached JwtUserDto immediately","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"Catch BadRequestException on the auth call and branch on the message ('账号未激活' vs '用户不存在') to show account-activation guidance instead of a generic failure.","preventionTips":["Always set is_enabled = 1 when inserting users by SQL.","When an admin toggles enabled, also evict the UserCacheManager entry so disable takes effect immediately.","Surface account status in the admin user list so operators see which accounts are disabled."],"tags":["authentication","account-state","eladmin","cache-invalidation"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}