From 24f61e044cc3411fc440cc3c77e95d25836082c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Tue, 5 Nov 2024 10:40:18 +0100 Subject: [PATCH] [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 void onClick(final AjaxRequestTarget target, final CommandWrapper ignore) 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 void onClick(final AjaxRequestTarget target, final CommandWrapper ignore) } ((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 CommandComposeDataProvider(final int paginatorRows) { @Override public Iterator iterator(final long first, final long count) { MacroTaskTO actual = taskRestClient.readTask(TaskType.MACRO, task); - - List 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 43a9155360..2605706973 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.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 boolean supports(final AuthPolicyConf conf) { 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 AuthMapperResult build( authPolicy.setRequiredAuthenticationHandlers(authHandlers); } - AnyAuthenticationHandlerRegisteredServiceAuthenticationPolicyCriteria criteria = - new AnyAuthenticationHandlerRegisteredServiceAuthenticationPolicyCriteria(); - criteria.setTryAll(policyConf.isTryAll()); - authPolicy.setCriteria(criteria); + authPolicy.setCriteria(buildCriteria(policyConf)); DefaultRegisteredServiceMultifactorPolicy mfaPolicy = null; if (!mfaAuthHandlers.isEmpty()) {