{"record":{"id":"e33f6fbebeaa1950","repo":"macrozheng/mall-learning","slug":"error-e33f6f","errorCode":null,"errorMessage":"用户名或密码错误","messagePattern":"用户名或密码错误","errorType":"exception","errorClass":"UsernameNotFoundException","httpStatus":null,"severity":"error","filePath":"mall-tiny-08/src/main/java/com/macro/mall/tiny/config/MallSecurityConfig.java","lineNumber":31,"sourceCode":" * @description 自定义配置，用于配置如何获取用户信息\n * @date 2022/5/20\n * @github https://github.com/macrozheng\n */\n@Configuration\npublic class MallSecurityConfig {\n\n    @Autowired\n    private UmsAdminService adminService;\n\n    @Bean\n    public UserDetailsService userDetailsService() {\n        //获取登录用户信息\n        return username -> {\n            AdminUserDetails admin = adminService.getAdminByUsername(username);\n            if (admin != null) {\n                return admin;\n            }\n            throw new UsernameNotFoundException(\"用户名或密码错误\");\n        };\n    }\n}\n","sourceCodeStart":13,"sourceCodeEnd":35,"githubUrl":"https://github.com/macrozheng/mall-learning/blob/cd02c000e57c693e49f1f72986dbfa6e4c952e09/mall-tiny-08/src/main/java/com/macro/mall/tiny/config/MallSecurityConfig.java#L13-L35","documentation":"mall-tiny-08's UserDetailsService throws UsernameNotFoundException when the submitted username has no matching admin in the database. Spring Security's DaoAuthenticationProvider catches this internally and reports authentication failure, so the client sees a generic bad-credentials response with this message.","triggerScenarios":"Login with a username absent from ums_admin; adminService.getAdminByUsername returns null and the lambda throws.","commonSituations":"Fresh environment without imported seed SQL, wrong database/profile, deleted or renamed account, username typo or whitespace from client input.","solutions":["SELECT the username from ums_admin to confirm existence","Import the project's schema/seed data into the configured database","Check datasource config and Spring profile","Register the user or insert the default admin row"],"exampleFix":"// before\nif (admin != null) { return admin; }\nthrow new UsernameNotFoundException(\"用户名或密码错误\");\n// after\nif (admin != null) { return admin; }\nlog.warn(\"Login for unknown user: {}\", username);\nthrow new UsernameNotFoundException(\"用户名或密码错误\");","handlingStrategy":"try-catch","validationCode":"if (!username?.trim()) return reject('用户名不能为空');\n// pre-check (optional): userExists = adminService.getAdminByUsername(username) != null","typeGuard":null,"tryCatchPattern":"try {\n    authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));\n} catch (AuthenticationException e) {\n    log.warn(\"Login failed: {}\", e.getMessage());\n    return CommonResult.validateFailed(\"用户名或密码错误\");\n}","preventionTips":["Load seed SQL into every new environment","Validate that registration completed before attempting login","Keep usernames consistent case-wise end to end","Monitor logs for repeated unknown-username attempts"],"tags":["spring-security","authentication","login","jdbc"],"backgroundTag":"user-not-found","analyzedSha":"cd02c000e57c693e49f1f72986dbfa6e4c952e09","analyzedAt":"2026-09-07T23:16:08.059Z","contentChangedAt":"2026-09-07T23:16:08.059Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}