{"record":{"id":"cc0e4d4b8c11d531","repo":"apolloconfig/apollo","slug":"current-user-not-found-cc0e4d","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/ItemController.java","lineNumber":282,"sourceCode":"      this.itemOpenApiService.updateItem(appId, env, clusterName, namespaceName, item,\n          resolvedOperator);\n    }\n  }\n\n  private void checkCommentLength(String comment) {\n    if (!StringUtils.isEmpty(comment) && comment.length() > ITEM_COMMENT_MAX_LENGTH) {\n      throw new BadRequestException(\"Comment length should not exceed %s characters\",\n          ITEM_COMMENT_MAX_LENGTH);\n    }\n  }\n\n  private String resolveOperator(String queryOperator, String payloadOperator) {\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.isBlank(loginUser.getUserId())) {\n        throw new BadRequestException(\"Current user not found\");\n      }\n      return loginUser.getUserId();\n    }\n\n    if (UserIdentityConstants.CONSUMER.equals(authType)) {\n      String operator = StringUtils.isBlank(queryOperator) ? payloadOperator : queryOperator;\n      RequestPrecondition.checkArguments(!StringUtils.isContainEmpty(operator),\n          \"operator should not be null or empty\");\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  private boolean shouldHideConfigToPortalUser(String appId, String env, String clusterName,","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java#L264-L300","documentation":"Thrown by ItemController.resolveOperator when authType is USER or USER_TOKEN but userInfoHolder.getUser() returns null or a UserInfo with a blank userId. The resolveOperator method (two-arg variant for ItemController) determines the acting user for item write operations; for interactive and user-token identities it expects a valid session user. Maps to HTTP 400 BadRequestException.","triggerScenarios":"Any item write endpoint (createItem, updateItem, createOrUpdateItem) called with USER or USER_TOKEN auth where the user session is absent, expired, or the UserInfo object has a null/blank userId.","commonSituations":"A Portal browser session expired before the item save completed (USER path). A USER_TOKEN references a deactivated user account. Integration tests with an improperly mocked UserInfoHolder. Thread-local context pollution in async request handling where the security context is cleared before the controller runs.","solutions":["For USER auth: re-authenticate through the Portal to establish a fresh session.","For USER_TOKEN: verify the token's associated user account is active and not deleted in the Portal user management page.","In tests: configure userInfoHolder.getUser() to return a valid UserInfo with a non-blank userId before invoking the controller."],"exampleFix":"// before — test mock returns null user\nwhen(userInfoHolder.getUser()).thenReturn(null);\ncontroller.updateItem(\"appA\", \"DEV\", \"default\", \"application\", item, false); // throws\n\n// after — provide valid UserInfo\nUserInfo user = new UserInfo();\nuser.setUserId(\"testUser\");\nwhen(userInfoHolder.getUser()).thenReturn(user);","handlingStrategy":"try-catch","validationCode":"// Before calling item write, verify the user session is valid\nUserInfo user = userInfoHolder.getUser();\nif (user == null || StringUtils.isBlank(user.getUserId())) {\n    throw new IllegalStateException(\"No active user session. Please re-authenticate.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    controller.updateItem(appId, env, clusterName, namespaceName, item, createIfNotExists);\n} catch (BadRequestException e) {\n    if (\"Current user not found\".equals(e.getMessage())) {\n        redirectToLogin(); // or refresh the token\n    } else {\n        throw e;\n    }\n}","preventionTips":["Implement session refresh logic before long-running batch item operations.","In tests, always set up a valid UserInfo in the UserInfoHolder mock.","For USER_TOKEN auth, periodically verify the user account is still active."],"tags":["validation","openapi","item","bad-request","user-session","http-400"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}