{"record":{"id":"2013554fa8453288","repo":"macrozheng/mall-learning","slug":"error-201355","errorCode":null,"errorMessage":"用户名或密码错误","messagePattern":"用户名或密码错误","errorType":"exception","errorClass":"UsernameNotFoundException","httpStatus":null,"severity":"error","filePath":"mall-tiny-06/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-06/src/main/java/com/macro/mall/tiny/config/MallSecurityConfig.java#L13-L35","documentation":"Same family as errors 0-1, in mall-tiny-06: the UserDetailsService lambda throws UsernameNotFoundException because adminService.getAdminByUsername found no matching admin row. This exception is translated by Spring Security's authentication provider into a failed login, surfaced with the generic 'username or password wrong' message.","triggerScenarios":"Login/authentication call with a username that has no row in ums_admin; the null check in the lambda fails and the exception is thrown.","commonSituations":"Missing seed data after recreating the database, wrong active Spring profile/database, username case mismatch (MySQL collation differences), client sending email instead of username.","solutions":["Query ums_admin for the username to confirm it exists","Re-import the module's SQL seed script into the configured database","Check application.yml datasource and profile configuration","Normalize/trim usernames before lookup"],"exampleFix":"// before\nif (admin != null) { return admin; }\nthrow new UsernameNotFoundException(\"用户名或密码错误\");\n// after\nif (admin != null) { return admin; }\nlog.warn(\"No admin found for username: {}\", username);\nthrow new UsernameNotFoundException(\"用户名或密码错误\");","handlingStrategy":"try-catch","validationCode":"if (username == null || username.isBlank()) throw new IllegalArgumentException(\"用户名不能为空\");","typeGuard":null,"tryCatchPattern":"try {\n    authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));\n} catch (AuthenticationException e) {\n    return CommonResult.failed(\"用户名或密码错误\");\n}","preventionTips":["Verify seed data exists in the target schema","Watch for MySQL collation/case-sensitivity in username lookups","Send username, not email, to the login endpoint","Log unknown-username attempts server-side for diagnosis"],"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"}