paascloud/paascloud-master · error · InternalAuthenticationServiceException
无法获取用户信息
Error message
无法获取用户信息
What it means
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.
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.
Example fix
// before
UserDetails user = repo.findByMobile(mobile);
return user; // null when missing
// after
UserDetails user = repo.findByMobile(mobile)
.map(SecurityUser::new)
.orElseThrow(() -> new UsernameNotFoundException(mobile)); Defensive patterns
Strategy: try-catch
Validate before calling
// verify user exists before SMS auth
boolean exists = userRepository.existsByMobile(mobile);
if (!exists) { throw new UsernameNotFoundException(mobile); } Try / catch
try {
authenticationManager.authenticate(new SmsCodeAuthenticationToken(mobile));
} catch (InternalAuthenticationServiceException e) {
log.warn("no user for mobile");
return redirectToRegister();
} Prevention
- 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.
When it happens
Trigger: Submitting an SmsCodeAuthenticationToken whose principal (mobile) has no matching user record, or a custom UserDetailsService that returns null instead of throwing for unknown mobiles.
Common situations: 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.
Understand the failure class
Background: "User not found", "Invalid user", and "does not exist": what missing-user lookup errors mean across Rocket.Chat, LiteLLM, Phabricator, rustfs, and pnpm — this error's family across 10 libraries.
Related errors
- 无法获取用户信息
- Authentication method not supported:
- Authentication method not supported:
- UsernameNotFoundException(userId)
- UsernameNotFoundException(username)
AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10).
Data as JSON: /api/errors/2924d418bbafddd2.
Report an issue: GitHub.
Appendix: source
Thrown at paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/authentication/mobile/SmsCodeAuthenticationProvider.java:38
/**
* Authenticate authentication.
*
* @param authentication the authentication
*
* @return the authentication
*
* @throws AuthenticationException the authentication exception
*/
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
SmsCodeAuthenticationToken authenticationToken = (SmsCodeAuthenticationToken) authentication;
UserDetails user = userDetailsService.loadUserByUsername((String) authenticationToken.getPrincipal());
if (user == null) {
throw new InternalAuthenticationServiceException("无法获取用户信息");
}
SmsCodeAuthenticationToken authenticationResult = new SmsCodeAuthenticationToken(user, user.getAuthorities());
authenticationResult.setDetails(authenticationToken.getDetails());
return authenticationResult;
}
/**
* Supports boolean.
*
* @param authentication the authentication
*
* @return the boolean
*/
@Override
public boolean supports(Class<?> authentication) {View on GitHub (pinned to 781281a950)