{"record":{"id":"3a90522bcd13cec6","repo":"paascloud/paascloud-master","slug":"usernamenotfoundexception-userid","errorCode":null,"errorMessage":"UsernameNotFoundException(userId)","messagePattern":"UsernameNotFoundException\\(userId\\)","errorType":"http","errorClass":"UsernameNotFoundException","httpStatus":401,"severity":"error","filePath":"paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/authentication/DefaultSocialUserDetailsServiceImpl.java","lineNumber":29,"sourceCode":" *\n * @author paascloud.net @gmail.com\n */\n@Slf4j\npublic class DefaultSocialUserDetailsServiceImpl implements SocialUserDetailsService {\n\n\t/**\n\t * Load user by user id social user details.\n\t *\n\t * @param userId the user id\n\t *\n\t * @return the social user details\n\t *\n\t * @throws UsernameNotFoundException the username not found exception\n\t */\n\t@Override\n\tpublic SocialUserDetails loadUserByUserId(String userId) throws UsernameNotFoundException {\n\t\tlog.warn(\"请配置 SocialUserDetailsService 接口的实现.\");\n\t\tthrow new UsernameNotFoundException(userId);\n\t}\n\n}\n","sourceCodeStart":11,"sourceCodeEnd":33,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/authentication/DefaultSocialUserDetailsServiceImpl.java#L11-L33","documentation":"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.","triggerScenarios":"Any openid/social authentication that reaches userDetailsService.loadUserByUserId(userId) while the app relies on the default stub instead of registering a custom SocialUserDetailsService implementation.","commonSituations":"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.","solutions":["Implement SocialUserDetailsService with a loadUserByUserId that loads your user and returns a SocialUserDetails instance.","Register it as a Spring bean (@Service or @Bean) so it replaces DefaultSocialUserDetailsServiceImpl.","Verify component scanning includes the package of your implementation.","Ensure it delegates to a loaded UserRepository/Feign client rather than returning null or throwing unconditionally."],"exampleFix":"// before\n// no implementation -> DefaultSocialUserDetailsServiceImpl used\n// after\n@Service\npublic class MySocialUserDetailsService implements SocialUserDetailsService {\n    @Override\n    public SocialUserDetails loadUserByUserId(String userId) {\n        return Optional.ofNullable(userRepository.findById(userId))\n            .map(MySocialUserDetails::new)\n            .orElseThrow(() -> new UsernameNotFoundException(userId));\n    }\n}","handlingStrategy":"try-catch","validationCode":"if (userDetailsService instanceof DefaultSocialUserDetailsServiceImpl) {\n    throw new IllegalStateException(\"Configure a real SocialUserDetailsService before enabling social login\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    SocialUserDetails u = socialUserDetailsService.loadUserByUserId(userId);\n} catch (UsernameNotFoundException e) {\n    log.error(\"SocialUserDetailsService not implemented or user missing: {}\", e.getMessage());\n    throw new AuthenticationServiceException(\"User store not configured\");\n}","preventionTips":["Implement and register SocialUserDetailsService as a bean during security setup.","Add a startup assertion that the bean is not the default stub.","Cover user loading with an integration test before enabling social login."],"tags":["java","spring-security","stub-implementation","social-login"],"backgroundTag":"abstract-method-not-implemented","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"}