Skip to content

Commit

Permalink
[SYNCOPE-1839] Removing Commands from Macro Tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Nov 5, 2024
1 parent 7f8a5c6 commit 24f61e0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -162,18 +163,39 @@ 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);
SyncopeConsoleSession.get().onException(e);
}
((BaseWebPage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
}, ActionLink.ActionType.DELETE, IdRepoEntitlement.TASK_UPDATE);
}, ActionLink.ActionType.DELETE, IdRepoEntitlement.TASK_UPDATE, true);

return panel;
}
Expand Down Expand Up @@ -232,10 +254,7 @@ public CommandComposeDataProvider(final int paginatorRows) {
@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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 24f61e0

Please sign in to comment.