{"record":{"id":"4add449140acda74","repo":"apolloconfig/apollo","slug":"current-user-not-found-4add44","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/ClusterController.java","lineNumber":152,"sourceCode":"      throw new AccessDeniedException(\"Access is denied\");\n    }\n  }\n\n  private void requireCreateClusterPermissionForUserToken(String appId, String env,\n      String clusterName) {\n    if (UserIdentityConstants.USER_TOKEN.equals(UserIdentityContextHolder.getAuthType())\n        && !unifiedPermissionValidator.hasCreateClusterPermission(appId, env, clusterName)) {\n      throw new AccessDeniedException(\"Create cluster permission is required\");\n    }\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.isBlank(loginUser.getUserId())) {\n        throw new BadRequestException(\"Current user not found\");\n      }\n      return loginUser.getUserId();\n    }\n\n    RequestPrecondition.checkArguments(!StringUtils.isContainEmpty(operator),\n        \"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}\n","sourceCodeStart":134,"sourceCodeEnd":167,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ClusterController.java#L134-L167","documentation":"Thrown by ClusterController.resolveOperator when authType is USER or USER_TOKEN but userInfoHolder.getUser() returns null or a UserInfo with a blank userId. The resolveOperator method determines who is performing the write operation; for interactive or user-token identities, it expects a valid logged-in user in the session context. Maps to HTTP 400 BadRequestException.","triggerScenarios":"Any cluster write endpoint (createCluster, deleteCluster) called with USER or USER_TOKEN auth where the user session has expired, is not populated, or the UserInfoHolder returns a UserInfo object with a null/blank userId field.","commonSituations":"A Portal session expired mid-operation (USER path), or a USER_TOKEN was issued for an account that was subsequently deleted/deactivated. Can also occur in integration tests where the UserInfoHolder mock is not properly configured, or after a Spring Security context is cleared by a concurrent request in the same thread.","solutions":["For USER auth: re-authenticate through the Portal login flow to establish a fresh session.","For USER_TOKEN: verify the token's associated user account still exists and is active in the Portal.","In tests: ensure userInfoHolder.getUser() returns a UserInfo with a non-blank userId before invoking the controller method."],"exampleFix":"// before — test/mock returns null user\nwhen(userInfoHolder.getUser()).thenReturn(null);\ncontroller.createCluster(\"appA\", \"DEV\", clusterDTO); // throws\n\n// after — provide a valid UserInfo\nUserInfo user = new UserInfo();\nuser.setUserId(\"testUser\");\nwhen(userInfoHolder.getUser()).thenReturn(user);","handlingStrategy":"try-catch","validationCode":"// Before calling cluster write, verify user session is valid (for USER/USER_TOKEN auth)\nUserInfo user = userInfoHolder.getUser();\nif (user == null || StringUtils.isBlank(user.getUserId())) {\n    // Re-authenticate or surface a login-required message\n    throw new IllegalStateException(\"No active user session. Please re-authenticate.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    controller.createCluster(appId, env, clusterDTO);\n} catch (BadRequestException e) {\n    if (\"Current user not found\".equals(e.getMessage())) {\n        // Session expired — redirect to login or refresh the token\n        redirectToLogin();\n    } else {\n        throw e;\n    }\n}","preventionTips":["Implement session-heartbeat checks in long-running Portal sessions before write operations.","In tests, always configure userInfoHolder with a valid UserInfo before calling write endpoints.","For USER_TOKEN auth, verify the token's user account exists and is active before use."],"tags":["validation","openapi","cluster","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"}