Changing the password at the first login#5323
Open
KremnevDmitry wants to merge 9 commits into
Open
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Added optional support for forcing a user to change their password at the next logon. The feature is opt-in and inert for applications whose user entity does not enable it.
What was done
@PasswordChangeRequiredmeta-annotation (modulesecurity) for aBoolean/booleanattribute on the application's user entity. Its presence activates the feature. A newPasswordChangeRequiredSupportbean reads and writes that flag; if no annotated attribute exists it is a full no-op.UserManager.resetPasswords(...)gained aresetPasswords(Set, boolean saveChanges, boolean requireChangeAtNextLogon)overload; the previous one- and two-argument methods now delegate withrequireChangeAtNextLogon = true.AbstractDatabaseUserRepository, modulesecurity-data) clears the flag when a user changes their own password and sets it according torequireChangeAtNextLogonwhen passwords are reset.ChangePasswordViewdialog is shown while the flag is set (modulesecurity-flowui, viaPasswordChangeRequiredViewListener). The adminResetPasswordViewgot a "Require change at next logon" checkbox.changePasswordViewtoUiMinimalPoliciesso any authenticated user is allowed to open the forced dialog.passwordChangeRequiredattribute on the generatedUserentity plus the Liquibase column.How it works
A
ViewOpenedEventlistener checks the current user after login. If the annotated attribute istrue, a modalChangePasswordViewopens and blocks interaction (Esc / outside-click disabled, no close button) until the password is changed; it cannot be bypassed via direct URL, and duplicate dialogs are guarded against. On success the flag is cleared in the database and on the cached principal, so later logins are unaffected. Applications without the annotation see no change.How to use
Add a
Booleanattribute to yourUserentity and annotate it with@PasswordChangeRequired(the standard project template now does this for new projects). Set it totrueto force a change at the user's next logon — manually, or by resetting the user's password (the admin reset-password dialog sets it by default;UserManager.resetPasswords(users, saveChanges, requireChangeAtNextLogon)controls it programmatically).Breaking changes
UserManagerhas a new abstract methodresetPasswords(Set, boolean, boolean). Code that implementsUserManagerdirectly must implement it; applications extendingAbstractDatabaseUserRepositoryare unaffected. Worth a release-note entry.Compatibility: opt-in; existing applications whose user entity has no
@PasswordChangeRequiredattribute are unaffected.