{"record":{"id":"c09db1fff89cee72","repo":"apolloconfig/apollo","slug":"current-user-not-found-c09db1","errorCode":null,"errorMessage":"Current user not found","messagePattern":"Current user not found","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/OpenApiOperatorResolver.java","lineNumber":48,"sourceCode":" */\n@Component\npublic class OpenApiOperatorResolver {\n\n  private final UserInfoHolder userInfoHolder;\n  private final UserService userService;\n\n  public OpenApiOperatorResolver(UserInfoHolder userInfoHolder, UserService userService) {\n    this.userInfoHolder = userInfoHolder;\n    this.userService = userService;\n  }\n\n  public String resolve(String operator) {\n    String authType = UserIdentityContextHolder.getAuthType();\n    if (UserIdentityConstants.USER.equals(authType)\n        || UserIdentityConstants.USER_TOKEN.equals(authType)) {\n      UserInfo loginUser = userInfoHolder.getUser();\n      if (loginUser == null || !StringUtils.hasText(loginUser.getUserId())) {\n        throw new BadRequestException(\"Current user not found\");\n      }\n      return loginUser.getUserId();\n    }\n\n    if (UserIdentityConstants.CONSUMER.equals(authType)) {\n      if (!StringUtils.hasText(operator)) {\n        throw new BadRequestException(\"operator should not be null or empty\");\n      }\n      if (userService.findByUserId(operator) == null) {\n        throw BadRequestException.userNotExists(operator);\n      }\n      return operator;\n    }\n\n    throw new BadRequestException(\"Unsupported auth type: %s\", authType);\n  }\n}\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/OpenApiOperatorResolver.java#L30-L66","documentation":"HTTP 400 (BadRequestException). Thrown by OpenApiOperatorResolver.resolve: auth type USER or USER_TOKEN but UserInfoHolder.getUser() is null or its userId has no text. This is the shared operator-resolution helper used across multiple OpenAPI controllers; it centralizes the same principal-missing failure seen in errors 84/92.","triggerScenarios":"Any OpenAPI write endpoint that delegates to OpenApiOperatorResolver.resolve() under USER/USER_TOKEN auth when the Spring Security principal is absent or has a blank userId.","commonSituations":"Expired portal session; user-token authenticated without resolving to a UserInfo; custom auth filter sets authType but not UserInfoHolder; gateway/proxy stripped auth context.","solutions":["Re-authenticate (fresh portal session or user-token) and retry.","Ensure the auth filter populates UserInfoHolder with a non-blank userId for USER/USER_TOKEN requests.","Use CONSUMER auth and pass an explicit operator if calling via OpenAPI token.","Add a pre-controller guard that rejects requests with a missing principal."],"exampleFix":"// before: USER_TOKEN principal missing -> 400\nString op = resolver.resolve(null);\n\n// after: ensure principal populated, or use CONSUMER\nclient.withConsumerToken(token).someWrite(op=\"svcacct\");","handlingStrategy":"try-catch","validationCode":"// For USER/USER_TOKEN: confirm principal present before resolving operator.\nUserInfo u = userInfoHolder.getUser();\nif (u == null || !StringUtils.hasText(u.getUserId())) { /* re-authenticate */ }","typeGuard":"null","tryCatchPattern":"try {\n  client.someWrite(appId, payload);\n} catch (HttpClientErrorException.BadRequest e) {\n  if (e.getResponseBodyAsString().contains(\"Current user not found\")) {\n    refreshToken(); client.someWrite(appId, payload);\n  }\n}","preventionTips":["Refresh user-tokens before they expire.","Ensure UserInfoHolder is populated by the auth filter.","Prefer CONSUMER + explicit operator for automation."],"tags":["apollo-portal","openapi","auth","bad-request","operator","user","resolver"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}