-
Notifications
You must be signed in to change notification settings - Fork 282
Implement password policy with hook #5419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
62a9d20
Add password policy interface, hook, validator, and helper
JolienTrog c04281b
Add `AnyPasswordPolicy` and `CommonPasswordPolicy`
JolienTrog 78a4d9e
Register built-in password policies in `ApplicationBootstrap`
JolienTrog 291f790
Add `PasswordPolicyConfigForm` to general configuration
JolienTrog 950ab21
Apply password policy to password change and user forms
JolienTrog 46c047e
Document password policy configuration and extension
JolienTrog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
application/forms/Config/General/PasswordPolicyConfigForm.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?php | ||
|
|
||
| // SPDX-FileCopyrightText: 2026 Icinga GmbH <https://icinga.com> | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
|
lippserd marked this conversation as resolved.
|
||
| namespace Icinga\Forms\Config\General; | ||
|
|
||
| use Exception; | ||
| use Icinga\Application\Config; | ||
| use Icinga\Application\Hook\PasswordPolicyHook; | ||
| use Icinga\Application\Logger; | ||
| use Icinga\Authentication\PasswordPolicyHelper; | ||
| use Icinga\Exception\IcingaException; | ||
| use Icinga\Web\Form; | ||
| use Throwable; | ||
|
|
||
| /** | ||
| * Configuration form for password policy selection | ||
| * | ||
| * This form is not used directly but as subform for the {@see GeneralConfigForm}. | ||
| */ | ||
| class PasswordPolicyConfigForm extends Form | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There already was some discussion with @lippserd to move this form into a new Security section in IW2. |
||
| { | ||
| /** | ||
| * @param Config $config The config to load the configured policy from | ||
| */ | ||
| public function __construct(protected Config $config) | ||
| { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| public function init(): void | ||
| { | ||
| $this->setName('form_config_general_password_policy'); | ||
| } | ||
|
|
||
| public function createElements(array $formData): static | ||
| { | ||
| $defaultPolicy = PasswordPolicyHook::DEFAULT_PASSWORD_POLICY; | ||
| $elementName = sprintf('%s_%s', PasswordPolicyHook::CONFIG_SECTION, PasswordPolicyHook::CONFIG_KEY); | ||
| $this->addElement('select', $elementName, [ | ||
| 'description' => $this->translate('Enforce password requirements for new passwords'), | ||
| 'label' => $this->translate('Password Policy'), | ||
| 'value' => $defaultPolicy, | ||
| 'multiOptions' => iterator_to_array(PasswordPolicyHook::yieldPolicies()), | ||
| 'autosubmit' => true, | ||
| ]); | ||
|
|
||
|
lippserd marked this conversation as resolved.
|
||
| try { | ||
| $policy = PasswordPolicyHook::fromCanonicalName($formData[$elementName] ?? $defaultPolicy); | ||
| } catch (Throwable $e) { | ||
| Logger::error("%s\n%s", $e, IcingaException::getConfidentialTraceAsString($e)); | ||
| PasswordPolicyHelper::addError($this, true); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| PasswordPolicyHelper::addDescription($this, $policy); | ||
|
|
||
| // Surface a load error if the saved policy is unavailable, e.g. because | ||
| // its providing module was disabled. The result is intentionally discarded. | ||
| try { | ||
| PasswordPolicyHook::loadConfigured($this->config); | ||
| } catch (Throwable) { | ||
| PasswordPolicyHelper::addError($this, true); | ||
| } | ||
|
|
||
| return $this; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.