paascloud/paascloud-master · error · UsernameNotFoundException

UsernameNotFoundException(userId)

Error message

UsernameNotFoundException(userId)

What it means

DefaultSocialUserDetailsServiceImpl is a placeholder implementation of SocialUserDetailsService that always throws UsernameNotFoundException(userId). It exists so the security module compiles without a real implementation; hitting it means the application has not supplied its own SocialUserDetailsService bean to load users by social user id.

Solutions

  1. Implement SocialUserDetailsService with a loadUserByUserId that loads your user and returns a SocialUserDetails instance.
  2. Register it as a Spring bean (@Service or @Bean) so it replaces DefaultSocialUserDetailsServiceImpl.
  3. Verify component scanning includes the package of your implementation.
  4. Ensure it delegates to a loaded UserRepository/Feign client rather than returning null or throwing unconditionally.

Example fix

// before
// no implementation -> DefaultSocialUserDetailsServiceImpl used
// after
@Service
public class MySocialUserDetailsService implements SocialUserDetailsService {
    @Override
    public SocialUserDetails loadUserByUserId(String userId) {
        return Optional.ofNullable(userRepository.findById(userId))
            .map(MySocialUserDetails::new)
            .orElseThrow(() -> new UsernameNotFoundException(userId));
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (userDetailsService instanceof DefaultSocialUserDetailsServiceImpl) {
    throw new IllegalStateException("Configure a real SocialUserDetailsService before enabling social login");
}

Try / catch

try {
    SocialUserDetails u = socialUserDetailsService.loadUserByUserId(userId);
} catch (UsernameNotFoundException e) {
    log.error("SocialUserDetailsService not implemented or user missing: {}", e.getMessage());
    throw new AuthenticationServiceException("User store not configured");
}

Prevention

When it happens

Trigger: Any openid/social authentication that reaches userDetailsService.loadUserByUserId(userId) while the app relies on the default stub instead of registering a custom SocialUserDetailsService implementation.

Common situations: New project integrating paascloud security modules before implementing user loading; missing @Service/@Bean annotation on the real implementation so Spring falls back to the default; component scan not covering the package containing the implementation.

Understand the failure class

Background: "NotImplementedError: Subclasses should override this method" / "must be implemented" — abstract method errors explained — this error's family across 40 libraries.

Related errors


AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10). Data as JSON: /api/errors/3a90522bcd13cec6. Report an issue: GitHub.

Appendix: source

Thrown at paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/authentication/DefaultSocialUserDetailsServiceImpl.java:29

 *
 * @author paascloud.net @gmail.com
 */
@Slf4j
public class DefaultSocialUserDetailsServiceImpl implements SocialUserDetailsService {

	/**
	 * Load user by user id social user details.
	 *
	 * @param userId the user id
	 *
	 * @return the social user details
	 *
	 * @throws UsernameNotFoundException the username not found exception
	 */
	@Override
	public SocialUserDetails loadUserByUserId(String userId) throws UsernameNotFoundException {
		log.warn("请配置 SocialUserDetailsService 接口的实现.");
		throw new UsernameNotFoundException(userId);
	}

}

View on GitHub (pinned to 781281a950)