{"record":{"id":"4d4bc9f810e3e28d","repo":"apolloconfig/apollo","slug":"user-is-disabled","errorCode":null,"errorMessage":"User is disabled","messagePattern":"User is disabled","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/UserTokenService.java","lineNumber":380,"sourceCode":"      throw BadRequestException.rateLimitIsInvalid();\n    }\n    if (request.getNamespaces() == null) {\n      return;\n    }\n    for (UserTokenNamespaceScope namespaceScope : request.getNamespaces()) {\n      if (namespaceScope == null) {\n        throw new BadRequestException(\"Token namespace scope can not be null\");\n      }\n    }\n  }\n\n  private void validateUserEnabled(String userId) {\n    UserInfo userInfo = userService.findByUserId(userId);\n    if (userInfo == null) {\n      throw BadRequestException.userNotExists(userId);\n    }\n    if (userInfo.getEnabled() != USER_ENABLED) {\n      throw new BadRequestException(\"User is disabled\");\n    }\n  }\n\n  private Date resolveExpires(Date requestedExpires, Date now) {\n    Date expires = requestedExpires;\n    if (expires == null) {\n      Calendar calendar = Calendar.getInstance();\n      calendar.setTime(now);\n      calendar.add(Calendar.DAY_OF_YEAR, portalConfig.userTokenDefaultExpireDays());\n      expires = calendar.getTime();\n    }\n    if (!expires.after(now)) {\n      throw new BadRequestException(\"Token expires must be in the future\");\n    }\n\n    Calendar maxCalendar = Calendar.getInstance();\n    maxCalendar.setTime(now);\n    maxCalendar.add(Calendar.DAY_OF_YEAR, portalConfig.userTokenMaxExpireDays());","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/UserTokenService.java#L362-L398","documentation":"Thrown by UserTokenService.validateUserEnabled() when the operator's UserInfo exists but has an enabled field not equal to 1 (USER_ENABLED). This check runs during createToken() — disabled users cannot create new tokens. Note that authenticate() (token validation at request time) also silently returns null for disabled users. BadRequestException → HTTP 400.","triggerScenarios":"A user whose portal account has been disabled (enabled=0) attempts to create a new access token via createToken(). The userService.findByUserId() lookup succeeds (the user record exists) but userInfo.getEnabled() != 1.","commonSituations":"An administrator disabled the user's account but the user still has an active session or API client attempting token operations. User was deactivated as part of offboarding but automation still tries to create tokens on their behalf.","solutions":["Have an administrator re-enable the user account (set enabled=1) in the user management interface.","Use a different, enabled user account to create the token.","If the operator is a service account, ensure it is not disabled in the user store."],"exampleFix":"// Not a code fix — requires admin action in the portal user management UI to re-enable the account.","handlingStrategy":"validation","validationCode":"UserInfo userInfo = userService.findByUserId(operator);\nif (userInfo == null || userInfo.getEnabled() != 1) {\n    throw new IllegalStateException(\"User account is disabled or does not exist: \" + operator);\n}\nuserTokenService.createToken(request, operator);","typeGuard":"static boolean isUserEnabled(UserInfo userInfo) {\n    return userInfo != null && userInfo.getEnabled() == 1;\n}","tryCatchPattern":"try {\n    userTokenService.createToken(request, operator);\n} catch (BadRequestException e) {\n    if (e.getMessage().contains(\"User is disabled\")) {\n        return Response.status(400).entity(\"Account is disabled — contact an administrator\").build();\n    }\n    throw e;\n}","preventionTips":["Check user account status before attempting token operations.","Re-enable disabled service accounts before their automation needs to create tokens."],"tags":["apollo-portal","user-token","user-management","bad-request"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}