{"record":{"id":"8ce046b94c5a703c","repo":"theonedev/onedev","slug":"cannot-set-primary-email-address-for-externally-au","errorCode":null,"errorMessage":"Cannot set primary email address for externally authenticated user","messagePattern":"Cannot set primary email address for externally authenticated user","errorType":"http","errorClass":"ExplicitException","httpStatus":400,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/EmailAddressResource.java","lineNumber":105,"sourceCode":"\t\t\n\t\temailAddressService.create(emailAddress);\n\n\t\tif (!getAuthUser().equals(owner)) \n\t\t\tauditService.audit(null, \"added email address \\\"\" + emailAddress.getValue() + \"\\\" in account \\\"\" + owner.getName() + \"\\\" via RESTful API\", null, null);\n\t\treturn emailAddress.getId();\n\t}\n\t\n\t@Api(order=250, description=\"Set as primary email address\")\n\t@Path(\"/primary\")\n\t@POST\n\tpublic Long setAsPrimary(@NotNull Long emailAddressId) {\n\t\tvar emailAddress = emailAddressService.load(emailAddressId);\n\t\tvar owner = emailAddress.getOwner();\n\t\tif (!SecurityUtils.isAdministrator() && !owner.equals(getAuthUser()))\n\t\t\tthrow new UnauthorizedException();\n\t\t\n\t\tif (owner.getPassword() == null)\n\t\t\tthrow new ExplicitException(\"Cannot set primary email address for externally authenticated user\");\n\t\t\n\t\temailAddressService.setAsPrimary(emailAddress);\n\n\t\tif (!getAuthUser().equals(owner)) \n\t\t\tauditService.audit(null, \"set email address \\\"\" + emailAddress.getValue() + \"\\\" as primary in account \\\"\" + owner.getName() + \"\\\" via RESTful API\", null, null);\n\t\t\n\t\treturn emailAddressId;\n\t}\n\t\n\t@Api(order=260, description=\"Resend verification email\")\n\t@Path(\"/resend-verification-email\")\n\t@POST\n\tpublic Long resendVerificationEmail(@NotNull Long emailAddressId) {\n\t\tvar emailAddress = emailAddressService.load(emailAddressId);\n\t\tif (!SecurityUtils.isAdministrator() && !emailAddress.getOwner().equals(getAuthUser()))\n\t\t\tthrow new UnauthorizedException();\n\n\t\tif (settingService.getMailConnector() == null)","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/EmailAddressResource.java#L87-L123","documentation":"Users authenticated through an external provider (e.g. LDAP, OAuth, SAML) have no local password. OneDev refuses to change the primary email address for such users via this endpoint because the primary address is tied to locally-authenticated account management. It throws ExplicitException.","triggerScenarios":"POST to /primary for an email address whose owner.getPassword() == null (externally authenticated user).","commonSituations":"Organization uses SSO/LDAP so all users are externally authenticated; admin scripts assuming local accounts; users migrated from password auth to SSO.","solutions":["Change the primary address in the external identity provider instead","Set a local password for the user (convert to locally authenticated) before changing primary address","Update account settings through the external auth system's admin console"],"exampleFix":"// before\nsetAsPrimary(emailAddressId); // owner is SSO user\n// after\nif (owner.getPassword() != null) setAsPrimary(emailAddressId); else updatePrimaryInIdp(owner);","handlingStrategy":"validation","validationCode":"if (owner.getPassword() == null) route to external IdP instead of API;","typeGuard":"boolean locallyAuthed = owner.getPassword() != null;","tryCatchPattern":"try { setAsPrimary(id); } catch (ExplicitException e) { /* externally authed: change in IdP */ }","preventionTips":["Detect external authentication before address changes","Manage primary addresses via the IdP for SSO users","Document that this endpoint applies to local accounts only"],"tags":["rest-api","sso","external-auth","onedev"],"backgroundTag":"unsupported-operation","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"}