From ba12ccd99e886f10e004b6c98cd8deba5909266a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Wed, 9 Aug 2023 09:10:26 +0200 Subject: [PATCH] Supporting mustChangePassword for User templates --- .../console/wizards/any/UserDetails.java | 32 +++++++++++-------- .../console/wizards/any/UserDetails.html | 4 +++ .../java/utils/TemplateUtils.java | 8 +++++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/UserDetails.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/UserDetails.java index 018373b106..aa5db4488b 100644 --- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/UserDetails.java +++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/UserDetails.java @@ -22,6 +22,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.syncope.client.ui.commons.Constants; import org.apache.syncope.client.ui.commons.ajax.markup.html.LabelInfo; +import org.apache.syncope.client.ui.commons.markup.html.form.AjaxCheckBoxPanel; import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel; import org.apache.syncope.client.ui.commons.wicket.markup.html.bootstrap.tabs.Accordion; import org.apache.syncope.client.ui.commons.wizards.any.PasswordPanel; @@ -43,25 +44,22 @@ public class UserDetails extends Details { private static final long serialVersionUID = 6592027822510220463L; - private static final String PASSWORD_CONTENT_PATH = "body:content"; - - protected final AjaxTextFieldPanel username; - - protected final UserTO userTO; - public UserDetails( final UserWrapper wrapper, final boolean templateMode, final boolean includeStatusPanel, final boolean showPasswordManagement, final PageReference pageRef) { + super(wrapper, templateMode, includeStatusPanel, pageRef); - userTO = wrapper.getInnerObject(); + UserTO userTO = wrapper.getInnerObject(); + // ------------------------ // Username // ------------------------ - username = new AjaxTextFieldPanel(Constants.USERNAME_FIELD_NAME, Constants.USERNAME_FIELD_NAME, + AjaxTextFieldPanel username = new AjaxTextFieldPanel( + Constants.USERNAME_FIELD_NAME, Constants.USERNAME_FIELD_NAME, new PropertyModel<>(userTO, Constants.USERNAME_FIELD_NAME), false); if (wrapper.getPreviousUserTO() != null && StringUtils.compare( @@ -78,6 +76,15 @@ public UserDetails( add(username); // ------------------------ + // ------------------------ + // mustChangePassword + // ------------------------ + AjaxCheckBoxPanel mustChangePassword = new AjaxCheckBoxPanel( + "mustChangePassword", "mustChangePassword", new PropertyModel<>(userTO, "mustChangePassword")); + + add(mustChangePassword.setOutputMarkupPlaceholderTag(true).setVisible(templateMode)); + // ------------------------ + // ------------------------ // Password // ------------------------ @@ -107,7 +114,7 @@ protected Component newTitle(final String markupId, final ITab tab, final Accord @Override public void onClick(final AjaxRequestTarget target) { model.setObject(model.getObject() == 0 ? -1 : 0); - Component passwordPanel = getParent().get(PASSWORD_CONTENT_PATH); + Component passwordPanel = getParent().get("body:content"); passwordPanel.setEnabled(model.getObject() >= 0); target.add(passwordPanel); } @@ -118,7 +125,7 @@ public void onClick(final AjaxRequestTarget target) { accordion.setOutputMarkupId(true); accordion.setVisible(showPasswordManagement); add(accordion); - // ------------------------ + // ------------------------ } @Override @@ -130,10 +137,7 @@ public static class EditUserPasswordPanel extends Panel { private static final long serialVersionUID = -8198836979773590078L; - public EditUserPasswordPanel( - final String id, - final UserWrapper wrapper, - final boolean templateMode) { + public EditUserPasswordPanel(final String id, final UserWrapper wrapper, final boolean templateMode) { super(id); setOutputMarkupId(true); add(new Label("warning", new ResourceModel("password.change.warning"))); diff --git a/client/idrepo/console/src/main/resources/org/apache/syncope/client/console/wizards/any/UserDetails.html b/client/idrepo/console/src/main/resources/org/apache/syncope/client/console/wizards/any/UserDetails.html index 3812011b93..cf9dcc7703 100644 --- a/client/idrepo/console/src/main/resources/org/apache/syncope/client/console/wizards/any/UserDetails.html +++ b/client/idrepo/console/src/main/resources/org/apache/syncope/client/console/wizards/any/UserDetails.html @@ -22,6 +22,10 @@ +
+ +
+
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/TemplateUtils.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/TemplateUtils.java index 7d063de1f8..28f0bb3ea3 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/TemplateUtils.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/TemplateUtils.java @@ -176,6 +176,14 @@ public void apply(final RealmMember realmMember, final AnyTO template) { } } + if (((UserTO) template).isMustChangePassword()) { + if (realmMember instanceof UserTO) { + ((UserTO) realmMember).setMustChangePassword(true); + } else if (realmMember instanceof UserCR) { + ((UserCR) realmMember).setMustChangePassword(true); + } + } + fillRelationships((GroupableRelatableTO) realmMember, ((GroupableRelatableTO) template)); fillMemberships((GroupableRelatableTO) realmMember, ((GroupableRelatableTO) template));