Search in sources :

Example 26 with ResourceTO

use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.

the class TopologyTogglePanel method getResourceFragment.

private Fragment getResourceFragment(final TopologyNode node, final PageReference pageRef) {
    Fragment fragment = new Fragment("actions", "resourceActions", this);
    AjaxLink<String> delete = new IndicatingOnConfirmAjaxLink<String>("delete", true) {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            try {
                resourceRestClient.delete(node.getKey());
                target.appendJavaScript(String.format("jsPlumb.remove('%s');", node.getKey()));
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                toggle(target, false);
            } catch (SyncopeClientException e) {
                LOG.error("While deleting resource {}", node.getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(delete, RENDER, StandardEntitlement.RESOURCE_DELETE);
    fragment.add(delete);
    AjaxLink<String> edit = new IndicatingAjaxLink<String>("edit") {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            ResourceTO resource = resourceRestClient.read(node.getKey());
            ConnInstanceTO connInstance = connectorRestClient.read(resource.getConnector());
            IModel<ResourceTO> model = new CompoundPropertyModel<>(resource);
            modal.setFormModel(model);
            target.add(modal.setContent(new ResourceWizardBuilder(resource, pageRef).build(BaseModal.CONTENT_ID, SyncopeConsoleSession.get().owns(StandardEntitlement.RESOURCE_UPDATE, connInstance.getAdminRealm()) ? AjaxWizard.Mode.EDIT : AjaxWizard.Mode.READONLY)));
            modal.header(new Model<>(MessageFormat.format(getString("resource.edit"), node.getKey())));
            modal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(edit, RENDER, StandardEntitlement.RESOURCE_READ);
    fragment.add(edit);
    AjaxLink<String> status = new IndicatingAjaxLink<String>("status") {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            ResourceTO modelObject = resourceRestClient.read(node.getKey());
            target.add(propTaskModal.setContent(new ResourceStatusModal(propTaskModal, pageRef, modelObject)));
            propTaskModal.header(new Model<>(MessageFormat.format(getString("resource.provisioning.status"), node.getKey())));
            propTaskModal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(status, RENDER, StandardEntitlement.USER_UPDATE);
    fragment.add(status);
    AjaxLink<String> provision = new IndicatingAjaxLink<String>("provision") {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            ResourceTO resource = resourceRestClient.read(node.getKey());
            ConnInstanceTO connInstance = connectorRestClient.read(resource.getConnector());
            if (SyncopeConsoleSession.get().owns(StandardEntitlement.RESOURCE_UPDATE, connInstance.getAdminRealm())) {
                provisionModal.addSubmitButton();
            } else {
                provisionModal.removeSubmitButton();
            }
            IModel<ResourceTO> model = new CompoundPropertyModel<>(resource);
            provisionModal.setFormModel(model);
            target.add(provisionModal.setContent(new ResourceProvisionPanel(provisionModal, resource, connInstance.getAdminRealm(), pageRef)));
            provisionModal.header(new Model<>(MessageFormat.format(getString("resource.edit"), node.getKey())));
            provisionModal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(edit, RENDER, StandardEntitlement.RESOURCE_READ);
    fragment.add(provision);
    AjaxLink<String> explore = new IndicatingAjaxLink<String>("explore") {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            ResourceTO resource = resourceRestClient.read(node.getKey());
            target.add(propTaskModal.setContent(new ConnObjects(resource, pageRef)));
            propTaskModal.header(new StringResourceModel("resource.explore.list", Model.of(node)));
            propTaskModal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(explore, RENDER, StandardEntitlement.RESOURCE_LIST_CONNOBJECT);
    fragment.add(explore);
    AjaxLink<String> propagation = new IndicatingAjaxLink<String>("propagation") {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        @SuppressWarnings("unchecked")
        public void onClick(final AjaxRequestTarget target) {
            target.add(propTaskModal.setContent(new PropagationTasks(propTaskModal, node.getKey(), pageRef)));
            propTaskModal.header(new Model<>(MessageFormat.format(getString("task.propagation.list"), node.getKey())));
            propTaskModal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(propagation, RENDER, StandardEntitlement.TASK_LIST);
    fragment.add(propagation);
    AjaxLink<String> pull = new IndicatingAjaxLink<String>("pull") {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            target.add(schedTaskModal.setContent(new PullTasks(schedTaskModal, pageRef, node.getKey())));
            schedTaskModal.header(new Model<>(MessageFormat.format(getString("task.pull.list"), node.getKey())));
            schedTaskModal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(pull, RENDER, StandardEntitlement.TASK_LIST);
    fragment.add(pull);
    AjaxLink<String> push = new IndicatingAjaxLink<String>("push") {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            target.add(schedTaskModal.setContent(new PushTasks(schedTaskModal, pageRef, node.getKey())));
            schedTaskModal.header(new Model<>(MessageFormat.format(getString("task.push.list"), node.getKey())));
            schedTaskModal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(push, RENDER, StandardEntitlement.TASK_LIST);
    fragment.add(push);
    AjaxLink<String> history = new IndicatingAjaxLink<String>("history") {

        private static final long serialVersionUID = -1876519166660008562L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            String resourceKey = String.class.cast(node.getKey());
            final ResourceTO modelObject = resourceRestClient.read(String.class.cast(node.getKey()));
            target.add(historyModal.setContent(new HistoryConfList<>(historyModal, resourceKey, pageRef, modelObject)));
            historyModal.header(new Model<>(MessageFormat.format(getString("resource.menu.history"), node.getDisplayName())));
            historyModal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(history, RENDER, StandardEntitlement.RESOURCE_HISTORY_LIST);
    fragment.add(history);
    // [SYNCOPE-1161] - Option to clone a resource
    AjaxLink<String> clone = new IndicatingOnConfirmAjaxLink<String>("clone", "confirmClone", true) {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            try {
                ResourceTO resource = resourceRestClient.read(node.getKey());
                resource.setKey("Copy of " + resource.getKey());
                // reset some resource objects keys
                if (resource.getOrgUnit() != null) {
                    resource.getOrgUnit().setKey(null);
                    for (ItemTO item : resource.getOrgUnit().getItems()) {
                        item.setKey(null);
                    }
                }
                for (ProvisionTO provision : resource.getProvisions()) {
                    provision.setKey(null);
                    if (provision.getMapping() != null) {
                        for (ItemTO item : provision.getMapping().getItems()) {
                            item.setKey(null);
                        }
                        provision.getMapping().getLinkingItems().clear();
                    }
                    provision.getVirSchemas().clear();
                }
                resourceRestClient.create(resource);
                // refresh Topology
                send(pageRef.getPage(), Broadcast.DEPTH, new AbstractResourceWizardBuilder.CreateEvent(resource.getKey(), resource.getKey(), TopologyNode.Kind.RESOURCE, resource.getConnector(), target));
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                toggle(target, false);
            } catch (SyncopeClientException e) {
                LOG.error("While cloning resource {}", node.getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(clone, RENDER, StandardEntitlement.RESOURCE_CREATE);
    fragment.add(clone);
    return fragment;
}
Also used : ConnObjects(org.apache.syncope.client.console.panels.ConnObjects) ResourceProvisionPanel(org.apache.syncope.client.console.wizards.resources.ResourceProvisionPanel) HistoryConfList(org.apache.syncope.client.console.panels.HistoryConfList) ResourceStatusModal(org.apache.syncope.client.console.status.ResourceStatusModal) PushTasks(org.apache.syncope.client.console.tasks.PushTasks) Fragment(org.apache.wicket.markup.html.panel.Fragment) ItemTO(org.apache.syncope.common.lib.to.ItemTO) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink) AbstractResourceWizardBuilder(org.apache.syncope.client.console.wizards.resources.AbstractResourceWizardBuilder) ResourceWizardBuilder(org.apache.syncope.client.console.wizards.resources.ResourceWizardBuilder) StringResourceModel(org.apache.wicket.model.StringResourceModel) PropagationTasks(org.apache.syncope.client.console.tasks.PropagationTasks) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) IndicatingOnConfirmAjaxLink(org.apache.syncope.client.console.wicket.markup.html.form.IndicatingOnConfirmAjaxLink) AbstractResourceWizardBuilder(org.apache.syncope.client.console.wizards.resources.AbstractResourceWizardBuilder) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PullTasks(org.apache.syncope.client.console.tasks.PullTasks) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO)

Example 27 with ResourceTO

use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.

the class TopologyTogglePanel method getConnectorFragment.

private Fragment getConnectorFragment(final TopologyNode node, final PageReference pageRef) {
    Fragment fragment = new Fragment("actions", "connectorActions", this);
    AjaxLink<String> delete = new IndicatingOnConfirmAjaxLink<String>("delete", true) {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            try {
                connectorRestClient.delete(String.class.cast(node.getKey()));
                target.appendJavaScript(String.format("jsPlumb.remove('%s');", node.getKey()));
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                toggle(target, false);
            } catch (SyncopeClientException e) {
                LOG.error("While deleting resource {}", node.getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(delete, RENDER, StandardEntitlement.CONNECTOR_DELETE);
    fragment.add(delete);
    AjaxLink<String> create = new IndicatingAjaxLink<String>("create") {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            final ResourceTO modelObject = new ResourceTO();
            modelObject.setConnector(String.class.cast(node.getKey()));
            modelObject.setConnectorDisplayName(node.getDisplayName());
            final IModel<ResourceTO> model = new CompoundPropertyModel<>(modelObject);
            modal.setFormModel(model);
            target.add(modal.setContent(new ResourceWizardBuilder(modelObject, pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.CREATE)));
            modal.header(new Model<>(MessageFormat.format(getString("resource.new"), node.getKey())));
            modal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(create, RENDER, StandardEntitlement.RESOURCE_CREATE);
    fragment.add(create);
    AjaxLink<String> edit = new IndicatingAjaxLink<String>("edit") {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            ConnInstanceTO connInstance = connectorRestClient.read(String.class.cast(node.getKey()));
            final IModel<ConnInstanceTO> model = new CompoundPropertyModel<>(connInstance);
            modal.setFormModel(model);
            target.add(modal.setContent(new ConnectorWizardBuilder(connInstance, pageRef).build(BaseModal.CONTENT_ID, SyncopeConsoleSession.get().owns(StandardEntitlement.CONNECTOR_UPDATE, connInstance.getAdminRealm()) ? AjaxWizard.Mode.EDIT : AjaxWizard.Mode.READONLY)));
            modal.header(new Model<>(MessageFormat.format(getString("connector.edit"), connInstance.getDisplayName())));
            modal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(edit, RENDER, StandardEntitlement.CONNECTOR_READ);
    fragment.add(edit);
    AjaxLink<String> history = new IndicatingAjaxLink<String>("history") {

        private static final long serialVersionUID = -1876519166660008562L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            String connKey = String.class.cast(node.getKey());
            ConnInstanceTO connInstance = connectorRestClient.read(connKey);
            target.add(historyModal.setContent(new HistoryConfList<>(historyModal, connKey, pageRef, connInstance)));
            historyModal.header(new Model<>(MessageFormat.format(getString("connector.menu.history"), node.getDisplayName())));
            historyModal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(history, RENDER, StandardEntitlement.CONNECTOR_HISTORY_LIST);
    fragment.add(history);
    return fragment;
}
Also used : HistoryConfList(org.apache.syncope.client.console.panels.HistoryConfList) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) IndicatingOnConfirmAjaxLink(org.apache.syncope.client.console.wicket.markup.html.form.IndicatingOnConfirmAjaxLink) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Fragment(org.apache.wicket.markup.html.panel.Fragment) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ConnectorWizardBuilder(org.apache.syncope.client.console.wizards.resources.ConnectorWizardBuilder) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) AbstractResourceWizardBuilder(org.apache.syncope.client.console.wizards.resources.AbstractResourceWizardBuilder) ResourceWizardBuilder(org.apache.syncope.client.console.wizards.resources.ResourceWizardBuilder) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO)

Example 28 with ResourceTO

use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.

the class ResourceDataBinderImpl method getResourceTO.

@Override
public ResourceTO getResourceTO(final ExternalResource resource) {
    ResourceTO resourceTO = new ResourceTO();
    // set the resource name
    resourceTO.setKey(resource.getKey());
    // set the connector instance
    ConnInstance connector = resource.getConnector();
    resourceTO.setConnector(connector == null ? null : connector.getKey());
    resourceTO.setConnectorDisplayName(connector == null ? null : connector.getDisplayName());
    // set the provision information
    resource.getProvisions().stream().map(provision -> {
        ProvisionTO provisionTO = new ProvisionTO();
        provisionTO.setKey(provision.getKey());
        provisionTO.setAnyType(provision.getAnyType().getKey());
        provisionTO.setObjectClass(provision.getObjectClass().getObjectClassValue());
        provisionTO.getAuxClasses().addAll(provision.getAuxClasses().stream().map(cls -> cls.getKey()).collect(Collectors.toList()));
        provisionTO.setSyncToken(provision.getSerializedSyncToken());
        if (provision.getMapping() != null) {
            MappingTO mappingTO = new MappingTO();
            provisionTO.setMapping(mappingTO);
            mappingTO.setConnObjectLink(provision.getMapping().getConnObjectLink());
            populateItems(provision.getMapping().getItems(), mappingTO);
        }
        virSchemaDAO.findByProvision(provision).forEach(virSchema -> {
            provisionTO.getVirSchemas().add(virSchema.getKey());
            MappingItem linkingMappingItem = virSchema.asLinkingMappingItem();
            ItemTO itemTO = new ItemTO();
            itemTO.setKey(linkingMappingItem.getKey());
            BeanUtils.copyProperties(linkingMappingItem, itemTO, ITEM_IGNORE_PROPERTIES);
            provisionTO.getMapping().getLinkingItems().add(itemTO);
        });
        return provisionTO;
    }).forEachOrdered(provisionTO -> {
        resourceTO.getProvisions().add(provisionTO);
    });
    if (resource.getOrgUnit() != null) {
        OrgUnit orgUnit = resource.getOrgUnit();
        OrgUnitTO orgUnitTO = new OrgUnitTO();
        orgUnitTO.setKey(orgUnit.getKey());
        orgUnitTO.setObjectClass(orgUnit.getObjectClass().getObjectClassValue());
        orgUnitTO.setSyncToken(orgUnit.getSerializedSyncToken());
        orgUnitTO.setConnObjectLink(orgUnit.getConnObjectLink());
        populateItems(orgUnit.getItems(), orgUnitTO);
        resourceTO.setOrgUnit(orgUnitTO);
    }
    resourceTO.setEnforceMandatoryCondition(resource.isEnforceMandatoryCondition());
    resourceTO.setPropagationPriority(resource.getPropagationPriority());
    resourceTO.setRandomPwdIfNotProvided(resource.isRandomPwdIfNotProvided());
    resourceTO.setCreateTraceLevel(resource.getCreateTraceLevel());
    resourceTO.setUpdateTraceLevel(resource.getUpdateTraceLevel());
    resourceTO.setDeleteTraceLevel(resource.getDeleteTraceLevel());
    resourceTO.setProvisioningTraceLevel(resource.getProvisioningTraceLevel());
    resourceTO.setPasswordPolicy(resource.getPasswordPolicy() == null ? null : resource.getPasswordPolicy().getKey());
    resourceTO.setAccountPolicy(resource.getAccountPolicy() == null ? null : resource.getAccountPolicy().getKey());
    resourceTO.setPullPolicy(resource.getPullPolicy() == null ? null : resource.getPullPolicy().getKey());
    resourceTO.getConfOverride().addAll(resource.getConfOverride());
    Collections.sort(resourceTO.getConfOverride());
    resourceTO.setOverrideCapabilities(resource.isOverrideCapabilities());
    resourceTO.getCapabilitiesOverride().addAll(resource.getCapabilitiesOverride());
    resourceTO.getPropagationActions().addAll(resource.getPropagationActions().stream().map(Entity::getKey).collect(Collectors.toList()));
    return resourceTO;
}
Also used : ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PullPolicy(org.apache.syncope.core.persistence.api.entity.policy.PullPolicy) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) JexlUtils(org.apache.syncope.core.provisioning.java.jexl.JexlUtils) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) ParseException(java.text.ParseException) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) MappingTO(org.apache.syncope.common.lib.to.MappingTO) OrgUnitItem(org.apache.syncope.core.persistence.api.entity.resource.OrgUnitItem) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) SchemaType(org.apache.syncope.common.lib.types.SchemaType) ConnInstanceDAO(org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO) ResourceDataBinder(org.apache.syncope.core.provisioning.api.data.ResourceDataBinder) Collectors(java.util.stream.Collectors) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PolicyDAO(org.apache.syncope.core.persistence.api.dao.PolicyDAO) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) ExternalResourceHistoryConfDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceHistoryConfDAO) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) ResourceHistoryConfTO(org.apache.syncope.common.lib.to.ResourceHistoryConfTO) BeanUtils(org.apache.syncope.core.spring.BeanUtils) HashSet(java.util.HashSet) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ItemTO(org.apache.syncope.common.lib.to.ItemTO) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Item(org.apache.syncope.core.persistence.api.entity.resource.Item) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ItemContainerTO(org.apache.syncope.common.lib.to.ItemContainerTO) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) ExternalResourceHistoryConf(org.apache.syncope.core.persistence.api.entity.resource.ExternalResourceHistoryConf) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Component(org.springframework.stereotype.Component) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) OrgUnitTO(org.apache.syncope.common.lib.to.OrgUnitTO) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) IntAttrNameParser(org.apache.syncope.core.provisioning.java.IntAttrNameParser) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) Entity(org.apache.syncope.core.persistence.api.entity.Entity) MappingTO(org.apache.syncope.common.lib.to.MappingTO) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) OrgUnitTO(org.apache.syncope.common.lib.to.OrgUnitTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance)

Example 29 with ResourceTO

use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.

the class ResourceLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_DELETE + "')")
public ResourceTO delete(final String key) {
    ExternalResource resource = resourceDAO.authFind(key);
    if (resource == null) {
        throw new NotFoundException("Resource '" + key + "'");
    }
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_DELETE), resource.getConnector().getAdminRealm().getFullPath());
    securityChecks(effectiveRealms, resource.getConnector().getAdminRealm().getFullPath(), resource.getKey());
    ResourceTO resourceToDelete = binder.getResourceTO(resource);
    resourceDAO.delete(key);
    return resourceToDelete;
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 30 with ResourceTO

use of org.apache.syncope.common.lib.to.ResourceTO in project syncope by apache.

the class ResourceHistoryConfTest method createDelete.

@Test
public void createDelete() {
    ExternalResource ldapResource = resourceDAO.find("resource-ldap");
    assertNotNull(ldapResource);
    ExternalResourceHistoryConf ldapHistory = entityFactory.newEntity(ExternalResourceHistoryConf.class);
    ldapHistory.setCreation(new Date());
    ldapHistory.setCreator("me");
    ldapHistory.setEntity(ldapResource);
    ldapHistory.setConf(new ResourceTO());
    ldapHistory = resourceHistoryConfDAO.save(ldapHistory);
    assertNotNull(ldapHistory.getKey());
    resourceHistoryConfDAO.flush();
    List<ExternalResourceHistoryConf> history = resourceHistoryConfDAO.findByEntity(ldapResource);
    assertEquals(1, history.size());
    assertEquals(ldapHistory, history.get(0));
    resourceHistoryConfDAO.delete(ldapHistory.getKey());
    resourceHistoryConfDAO.flush();
    assertNull(resourceHistoryConfDAO.find(ldapHistory.getKey()));
    assertTrue(resourceHistoryConfDAO.findByEntity(ldapResource).isEmpty());
}
Also used : ExternalResourceHistoryConf(org.apache.syncope.core.persistence.api.entity.resource.ExternalResourceHistoryConf) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Date(java.util.Date) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)61 Test (org.junit.jupiter.api.Test)49 ItemTO (org.apache.syncope.common.lib.to.ItemTO)32 ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)29 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)27 Response (javax.ws.rs.core.Response)23 MappingTO (org.apache.syncope.common.lib.to.MappingTO)23 UserTO (org.apache.syncope.common.lib.to.UserTO)17 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)14 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)12 ResourceService (org.apache.syncope.common.rest.api.service.ResourceService)11 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)10 GroupTO (org.apache.syncope.common.lib.to.GroupTO)10 ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)9 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)9 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)8 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)8 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)8 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)8 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)8