You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2023/08/09 07:15:37 UTC

[syncope] 01/02: Supporting mustChangePassword for User templates

This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git

commit 85c5325e82d9da54964f262e1e71e9b03d1063e6
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Wed Aug 9 09:10:26 2023 +0200

    Supporting mustChangePassword for User templates
---
 .../client/console/wizards/any/UserDetails.java    | 32 ++++++++++++----------
 .../client/console/wizards/any/UserDetails.html    |  4 +++
 .../provisioning/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 java.util.List;
 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<UserTO> {
 
     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 class UserDetails extends Details<UserTO> {
         add(username);
         // ------------------------
 
+        // ------------------------
+        // mustChangePassword
+        // ------------------------
+        AjaxCheckBoxPanel mustChangePassword = new AjaxCheckBoxPanel(
+                "mustChangePassword", "mustChangePassword", new PropertyModel<>(userTO, "mustChangePassword"));
+
+        add(mustChangePassword.setOutputMarkupPlaceholderTag(true).setVisible(templateMode));
+        // ------------------------
+
         // ------------------------
         // Password
         // ------------------------
@@ -107,7 +114,7 @@ public class UserDetails extends Details<UserTO> {
                     @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 class UserDetails extends Details<UserTO> {
         accordion.setOutputMarkupId(true);
         accordion.setVisible(showPasswordManagement);
         add(accordion);
-        // ------------------------        
+        // ------------------------
     }
 
     @Override
@@ -130,10 +137,7 @@ public class UserDetails extends Details<UserTO> {
 
         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 @@ under the License.
       <span wicket:id="username"/>
     </div>
 
+    <div class="form-group">
+      <span wicket:id="mustChangePassword"/>
+    </div>
+
     <div wicket:id="accordionPanel"></div>
   </wicket:extend>
 </html>
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 class TemplateUtils {
                 }
             }
 
+            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));