{"record":{"id":"e519d8d806083ac9","repo":"passbolt/passbolt_api","slug":"could-not-validate-the-mfa-policies-settings","errorCode":null,"errorMessage":"Could not validate the MFA policies settings.","messagePattern":"Could not validate the MFA policies settings\\.","errorType":"validation","errorClass":"FormValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltEe/MfaPolicies/src/Controller/MfaPoliciesSettingsSetController.php","lineNumber":47,"sourceCode":"    /**\n     * Create/update MFA policies settings.\n     *\n     * @return void\n     */\n    public function post()\n    {\n        if (!$this->User->isAdmin()) {\n            throw new ForbiddenException(\n                __('Only administrators are allowed to create/update MFA policies settings.')\n            );\n        }\n\n        $requestData = $this->getRequest()->getData();\n\n        $form = new MfaPoliciesSettingsForm();\n\n        if (!$form->execute($requestData)) {\n            throw new FormValidationException(__('Could not validate the MFA policies settings.'), $form);\n        }\n\n        $setSettingsService = new MfaPoliciesSetSettingsService();\n\n        $mfaPolicySettingsDto = MfaPolicySettings::createFromArray([\n            'policy' => $form->getData('policy'),\n            'remember_me_for_a_month' => $form->getData('remember_me_for_a_month'),\n        ]);\n\n        $settings = $setSettingsService->createOrUpdate($this->User->getExtendAccessControl(), $mfaPolicySettingsDto);\n\n        $this->success(__('The operation was successful.'), $settings);\n    }\n}\n","sourceCodeStart":29,"sourceCodeEnd":62,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/MfaPolicies/src/Controller/MfaPoliciesSettingsSetController.php#L29-L62","documentation":"The POST body for MFA policy settings is validated by MfaPoliciesSettingsForm (e.g. 'policy' must be an allowed value like 'mandatory'/'opt-out' or 'opt-in'). When $form->execute($requestData) fails, a FormValidationException with this message is thrown, carrying the form's errors.","triggerScenarios":"POST /mfa/policies/settings.json with missing or invalid fields — e.g. policy not in the allowed enum, unexpected extra types, or empty request data.","commonSituations":"API clients sending 'policy' values other than the supported enum, omitting the policy key, or sending JSON not parsed into form fields.","solutions":["Inspect the FormValidationException errors to see which field failed","Send only the supported 'policy' value ('mandatory' or 'opt-out' depending on edition/version)","Ensure the request body is JSON with content-type application/json and contains the 'policy' key"],"exampleFix":"// before\n{\"mfaPolicy\": \"enforced\"}\n// after\n{\"policy\": \"mandatory\"}","handlingStrategy":"validation","validationCode":"$data = $this->getRequest()->getData();\n$form = new MfaPoliciesSettingsForm();\nif (!$form->execute($data)) {\n    $errors = $form->getErrors(); // inspect before proceeding\n}","typeGuard":null,"tryCatchPattern":"try {\n    $resp = $client->post('/mfa/policies/settings.json', ['policy' => 'mandatory']);\n} catch (FormValidationException $e) {\n    $errors = $e->getForm()->getErrors();\n}","preventionTips":["Only send the documented 'policy' enum values","Send JSON with proper content-type header","Consult the form/DTO definition for accepted fields before integrating"],"tags":["mfa-policies","validation","form-validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}