Search in sources :

Example 86 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class NotificationTaskDirectoryPanel method getActions.

@Override
public ActionsPanel<NotificationTaskTO> getActions(final IModel<NotificationTaskTO> model) {
    final ActionsPanel<NotificationTaskTO> panel = super.getActions(model);
    final NotificationTaskTO taskTO = model.getObject();
    panel.add(new ActionLink<NotificationTaskTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
            viewTask(taskTO, target);
        }
    }, ActionLink.ActionType.VIEW, StandardEntitlement.TASK_READ);
    panel.add(new ActionLink<NotificationTaskTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
            viewMailBody(MailTemplateFormat.TEXT, taskTO.getTextBody(), target);
        }
    }, ActionLink.ActionType.TEXT, StandardEntitlement.TASK_READ);
    panel.add(new ActionLink<NotificationTaskTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
            viewMailBody(MailTemplateFormat.HTML, taskTO.getHtmlBody(), target);
        }
    }, ActionLink.ActionType.HTML, StandardEntitlement.TASK_READ);
    panel.add(new ActionLink<NotificationTaskTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
            try {
                restClient.startExecution(taskTO.getKey(), null);
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (SyncopeClientException e) {
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                LOG.error("While running {}", taskTO.getKey(), e);
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionLink.ActionType.EXECUTE, StandardEntitlement.TASK_EXECUTE);
    panel.add(new ActionLink<NotificationTaskTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
            try {
                restClient.delete(TaskType.NOTIFICATION, taskTO.getKey());
                updateResultTable(target);
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (SyncopeClientException e) {
                LOG.error("While deleting {}", taskTO.getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionLink.ActionType.DELETE, StandardEntitlement.TASK_DELETE, true);
    return panel;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) BasePage(org.apache.syncope.client.console.pages.BasePage) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO)

Example 87 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class SchedTaskDirectoryPanel method getActions.

@Override
public ActionsPanel<T> getActions(final IModel<T> model) {
    final ActionsPanel<T> panel = super.getActions(model);
    final T taskTO = model.getObject();
    panel.add(new ActionLink<T>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final T ignore) {
            SchedTaskDirectoryPanel.this.getTogglePanel().close(target);
            viewTask(taskTO, target);
        }
    }, ActionLink.ActionType.VIEW, StandardEntitlement.TASK_READ);
    panel.add(new ActionLink<T>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final T ignore) {
            SchedTaskDirectoryPanel.this.getTogglePanel().close(target);
            send(SchedTaskDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(restClient.readTask(taskType, model.getObject().getKey()), target).setResourceModel(new StringResourceModel("inner.task.edit", SchedTaskDirectoryPanel.this, Model.of(Pair.of(ActionLink.ActionType.EDIT, model.getObject())))));
        }
    }, ActionLink.ActionType.EDIT, StandardEntitlement.TASK_UPDATE);
    panel.add(new ActionLink<T>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final T ignore) {
            SchedTaskDirectoryPanel.this.getTogglePanel().close(target);
            final T clone = SerializationUtils.clone(model.getObject());
            clone.setKey(null);
            send(SchedTaskDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(clone, target).setResourceModel(new StringResourceModel("inner.task.clone", SchedTaskDirectoryPanel.this, Model.of(Pair.of(ActionLink.ActionType.CLONE, model.getObject())))));
        }
    }, ActionLink.ActionType.CLONE, StandardEntitlement.TASK_CREATE);
    panel.add(new ActionLink<T>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final T ignore) {
            SchedTaskDirectoryPanel.this.getTogglePanel().close(target);
            startAt.setExecutionDetail(model.getObject().getKey(), model.getObject().getName(), target);
            startAt.toggle(target, true);
        }
    }, ActionLink.ActionType.EXECUTE, StandardEntitlement.TASK_EXECUTE);
    addFurtherActions(panel, model);
    panel.add(new ActionLink<T>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final T ignore) {
            try {
                restClient.delete(taskType, taskTO.getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
                SchedTaskDirectoryPanel.this.getTogglePanel().close(target);
            } catch (SyncopeClientException e) {
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                LOG.error("While deleting propagation task {}", taskTO.getKey(), e);
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionLink.ActionType.DELETE, StandardEntitlement.TASK_DELETE, true);
    return panel;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxWizard(org.apache.syncope.client.console.wizards.AjaxWizard) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) BasePage(org.apache.syncope.client.console.pages.BasePage) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 88 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class ResourceLogic method setLatestSyncToken.

@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_UPDATE + "')")
public void setLatestSyncToken(final String key, final String anyTypeKey) {
    ExternalResource resource = resourceDAO.authFind(key);
    if (resource == null) {
        throw new NotFoundException("Resource '" + key + "'");
    }
    Connector connector;
    try {
        connector = connFactory.getConnector(resource);
    } catch (Exception e) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidConnInstance);
        sce.getElements().add(e.getMessage());
        throw sce;
    }
    if (SyncopeConstants.REALM_ANYTYPE.equals(anyTypeKey)) {
        if (resource.getOrgUnit() == null) {
            throw new NotFoundException("Realm provision not enabled for Resource '" + key + "'");
        }
        resource.getOrgUnit().setSyncToken(connector.getLatestSyncToken(resource.getOrgUnit().getObjectClass()));
    } else {
        AnyType anyType = anyTypeDAO.find(anyTypeKey);
        if (anyType == null) {
            throw new NotFoundException("AnyType '" + anyTypeKey + "'");
        }
        Optional<? extends Provision> provision = resource.getProvision(anyType);
        if (!provision.isPresent()) {
            throw new NotFoundException("Provision for AnyType '" + anyTypeKey + "' in Resource '" + key + "'");
        }
        provision.get().setSyncToken(connector.getLatestSyncToken(provision.get().getObjectClass()));
    }
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_UPDATE), resource.getConnector().getAdminRealm().getFullPath());
    securityChecks(effectiveRealms, resource.getConnector().getAdminRealm().getFullPath(), resource.getKey());
    resourceDAO.save(resource);
}
Also used : Connector(org.apache.syncope.core.provisioning.api.Connector) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 89 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class TaskLogic method read.

@PreAuthorize("hasRole('" + StandardEntitlement.TASK_READ + "')")
@Transactional(readOnly = true)
public <T extends TaskTO> T read(final TaskType type, final String key, final boolean details) {
    Task task = taskDAO.find(key);
    if (task == null) {
        throw new NotFoundException("Task " + key);
    }
    TaskUtils taskUtils = taskUtilsFactory.getInstance(task);
    if (type != null && taskUtils.getType() != type) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add("Found " + type + ", expected " + taskUtils.getType());
        throw sce;
    }
    return binder.getTaskTO(task, taskUtilsFactory.getInstance(task), details);
}
Also used : TaskUtils(org.apache.syncope.core.persistence.api.entity.task.TaskUtils) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) Task(org.apache.syncope.core.persistence.api.entity.task.Task) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 90 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class LoggerLogic method throwInvalidLogger.

private void throwInvalidLogger(final LoggerType type) {
    SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidLogger);
    sce.getElements().add("Expected " + type.name());
    throw sce;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException)

Aggregations

SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)240 Test (org.junit.jupiter.api.Test)105 UserTO (org.apache.syncope.common.lib.to.UserTO)50 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)40 Response (javax.ws.rs.core.Response)34 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)20 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)19 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)18 Realm (org.apache.syncope.core.persistence.api.entity.Realm)18 GroupTO (org.apache.syncope.common.lib.to.GroupTO)17 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)16 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 Map (java.util.Map)14 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)14 ArrayList (java.util.ArrayList)12 List (java.util.List)12 ItemTO (org.apache.syncope.common.lib.to.ItemTO)12 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)12 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)11