{"record":{"id":"4c7fed514e032ca3","repo":"wuyouzhuguli/SpringAll","slug":"error-4c7fed","errorCode":null,"errorMessage":"未找到与该手机号对应的用户","messagePattern":"未找到与该手机号对应的用户","errorType":"validation","errorClass":"InternalAuthenticationServiceException","httpStatus":null,"severity":"error","filePath":"64.Spring-Security-OAuth2-Customize/src/main/java/cc/mrbird/security/validate/smscode/SmsAuthenticationProvider.java","lineNumber":20,"sourceCode":"\nimport cc.mrbird.security.service.UserDetailService;\nimport org.springframework.security.authentication.AuthenticationProvider;\nimport org.springframework.security.authentication.InternalAuthenticationServiceException;\nimport org.springframework.security.core.Authentication;\nimport org.springframework.security.core.AuthenticationException;\nimport org.springframework.security.core.userdetails.UserDetails;\n\npublic class SmsAuthenticationProvider implements AuthenticationProvider {\n\n    private UserDetailService userDetailService;\n\n    @Override\n    public Authentication authenticate(Authentication authentication) throws AuthenticationException {\n        SmsAuthenticationToken authenticationToken = (SmsAuthenticationToken) authentication;\n        UserDetails userDetails = userDetailService.loadUserByUsername((String) authenticationToken.getPrincipal());\n\n        if (userDetails == null)\n            throw new InternalAuthenticationServiceException(\"未找到与该手机号对应的用户\");\n\n        SmsAuthenticationToken authenticationResult = new SmsAuthenticationToken(userDetails, userDetails.getAuthorities());\n\n        authenticationResult.setDetails(authenticationToken.getDetails());\n\n        return authenticationResult;\n    }\n\n    @Override\n    public boolean supports(Class<?> aClass) {\n        return SmsAuthenticationToken.class.isAssignableFrom(aClass);\n    }\n\n    public UserDetailService getUserDetailService() {\n        return userDetailService;\n    }\n\n    public void setUserDetailService(UserDetailService userDetailService) {","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/wuyouzhuguli/SpringAll/blob/614d2578d9495acf53cc02f2dee9c6131cc5e51a/64.Spring-Security-OAuth2-Customize/src/main/java/cc/mrbird/security/validate/smscode/SmsAuthenticationProvider.java#L2-L38","documentation":"InternalAuthenticationServiceException thrown by SmsAuthenticationProvider.authenticate (project 64) when userDetailService.loadUserByUsername(mobile) returns null. Identical semantics to error 65 (project 61); the principal is the mobile number and the UserDetailService must resolve it. Same caveat: standard UserDetailsService implementations throw UsernameNotFoundException rather than returning null.","triggerScenarios":"Mobile number not registered with the user store; UserDetailService queries by username, not phone; principal mismatch.","commonSituations":"No user row for the phone; schema phone column not queried; test fixtures missing.","solutions":["Register the mobile in the user store so loadUserByUsername(mobile) resolves.","Ensure UserDetailService filters by the phone/mobile column.","Confirm SmsAuthenticationToken carries the mobile as principal.","Throw UsernameNotFoundException from UserDetailService for unknown users (Spring convention)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the mobile is registered before offering SMS login (if an endpoint exists).\nconst ok = await fetch(`/users/exists?mobile=${encodeURIComponent(mobile)}`).then(r=>r.json());\nif (!ok.exists) { promptRegister(mobile); return; }","typeGuard":null,"tryCatchPattern":"try { await smsLogin(mobile, code); }\ncatch (e) {\n  if (/未找到与该手机号对应的用户/.test(e.message)) promptRegister(mobile);\n  else handleError(e);\n}","preventionTips":["Make UserDetailService load by mobile.","Throw UsernameNotFoundException for unknown users (Spring convention).","Seed users for QA mobiles."],"tags":["spring-security","sms","user-management","authentication"],"backgroundTag":null,"analyzedSha":"614d2578d9495acf53cc02f2dee9c6131cc5e51a","analyzedAt":"2026-08-14T04:40:03.488Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}