Search in sources :

Example 81 with SyncopeClientException

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

the class DynRealmDataBinderImpl method setDynMembership.

private void setDynMembership(final DynRealm dynRealm, final AnyType anyType, final String dynMembershipFIQL) {
    SearchCond dynMembershipCond = SearchCondConverter.convert(dynMembershipFIQL);
    if (!dynMembershipCond.isValid()) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSearchExpression);
        sce.getElements().add(dynMembershipFIQL);
        throw sce;
    }
    DynRealmMembership dynMembership;
    if (dynRealm.getDynMembership(anyType).isPresent()) {
        dynMembership = dynRealm.getDynMembership(anyType).get();
    } else {
        dynMembership = entityFactory.newEntity(DynRealmMembership.class);
        dynMembership.setDynRealm(dynRealm);
        dynMembership.setAnyType(anyType);
        dynRealm.add(dynMembership);
    }
    dynMembership.setFIQLCond(dynMembershipFIQL);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DynRealmMembership(org.apache.syncope.core.persistence.api.entity.DynRealmMembership) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond)

Example 82 with SyncopeClientException

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

the class ReportDataBinderImpl method getReport.

@Override
public void getReport(final Report report, final ReportTO reportTO) {
    BeanUtils.copyProperties(reportTO, report, IGNORE_REPORT_PROPERTIES);
    ReportTemplate template = reportTemplateDAO.find(reportTO.getTemplate());
    if (template == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
        sce.getElements().add("template");
        throw sce;
    }
    report.setTemplate(template);
    reportTO.getReportlets().forEach(reportletKey -> {
        Implementation reportlet = implementationDAO.find(reportletKey);
        if (reportlet == null) {
            LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", reportletKey);
        } else {
            report.add(reportlet);
        }
    });
    // remove all implementations not contained in the TO
    report.getReportlets().removeIf(reportlet -> !reportTO.getReportlets().contains(reportlet.getKey()));
}
Also used : ReportTemplate(org.apache.syncope.core.persistence.api.entity.ReportTemplate) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

Example 83 with SyncopeClientException

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

the class RealmDataBinderImpl method create.

@Override
public Realm create(final Realm parent, final RealmTO realmTO) {
    Realm realm = entityFactory.newEntity(Realm.class);
    realm.setName(realmTO.getName());
    realm.setParent(parent);
    if (realmTO.getPasswordPolicy() != null) {
        Policy policy = policyDAO.find(realmTO.getPasswordPolicy());
        if (policy instanceof PasswordPolicy) {
            realm.setPasswordPolicy((PasswordPolicy) policy);
        } else {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
            sce.getElements().add("Expected " + PasswordPolicy.class.getSimpleName() + ", found " + policy.getClass().getSimpleName());
            throw sce;
        }
    }
    if (realmTO.getAccountPolicy() != null) {
        Policy policy = policyDAO.find(realmTO.getAccountPolicy());
        if (policy instanceof AccountPolicy) {
            realm.setAccountPolicy((AccountPolicy) policy);
        } else {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
            sce.getElements().add("Expected " + AccountPolicy.class.getSimpleName() + ", found " + policy.getClass().getSimpleName());
            throw sce;
        }
    }
    realmTO.getActions().forEach(logicActionsKey -> {
        Implementation logicAction = implementationDAO.find(logicActionsKey);
        if (logicAction == null) {
            LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", logicActionsKey);
        } else {
            realm.add(logicAction);
        }
    });
    setTemplates(realmTO, realm);
    realmTO.getResources().forEach(resourceKey -> {
        ExternalResource resource = resourceDAO.find(resourceKey);
        if (resource == null) {
            LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", resourceKey);
        } else {
            realm.add(resource);
        }
    });
    return realm;
}
Also used : PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) Policy(org.apache.syncope.core.persistence.api.entity.policy.Policy) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) AnyTemplateRealm(org.apache.syncope.core.persistence.api.entity.AnyTemplateRealm) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

Example 84 with SyncopeClientException

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

the class RealmDataBinderImpl method update.

@Override
public PropagationByResource update(final Realm realm, final RealmTO realmTO) {
    realm.setName(realmTO.getName());
    realm.setParent(realmTO.getParent() == null ? null : realmDAO.find(realmTO.getParent()));
    if (realmTO.getAccountPolicy() == null) {
        realm.setAccountPolicy(null);
    } else {
        Policy policy = policyDAO.find(realmTO.getAccountPolicy());
        if (policy instanceof AccountPolicy) {
            realm.setAccountPolicy((AccountPolicy) policy);
        } else {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
            sce.getElements().add("Expected " + AccountPolicy.class.getSimpleName() + ", found " + policy.getClass().getSimpleName());
            throw sce;
        }
    }
    if (realmTO.getPasswordPolicy() == null) {
        realm.setPasswordPolicy(null);
    } else {
        Policy policy = policyDAO.find(realmTO.getPasswordPolicy());
        if (policy instanceof PasswordPolicy) {
            realm.setPasswordPolicy((PasswordPolicy) policy);
        } else {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
            sce.getElements().add("Expected " + PasswordPolicy.class.getSimpleName() + ", found " + policy.getClass().getSimpleName());
            throw sce;
        }
    }
    realmTO.getActions().forEach(logicActionsKey -> {
        Implementation logicActions = implementationDAO.find(logicActionsKey);
        if (logicActions == null) {
            LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", logicActionsKey);
        } else {
            realm.add(logicActions);
        }
    });
    // remove all implementations not contained in the TO
    realm.getActions().removeIf(implementation -> !realmTO.getActions().contains(implementation.getKey()));
    setTemplates(realmTO, realm);
    PropagationByResource propByRes = new PropagationByResource();
    realmTO.getResources().forEach(resourceKey -> {
        ExternalResource resource = resourceDAO.find(resourceKey);
        if (resource == null) {
            LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", resourceKey);
        } else {
            realm.add(resource);
            propByRes.add(ResourceOperation.CREATE, resource.getKey());
        }
    });
    // remove all resources not contained in the TO
    realm.getResources().removeIf(resource -> {
        boolean contained = realmTO.getResources().contains(resource.getKey());
        if (!contained) {
            propByRes.add(ResourceOperation.DELETE, resource.getKey());
        }
        return !contained;
    });
    return propByRes;
}
Also used : PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) Policy(org.apache.syncope.core.persistence.api.entity.policy.Policy) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

Example 85 with SyncopeClientException

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

the class ExecutionsDirectoryPanel method getActions.

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

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final ExecTO ignore) {
            ExecutionsDirectoryPanel.this.getTogglePanel().close(target);
            next(new StringResourceModel("execution.view", ExecutionsDirectoryPanel.this, model).getObject(), new ExecMessage(model.getObject().getMessage()), target);
        }
    }, ActionLink.ActionType.VIEW, StandardEntitlement.TASK_READ);
    panel.add(new ActionLink<ExecTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final ExecTO ignore) {
            ExecutionsDirectoryPanel.this.getTogglePanel().close(target);
            try {
                restClient.deleteExecution(taskExecutionTO.getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (SyncopeClientException scce) {
                SyncopeConsoleSession.get().error(scce.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionLink.ActionType.DELETE, StandardEntitlement.TASK_DELETE, true);
    addFurtherAcions(panel, model);
    return panel;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ExecTO(org.apache.syncope.common.lib.to.ExecTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) BasePage(org.apache.syncope.client.console.pages.BasePage) StringResourceModel(org.apache.wicket.model.StringResourceModel)

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