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 4eac9a5a54a5193cf8be065fbeca4cd42f6bc5f0
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Tue Nov 5 10:40:18 2024 +0100

    [SYNCOPE-1839] Removing Commands from Macro Tasks
---
 .../syncope/client/ui/commons/Constants.java       |  2 ++
 .../tasks/CommandComposeDirectoryPanel.java        | 35 +++++++++++++++++-----
 .../wa/starter/mapping/DefaultAuthMapper.java      | 13 +++++---
 3 files changed, 38 insertions(+), 12 deletions(-)

diff --git 
a/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/Constants.java
 
b/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/Constants.java
index 644ce96cdb..ba40bd2598 100644
--- 
a/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/Constants.java
+++ 
b/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/Constants.java
@@ -71,6 +71,8 @@ public final class Constants {
 
     public static final String OPERATION_ERROR = "operation_error";
 
+    public static final String OPERATION_NO_OP = "operation_no_op";
+
     public static final String CAPTCHA_ERROR = "captcha_error";
 
     public static final String SEARCH_ERROR = "search_error";
diff --git 
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/tasks/CommandComposeDirectoryPanel.java
 
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/tasks/CommandComposeDirectoryPanel.java
index aa31489c16..ef7eadc11d 100644
--- 
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/tasks/CommandComposeDirectoryPanel.java
+++ 
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/tasks/CommandComposeDirectoryPanel.java
@@ -18,6 +18,7 @@
  */
 package org.apache.syncope.client.console.tasks;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -162,10 +163,31 @@ public class CommandComposeDirectoryPanel extends 
DirectoryPanel<
             public void onClick(final AjaxRequestTarget target, final 
CommandWrapper ignore) {
                 try {
                     MacroTaskTO actual = 
taskRestClient.readTask(TaskType.MACRO, task);
-                    
actual.getCommands().remove(model.getObject().getCommand());
-                    taskRestClient.update(TaskType.MACRO, actual);
 
-                    
SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
+                    // cannot rely on 
actual.getCommands().remove(model.getObject().getCommand())
+                    // since CommandArgs instances could not be implementing 
equals() / hashCode()
+                    Integer idx = null;
+                    for (int i = 0; i < actual.getCommands().size() && idx == 
null; i++) {
+                        CommandTO actualCmd = actual.getCommands().get(i);
+                        try {
+                            if 
(actualCmd.getKey().equals(model.getObject().getCommand().getKey())
+                                    && 
MAPPER.writeValueAsString(actualCmd.getArgs()).equals(
+                                            
MAPPER.writeValueAsString(model.getObject().getCommand().getArgs()))) {
+
+                                idx = i;
+                            }
+                        } catch (JsonProcessingException e) {
+                            LOG.error("While comparing command arguments", e);
+                        }
+                    }
+                    if (idx == null) {
+                        
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_NO_OP));
+                    } else {
+                        actual.getCommands().remove(idx.intValue());
+                        taskRestClient.update(TaskType.MACRO, actual);
+                        
SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
+                    }
+
                     customActionOnFinishCallback(target);
                 } catch (SyncopeClientException e) {
                     LOG.error("While deleting {}", model.getObject(), e);
@@ -173,7 +195,7 @@ public class CommandComposeDirectoryPanel extends 
DirectoryPanel<
                 }
                 ((BaseWebPage) 
pageRef.getPage()).getNotificationPanel().refresh(target);
             }
-        }, ActionLink.ActionType.DELETE, IdRepoEntitlement.TASK_UPDATE);
+        }, ActionLink.ActionType.DELETE, IdRepoEntitlement.TASK_UPDATE, true);
 
         return panel;
     }
@@ -232,10 +254,7 @@ public class CommandComposeDirectoryPanel extends 
DirectoryPanel<
         @Override
         public Iterator<CommandWrapper> iterator(final long first, final long 
count) {
             MacroTaskTO actual = taskRestClient.readTask(TaskType.MACRO, task);
-
-            List<CommandTO> commands = actual.getCommands();
-
-            return commands.subList((int) first, (int) (first + 
count)).stream().
+            return actual.getCommands().subList((int) first, (int) (first + 
count)).stream().
                     map(command -> new 
CommandWrapper(false).setCommand(command)).
                     iterator();
         }
diff --git 
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/DefaultAuthMapper.java
 
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/DefaultAuthMapper.java
index 3f925e9373..9c2e41f781 100644
--- 
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/DefaultAuthMapper.java
+++ 
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/DefaultAuthMapper.java
@@ -39,6 +39,7 @@ import 
org.apereo.cas.services.AnyAuthenticationHandlerRegisteredServiceAuthenti
 import org.apereo.cas.services.DefaultRegisteredServiceAuthenticationPolicy;
 import 
org.apereo.cas.services.DefaultRegisteredServiceDelegatedAuthenticationPolicy;
 import org.apereo.cas.services.DefaultRegisteredServiceMultifactorPolicy;
+import org.apereo.cas.services.RegisteredServiceAuthenticationPolicyCriteria;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.ObjectProvider;
@@ -52,6 +53,13 @@ public class DefaultAuthMapper implements AuthMapper {
         return DefaultAuthPolicyConf.class.equals(conf.getClass());
     }
 
+    protected RegisteredServiceAuthenticationPolicyCriteria 
buildCriteria(final DefaultAuthPolicyConf policyConf) {
+        AnyAuthenticationHandlerRegisteredServiceAuthenticationPolicyCriteria 
criteria =
+                new 
AnyAuthenticationHandlerRegisteredServiceAuthenticationPolicyCriteria();
+        criteria.setTryAll(policyConf.isTryAll());
+        return criteria;
+    }
+
     @Override
     public AuthMapperResult build(
             final String pac4jCoreName,
@@ -90,10 +98,7 @@ public class DefaultAuthMapper implements AuthMapper {
             authPolicy.setRequiredAuthenticationHandlers(authHandlers);
         }
 
-        AnyAuthenticationHandlerRegisteredServiceAuthenticationPolicyCriteria 
criteria =
-                new 
AnyAuthenticationHandlerRegisteredServiceAuthenticationPolicyCriteria();
-        criteria.setTryAll(policyConf.isTryAll());
-        authPolicy.setCriteria(criteria);
+        authPolicy.setCriteria(buildCriteria(policyConf));
 
         DefaultRegisteredServiceMultifactorPolicy mfaPolicy = null;
         if (!mfaAuthHandlers.isEmpty()) {

Reply via email to