{"record":{"id":"2924d418bbafddd2","repo":"paascloud/paascloud-master","slug":"error-2924d4","errorCode":null,"errorMessage":"无法获取用户信息","messagePattern":"无法获取用户信息","errorType":"http","errorClass":"InternalAuthenticationServiceException","httpStatus":401,"severity":"error","filePath":"paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/authentication/mobile/SmsCodeAuthenticationProvider.java","lineNumber":38,"sourceCode":"\n\t/**\n\t * Authenticate authentication.\n\t *\n\t * @param authentication the authentication\n\t *\n\t * @return the authentication\n\t *\n\t * @throws AuthenticationException the authentication exception\n\t */\n\t@Override\n\tpublic Authentication authenticate(Authentication authentication) throws AuthenticationException {\n\n\t\tSmsCodeAuthenticationToken authenticationToken = (SmsCodeAuthenticationToken) authentication;\n\n\t\tUserDetails user = userDetailsService.loadUserByUsername((String) authenticationToken.getPrincipal());\n\n\t\tif (user == null) {\n\t\t\tthrow new InternalAuthenticationServiceException(\"无法获取用户信息\");\n\t\t}\n\n\t\tSmsCodeAuthenticationToken authenticationResult = new SmsCodeAuthenticationToken(user, user.getAuthorities());\n\n\t\tauthenticationResult.setDetails(authenticationToken.getDetails());\n\n\t\treturn authenticationResult;\n\t}\n\n\t/**\n\t * Supports boolean.\n\t *\n\t * @param authentication the authentication\n\t *\n\t * @return the boolean\n\t */\n\t@Override\n\tpublic boolean supports(Class<?> authentication) {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/authentication/mobile/SmsCodeAuthenticationProvider.java#L20-L56","documentation":"SmsCodeAuthenticationProvider.authenticate throws InternalAuthenticationServiceException('无法获取用户信息') when userDetailsService.loadUserByUsername(mobile) returns null for the mobile number used as principal. The provider requires a real UserDetails to build the authenticated SmsCodeAuthenticationToken.","triggerScenarios":"Submitting an SmsCodeAuthenticationToken whose principal (mobile) has no matching user record, or a custom UserDetailsService that returns null instead of throwing for unknown mobiles.","commonSituations":"User attempts SMS login with a phone number never registered; user record deleted between code validation and authentication; custom UserDetailsService with a bug returning null on lookup failures; test/dev data absent in the connected database.","solutions":["Register/verify the user exists for the given mobile number before SMS login.","Make your UserDetailsService throw UsernameNotFoundException rather than returning null so failures are reported consistently.","Check the UserDetailsService queries the correct table/datasource where the user exists.","Confirm the mobile string passed as principal matches the stored format (e.g. no country code vs with country code).","Ensure SMS code validation happens before authentication so only verified mobiles reach the provider."],"exampleFix":"// before\nUserDetails user = repo.findByMobile(mobile);\nreturn user; // null when missing\n// after\nUserDetails user = repo.findByMobile(mobile)\n    .map(SecurityUser::new)\n    .orElseThrow(() -> new UsernameNotFoundException(mobile));","handlingStrategy":"try-catch","validationCode":"// verify user exists before SMS auth\nboolean exists = userRepository.existsByMobile(mobile);\nif (!exists) { throw new UsernameNotFoundException(mobile); }","typeGuard":null,"tryCatchPattern":"try {\n    authenticationManager.authenticate(new SmsCodeAuthenticationToken(mobile));\n} catch (InternalAuthenticationServiceException e) {\n    log.warn(\"no user for mobile\");\n    return redirectToRegister();\n}","preventionTips":["Make UserDetailsService throw, never return null.","Normalize mobile format (country code) before lookup.","Register users before permitting SMS login.","Validate SMS code before provider authentication."],"tags":["java","spring-security","sms","user-not-found"],"backgroundTag":"user-not-found","analyzedSha":"781281a9503332ed3cef44ea618349d14230a127","analyzedAt":"2026-09-10T10:59:02.070Z","contentChangedAt":"2026-09-10T10:59:02.070Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}