{"record":{"id":"89542be4bbba243f","repo":"apereo/cas","slug":"resource-id-id-already-exists-in-namespace-pa","errorCode":null,"errorMessage":"Resource ID ${id} already exists in namespace ${payload.namespace}.","messagePattern":"Resource ID (.+?) already exists in namespace (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"support/cas-server-support-thymeleaf/src/main/resources/static/js/palantir-authz.js","lineNumber":855,"sourceCode":"    const showEditor = $(\"#showHeimdallResourceJsonEditor\").val() === \"true\";\n    localStorage.setItem(HEIMDALL_EDITOR_PREFERENCE, String(showEditor));\n    $(\"#heimdallResourceEditorContainer\").toggle(showEditor);\n    $(\"#heimdallResourceControls\").toggleClass(\"heimdall-resource-controls-expanded\", !showEditor);\n    if (showEditor && typeof ace !== \"undefined\") {\n        setTimeout(() => ace.edit(\"heimdallResourceEditor\").resize(true), 50);\n    }\n}\n\nfunction validateHeimdallResourceIdentity(payload) {\n    const dialog = $(\"#newHeimdallResourceDialog\");\n    const editMode = dialog.data(\"edit-mode\") === true;\n    const originalId = dialog.data(\"original-id\");\n    const catalog = dialog.data(\"resource-catalog\") ?? {};\n    const id = Number($(\"#heimdallResourceId\").val());\n    const duplicate = (catalog[payload.namespace] ?? []).some(resource => Number(resource.id) === Number(id)\n        && (!editMode || Number(resource.id) !== Number(originalId)));\n    if (duplicate) {\n        throw new Error(`Resource ID ${id} already exists in namespace ${payload.namespace}.`);\n    }\n}\n\nfunction storeHeimdallResources(payload) {\n    return $.ajax({\n        url: `${CasActuatorEndpoints.heimdall()}/resources`,\n        method: \"POST\",\n        contentType: \"application/json\",\n        data: JSON.stringify(payload)\n    });\n}\n\nfunction prefillHeimdallResourceDialog(resource) {\n    $(\"#heimdallResourceId\").val(resource.id);\n    $(\"#heimdallResourcePattern\").val(resource.pattern ?? \"\");\n    $(\"#heimdallResourceMethod\").val(resource.method ?? \"\");\n    setHeimdallSwitchState(\"heimdallEnforceAllPolicies\", resource.enforceAllPolicies === true);\n    prefillHeimdallResourceProperties(resource.properties);","sourceCodeStart":837,"sourceCodeEnd":873,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/support/cas-server-support-thymeleaf/src/main/resources/static/js/palantir-authz.js#L837-L873","documentation":"Client-side guard in the Palantir Heimdall resource editor. Before saving a resource it checks the in-memory catalog for an existing resource with the same numeric ID in the same namespace; if one exists (and is not the resource being edited), it throws. This prevents duplicate resource IDs within a namespace in the authorization service.","triggerScenarios":"Submitting the Heimdall resource dialog with a resource ID that already exists in the selected namespace, or editing a resource and changing its ID to collide with another resource in that namespace.","commonSituations":"Re-importing a resource definition with a fixed ID, copy-pasting resource JSON and forgetting to change the ID, or two admins assigning the same numeric ID in one namespace.","solutions":["Pick a resource ID not already used in the target namespace","Verify which namespace you are saving into; the ID may be free in a different namespace","If editing, reopen the dialog so the original-id is tracked and the existing resource is updated instead of created"],"exampleFix":"// before\n$('#heimdallResourceId').val(42); // 42 already exists in namespace\n// after\nconst taken = (catalog[payload.namespace] ?? []).some(r => Number(r.id) === 42);\n$('#heimdallResourceId').val(taken ? nextFreeId(catalog, payload.namespace) : 42);","handlingStrategy":"validation","validationCode":"const catalog = dialog.data(\"resource-catalog\") ?? {};\nconst id = Number($(\"#heimdallResourceId\").val());\nconst taken = (catalog[payload.namespace] ?? []).some(r => Number(r.id) === id && Number(r.id) !== Number(originalId));\nif (taken) { alert(`ID ${id} is already used in namespace ${payload.namespace}`); return; }","typeGuard":"const isIdFree = (catalog, namespace, id, exceptId) =>\n  !(catalog?.[namespace] ?? []).some(r => Number(r.id) === Number(id) && Number(r.id) !== Number(exceptId));","tryCatchPattern":"try { storeHeimdallResources(payload); } catch (e) { if (/already exists in namespace/.test(e.message)) { alert('Choose a different resource ID'); } else { throw e; } }","preventionTips":["Check the resource catalog for the ID before submitting the dialog","Let the system suggest the next free ID instead of typing one manually","When editing, always load the dialog so original-id is tracked"],"tags":["javascript","duplicate-resource-id","validation"],"backgroundTag":"file-already-exists","analyzedSha":"e7288fc434b4f4505b8452e1a57e8fb3111bb863","analyzedAt":"2026-09-08T15:39:16.015Z","contentChangedAt":"2026-09-08T15:39:16.015Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}