{"record":{"id":"2f3781efeb301d81","repo":"paascloud/paascloud-master","slug":"error-2f3781","errorCode":null,"errorMessage":"无法获取用户信息","messagePattern":"无法获取用户信息","errorType":"http","errorClass":"InternalAuthenticationServiceException","httpStatus":401,"severity":"error","filePath":"paascloud-common/paascloud-security-app/src/main/java/com/paascloud/security/app/authentication/openid/OpenIdAuthenticationProvider.java","lineNumber":56,"sourceCode":"\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\tOpenIdAuthenticationToken authenticationToken = (OpenIdAuthenticationToken) authentication;\n\n\t\tSet<String> providerUserIds = new HashSet<>();\n\t\tproviderUserIds.add((String) authenticationToken.getPrincipal());\n\t\tSet<String> userIds = usersConnectionRepository.findUserIdsConnectedTo(authenticationToken.getProviderId(), providerUserIds);\n\n\t\tif (CollectionUtils.isEmpty(userIds) || userIds.size() != 1) {\n\t\t\tthrow new InternalAuthenticationServiceException(\"无法获取用户信息\");\n\t\t}\n\n\t\tString userId = userIds.iterator().next();\n\n\t\tUserDetails user = userDetailsService.loadUserByUserId(userId);\n\n\t\tif (user == null) {\n\t\t\tthrow new InternalAuthenticationServiceException(\"无法获取用户信息\");\n\t\t}\n\n\t\tOpenIdAuthenticationToken authenticationResult = new OpenIdAuthenticationToken(user, user.getAuthorities());\n\n\t\tauthenticationResult.setDetails(authenticationToken.getDetails());\n\n\t\treturn authenticationResult;\n\t}\n\n\t/**","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-common/paascloud-security-app/src/main/java/com/paascloud/security/app/authentication/openid/OpenIdAuthenticationProvider.java#L38-L74","documentation":"OpenIdAuthenticationProvider.authenticate throws InternalAuthenticationServiceException('无法获取用户信息') when usersConnectionRepository.findUserIdsConnectedTo returns no userId (or more than one) for the given providerId + openId pair. It means no (or ambiguous) local user is bound to that social account, so authentication cannot proceed.","triggerScenarios":"Submitting an OpenIdAuthenticationToken whose providerId/openid combination has no row in the social user-connection table (e.g. UaaConnectionRepository / social_connection), or a data anomaly producing multiple connected userIds for the same providerUserId.","commonSituations":"User tries openid login before completing signup/binding; the social connection record was deleted or the appSecret/providerId changed; database rows duplicated by repeated connection inserts; deviceId-based caching of the connection was lost before doPostSignUp ran.","solutions":["Ensure the social connection exists: complete the signup/binding flow (AppSingUpUtils.doPostSignUp) so the connection is persisted for this providerId+openid.","Check the user connection table for rows matching providerId and providerUserId; remove duplicates if userIds.size() != 1.","Verify the providerId sent by the client matches the one stored when the connection was created.","Confirm usersConnectionRepository is wired to the correct datasource/table.","Log authenticationToken.getProviderId() and principal to debug which pair is missing."],"exampleFix":"// before\n// client logs in with openid directly without binding\n// after\n// first bind: POST social signup with deviceId header so AppSingUpUtils persists the Connection,\n// then retry the openid login with the same providerId/openid","handlingStrategy":"try-catch","validationCode":"// pre-check binding before login\nSet<String> ids = usersConnectionRepository.findUserIdsConnectedTo(providerId, Set.of(openId));\nboolean bound = ids != null && ids.size() == 1;","typeGuard":null,"tryCatchPattern":"try {\n    authenticationManager.authenticate(openIdToken);\n} catch (InternalAuthenticationServiceException e) {\n    // guide user to signup/binding flow\n    return redirectToSocialSignUp();\n}","preventionTips":["Complete the bind/signup flow before allowing openid login.","Enforce unique constraint on (provider_id, provider_user_id).","Keep deviceId-based cache and DB binding consistent."],"tags":["java","spring-security","social-login","openid","user-not-found"],"backgroundTag":"social-account-not-bound","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"}