{"record":{"id":"40e7a5bc80e21da1","repo":"theonedev/onedev","slug":"name-is-already-used-by-another-sso-provider","errorCode":null,"errorMessage":"Name is already used by another SSO provider","messagePattern":"Name is already used by another SSO provider","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/SsoProviderResource.java","lineNumber":80,"sourceCode":"\tpublic Long getSsoProviderId(@PathParam(\"name\") String name) {\n    \tif (!SecurityUtils.isAdministrator()) \n\t\t\tthrow new UnauthorizedException();\n\n\t\tvar ssoProvider = ssoProviderService.find(name);\n\t\tif (ssoProvider != null)\n\t\t\treturn ssoProvider.getId();\n\t\telse\n\t\t\tthrow new NotFoundException();\n\t}\n\n\t@Api(order=300, description=\"Create SSO provider\")\n    @POST\n    public Long createSsoProvider(@NotNull @Valid SsoProvider ssoProvider) {\n    \tif (!SecurityUtils.isAdministrator()) \n\t\t\tthrow new UnauthorizedException();\n\n\t\tif (ssoProviderService.find(ssoProvider.getName()) != null)\n\t\t\tthrow new NotAcceptableException(\"Name is already used by another SSO provider\");\n\n\t\tssoProviderService.createOrUpdate(ssoProvider);\n\t\tvar auditContent = VersionedXmlDoc.fromBean(ssoProvider).toXML();\n\t\tauditService.audit(null, \"created SSO provider \\\"\" + ssoProvider.getName() + \"\\\" via RESTful API\", null, auditContent);\n\n    \treturn ssoProvider.getId();\n    }\n\n\t@Api(order=350, description=\"Update SSO provider of specified id\")\n\t@Path(\"/{ssoProviderId}\")\n\t@POST\n\tpublic Response updateSsoProvider(@PathParam(\"ssoProviderId\") Long ssoProviderId, @NotNull @Valid SsoProvider ssoProvider) {\n\t\tif (!SecurityUtils.isAdministrator())\n\t\t\tthrow new UnauthorizedException();\n\n\t\tSsoProvider existingSsoProvider = ssoProviderService.find(ssoProvider.getName());\n\t\tif (existingSsoProvider != null && !existingSsoProvider.equals(ssoProvider))\n\t\t\tthrow new NotAcceptableException(\"Name is already used by another SSO provider\");","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/SsoProviderResource.java#L62-L98","documentation":"Before creating an SSO provider via REST, createSsoProvider checks ssoProviderService.find(ssoProvider.getName()); if an existing provider already uses the requested name, a NotAcceptableException (406) is thrown. Provider names are unique keys, so duplicates cannot be created.","triggerScenarios":"POST to the SSO provider collection endpoint with a JSON body whose 'name' field equals an existing provider's name (case-sensitive lookup by exact name).","commonSituations":"Re-running an idempotent provisioning script without a duplicate check; copying an exported provider config and posting it unchanged; re-creating a provider that was renamed rather than deleted.","solutions":["Choose a unique name for the new SSO provider.","List existing providers (GET the collection endpoint) and reuse/rename instead of creating a duplicate.","Make automation idempotent: check for an existing provider first and update its id via the update endpoint instead of POSTing a new one."],"exampleFix":"// before\nPOST /~api/sso-providers {\"name\":\"azure-ad\", ...}   // 406 if 'azure-ad' exists\n// after: check first, then update\nGET /~api/sso-providers -> find id of 'azure-ad'\nPOST /~api/sso-providers/{id} {\"id\":id, \"name\":\"azure-ad\", ...}","handlingStrategy":"validation","validationCode":"const providers = await fetch('/~api/sso-providers', {headers: {Authorization: auth}}).then(r => r.json());\nif (providers.some(p => p.name === newProvider.name))\n  throw new Error(`SSO provider name '${newProvider.name}' already in use`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefix provider names with an environment/owner (e.g. 'prod-azure-ad').","Make provisioning scripts idempotent: update existing instead of always POSTing.","List existing providers before import."],"tags":["rest-api","uniqueness-constraint","sso","onedev"],"backgroundTag":"resource-already-exists","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}