{"record":{"id":"6fec0dfba299a0d2","repo":"elunez/eladmin","slug":"error-6fec0d","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":50,"sourceCode":" * @author Zheng Jie\n * @date 2018-11-22\n */\n@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":32,"sourceCodeEnd":66,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java#L32-L66","documentation":"Thrown by UserDetailsServiceImpl.loadUserByUsername (eladmin-system/.../security/service/UserDetailsServiceImpl.java:50) during Spring Security authentication when userService.getLoginData(username) returns null. This is eladmin's user-not-found signal: the username typed at login, or embedded in a JWT being re-resolved, has no matching row in sys_user. Spring's DaoAuthenticationProvider surfaces it as a BadCredentials-style 400 via the global exception handler.","triggerScenarios":"POST /auth/login with a misspelled or deleted username; a valid JWT for a user deleted after login (token verification re-invokes loadUserByUsername); logging in with the email field while getLoginData only matches username; test environment pointing at a database whose sys_user table is empty or not seeded by eladmin.sql.","commonSituations":"Fresh clone where sql/eladmin.sql was never imported so the default 'admin' account does not exist; user soft-deleted via DELETE /users but the browser still holds an old token; case-sensitive username mismatch (Admin vs admin); multiple datasource profiles so login hits the wrong schema.","solutions":["Verify the username exists: SELECT * FROM sys_user WHERE username = 'admin' against the datasource the running service actually uses.","If the table is empty, import sql/eladmin.sql (or at minimum the sys_user row) and re-login.","If the user was deleted while a session was open, clear the token/localStorage in the front end and log in again.","Confirm getLoginData's query (findByUsername) matches the identifier you are sending — eladmin authenticates on username, not email."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before login, confirm the account exists against the same backend\n// (or at minimum, treat any 400 from /auth/login as invalid credentials).\nawait axios.get('/api/users/' + encodeURIComponent(username) + '/exists') // if exposed\n// Practically: just handle the 400 gracefully in the login form.\ntry {\n  await store.dispatch('login', { username, password });\n} catch (e) {\n  this.$notify.error(e.response && e.response.data.message || '登录失败');\n}","typeGuard":null,"tryCatchPattern":"catch (BadRequestException e) when auth endpoints are involved: map to a friendly '用户名或密码错误' message; do NOT retry automatically — not-found is a permanent client condition.","preventionTips":["Seed sys_user from sql/eladmin.sql before first login.","After deleting a user, invalidate front-end tokens so stale JWTs do not keep re-triggering loadUserByUsername.","Log the attempted username (never the password) server-side to spot case or whitespace mismatches early."],"tags":["authentication","spring-security","eladmin","user-management","database"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}