{"record":{"id":"acccb4cfec974efc","repo":"theonedev/onedev","slug":"two-factor-authentication-not-enabled","errorCode":null,"errorMessage":"Two-factor authentication not enabled","messagePattern":"Two-factor authentication not enabled","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"info","filePath":"server-core/src/main/java/io/onedev/server/web/page/my/twofactorauthentication/MyTwoFactorAuthenticationPage.java","lineNumber":22,"sourceCode":"import io.onedev.server.model.User;\nimport io.onedev.server.web.component.user.twofactorauthentication.TwoFactorAuthenticationStatusPanel;\nimport io.onedev.server.web.page.my.MyPage;\n\nimport static io.onedev.server.model.User.Type.ORDINARY;\nimport static io.onedev.server.web.translation.Translation._T;\n\nimport org.apache.wicket.Component;\nimport org.apache.wicket.markup.html.basic.Label;\nimport org.apache.wicket.request.mapper.parameter.PageParameters;\n\npublic class MyTwoFactorAuthenticationPage extends MyPage {\n\n\tpublic MyTwoFactorAuthenticationPage(PageParameters params) {\n\t\tsuper(params);\n\t\tif (getUser().getType() != ORDINARY || getUser().isDisabled())\n\t\t\tthrow new IllegalStateException();\n\t\telse if (!getUser().isEnforce2FA())\n\t\t\tthrow new ExplicitException(_T(\"Two-factor authentication not enabled\"));\t\t\n\t}\n\t\n\t@Override\n\tprotected void onInitialize() {\n\t\tsuper.onInitialize();\n\n\t\tadd(new TwoFactorAuthenticationStatusPanel(\"content\") {\n\t\t\t@Override\n\t\t\tprotected User getUser() {\n\t\t\t\treturn MyTwoFactorAuthenticationPage.this.getUser();\n\t\t\t}\n\t\t});\n\t}\n\n\t@Override\n\tprotected Component newTopbarTitle(String componentId) {\n\t\treturn new Label(componentId, _T(\"Two Factor Authentication\"));\n\t}","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/web/page/my/twofactorauthentication/MyTwoFactorAuthenticationPage.java#L4-L40","documentation":"MyTwoFactorAuthenticationPage throws an ExplicitException when the current user is not subject to enforced two-factor authentication. The page manages 2FA settings and only applies when 2FA is mandatory for the user. Thrown as a localized, user-facing message.","triggerScenarios":"Opening the my two-factor-authentication page as a user for whom getUser().isEnforce2FA() is false (e.g. not in a group/project requiring 2FA).","commonSituations":"Users on instances without the 2FA enforcement setting enabled, or accounts not covered by the 2FA-enforcing group, trying to self-enroll.","solutions":["Enable two-factor authentication enforcement for the user (via group or system security setting) if 2FA enrollment is desired","Have an admin configure the 2FA requirement in server settings","Use the general profile security page if non-enforced 2FA enrollment is available"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"if (user.getType() == ORDINARY && !user.isEnforce2FA()) {\n    // 2FA page not applicable; hide or route elsewhere\n}","typeGuard":null,"tryCatchPattern":"try {\n    openTwoFactorPage();\n} catch (ExplicitException e) {\n    showNotEnrolledAvailableInfo();\n}","preventionTips":["Only link the 2FA page for users under enforced 2FA","Configure 2FA enforcement (group/system setting) if users should self-manage 2FA","Check isEnforce2FA before rendering 2FA management UI"],"tags":["authentication","two-factor","security","feature-not-enabled"],"backgroundTag":"feature-not-enabled","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"}