{"record":{"id":"ba60340b8d0aa0e6","repo":"apolloconfig/apollo","slug":"operator-should-not-be-null-or-empty-ba6034","errorCode":null,"errorMessage":"operator should not be null or empty","messagePattern":"operator should not be null or empty","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/AppController.java","lineNumber":277,"sourceCode":"      return;\n    }\n    throw new AccessDeniedException(\"Create application permission is required\");\n  }\n\n  private String resolveOperator(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  private void validatePortalApp(OpenAppDTO app) {\n    if (!UserIdentityConstants.USER.equals(UserIdentityContextHolder.getAuthType())) {\n      return;\n    }\n    if (!StringUtils.hasText(app.getName())) {\n      throw BadRequestException.appNameIsBlank();\n    }\n    if (!InputValidator.isValidClusterNamespace(app.getAppId())) {","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/AppController.java#L259-L295","documentation":"Thrown by AppController.resolveOperator when the auth type is CONSUMER (OpenAPI token-based) and the operator parameter passed from the request is blank. For consumer-token requests, Apollo requires an explicit operator value because the token itself does not identify a human user. StringUtils.hasText(operator) must be true. Results in HTTP 400.","triggerScenarios":"Calling any AppController method that invokes resolveOperator (createApp with CONSUMER auth, createAppInEnv, updateApp, deleteApp) with a Consumer token but without providing an operator parameter, or providing an empty/whitespace operator.","commonSituations":"An OpenAPI client authenticates with a consumer token but does not include the operator field in the request body or header. The OpenAPI spec marks operator as optional but Apollo requires it for consumer-token auth. A client library version that doesn't send the operator field.","solutions":["Include a non-blank operator user ID in the request when authenticating with a consumer token.","Ensure the operator value is a valid user ID that exists in the user service (the next check, findByUserId, will reject unknown users).","If using a Java client, explicitly set the operator parameter on every consumer-token request."],"exampleFix":"// before\n// Consumer-token request without operator\napi.createAppInEnv(\"DEV\", app, null);\n\n// after\n// Consumer-token request with operator\napi.createAppInEnv(\"DEV\", app, \"admin\");","handlingStrategy":"validation","validationCode":"// For CONSUMER auth, ensure operator is provided and valid\nif (UserIdentityConstants.CONSUMER.equals(UserIdentityContextHolder.getAuthType())) {\n    if (operator == null || operator.trim().isEmpty()) {\n        throw new IllegalArgumentException(\n            \"Operator user ID is required for consumer-token requests\");\n    }\n    if (userService.findByUserId(operator) == null) {\n        throw new IllegalArgumentException(\"Operator user does not exist: \" + operator);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include a valid operator user ID in consumer-token requests.","Validate the operator exists in the user service before the API call.","Document that operator is required for CONSUMER auth and optional for USER auth."],"tags":["openapi","validation","apollo-portal","operator","consumer-token","authentication"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}