Search in sources :

Example 16 with ProvisionTO

use of org.apache.syncope.common.lib.to.ProvisionTO 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 17 with ProvisionTO

use of org.apache.syncope.common.lib.to.ProvisionTO 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 18 with ProvisionTO

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

the class MultitenancyITCase method createResourceAndPull.

@Test
public void createResourceAndPull() {
    // read connector
    ConnInstanceTO conn = adminClient.getService(ConnectorService.class).read("b7ea96c3-c633-488b-98a0-b52ac35850f7", Locale.ENGLISH.getLanguage());
    assertNotNull(conn);
    assertEquals("LDAP", conn.getDisplayName());
    // prepare resource
    ResourceTO resource = new ResourceTO();
    resource.setKey("new-ldap-resource");
    resource.setConnector(conn.getKey());
    try {
        ProvisionTO provisionTO = new ProvisionTO();
        provisionTO.setAnyType(AnyTypeKind.USER.name());
        provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
        resource.getProvisions().add(provisionTO);
        MappingTO mapping = new MappingTO();
        mapping.setConnObjectLink("'uid=' + username + ',ou=people,o=isp'");
        provisionTO.setMapping(mapping);
        ItemTO item = new ItemTO();
        item.setIntAttrName("username");
        item.setExtAttrName("cn");
        item.setPurpose(MappingPurpose.BOTH);
        mapping.setConnObjectKeyItem(item);
        item = new ItemTO();
        item.setPassword(true);
        item.setIntAttrName("password");
        item.setExtAttrName("userPassword");
        item.setPurpose(MappingPurpose.BOTH);
        item.setMandatoryCondition("true");
        mapping.add(item);
        item = new ItemTO();
        item.setIntAttrName("key");
        item.setPurpose(MappingPurpose.BOTH);
        item.setExtAttrName("sn");
        item.setMandatoryCondition("true");
        mapping.add(item);
        item = new ItemTO();
        item.setIntAttrName("email");
        item.setPurpose(MappingPurpose.BOTH);
        item.setExtAttrName("mail");
        mapping.add(item);
        // create resource
        Response response = adminClient.getService(ResourceService.class).create(resource);
        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
        resource = adminClient.getService(ResourceService.class).read(resource.getKey());
        assertNotNull(resource);
        // create pull task
        PullTaskTO task = new PullTaskTO();
        task.setName("LDAP Pull Task");
        task.setActive(true);
        task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
        task.setResource(resource.getKey());
        task.setPullMode(PullMode.FULL_RECONCILIATION);
        task.setPerformCreate(true);
        response = adminClient.getService(TaskService.class).create(TaskType.PULL, task);
        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
        task = adminClient.getService(TaskService.class).read(TaskType.PULL, StringUtils.substringAfterLast(response.getLocation().toASCIIString(), "/"), true);
        assertNotNull(resource);
        // pull
        ExecTO execution = AbstractTaskITCase.execProvisioningTask(adminClient.getService(TaskService.class), TaskType.PULL, task.getKey(), 50, false);
        // verify execution status
        String status = execution.getStatus();
        assertNotNull(status);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(status));
        // verify that pulled user is found
        PagedResult<UserTO> matchingUsers = adminClient.getService(UserService.class).search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").query()).build());
        assertNotNull(matchingUsers);
        assertEquals(1, matchingUsers.getResult().size());
    } finally {
        adminClient.getService(ResourceService.class).delete(resource.getKey());
    }
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) UserService(org.apache.syncope.common.rest.api.service.UserService) TaskService(org.apache.syncope.common.rest.api.service.TaskService) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) ItemTO(org.apache.syncope.common.lib.to.ItemTO) ConnectorService(org.apache.syncope.common.rest.api.service.ConnectorService) Response(javax.ws.rs.core.Response) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) Test(org.junit.jupiter.api.Test)

Example 19 with ProvisionTO

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

the class PropagationTaskITCase method propagationJEXLTransformer.

@Test
public void propagationJEXLTransformer() {
    // 0. Set propagation JEXL MappingItemTransformer
    ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
    ResourceTO originalResource = SerializationUtils.clone(resource);
    ProvisionTO provision = resource.getProvision("PRINTER").get();
    assertNotNull(provision);
    Optional<ItemTO> mappingItem = provision.getMapping().getItems().stream().filter(item -> "location".equals(item.getIntAttrName())).findFirst();
    assertTrue(mappingItem.isPresent());
    assertTrue(mappingItem.get().getTransformers().isEmpty());
    String suffix = getUUIDString();
    mappingItem.get().setPropagationJEXLTransformer("value + '" + suffix + "'");
    try {
        resourceService.update(resource);
        // 1. create printer on external resource
        AnyObjectTO anyObjectTO = AnyObjectITCase.getSampleTO("propagationJEXLTransformer");
        String originalLocation = anyObjectTO.getPlainAttr("location").get().getValues().get(0);
        assertFalse(originalLocation.endsWith(suffix));
        anyObjectTO = createAnyObject(anyObjectTO).getEntity();
        assertNotNull(anyObjectTO);
        // 2. verify that JEXL MappingItemTransformer was applied during propagation
        // (location ends with given suffix on external resource)
        ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
        assertFalse(anyObjectTO.getPlainAttr("location").get().getValues().get(0).endsWith(suffix));
        assertTrue(connObjectTO.getAttr("LOCATION").get().getValues().get(0).endsWith(suffix));
    } finally {
        resourceService.update(originalResource);
    }
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ExecuteQuery(org.apache.syncope.common.rest.api.beans.ExecuteQuery) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) TaskTO(org.apache.syncope.common.lib.to.TaskTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SerializationUtils(org.apache.commons.lang3.SerializationUtils) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ArrayList(java.util.ArrayList) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PagedResult(org.apache.syncope.common.lib.to.PagedResult) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ExecQuery(org.apache.syncope.common.rest.api.beans.ExecQuery) Test(org.junit.jupiter.api.Test) List(java.util.List) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) BulkAction(org.apache.syncope.common.lib.to.BulkAction) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) TaskType(org.apache.syncope.common.lib.types.TaskType) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Test(org.junit.jupiter.api.Test)

Example 20 with ProvisionTO

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

the class PullTaskITCase method reconcileFromScriptedSQL.

@Test
public void reconcileFromScriptedSQL() throws IOException {
    // 0. reset sync token and set MappingItemTransformer
    ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
    ResourceTO originalResource = SerializationUtils.clone(resource);
    ProvisionTO provision = resource.getProvision("PRINTER").get();
    assertNotNull(provision);
    ItemTO mappingItem = provision.getMapping().getItems().stream().filter(object -> "location".equals(object.getIntAttrName())).findFirst().get();
    assertNotNull(mappingItem);
    final String prefix = "PREFIX_";
    ImplementationTO transformer = new ImplementationTO();
    transformer.setKey("PrefixItemTransformer");
    transformer.setEngine(ImplementationEngine.GROOVY);
    transformer.setType(ImplementationType.ITEM_TRANSFORMER);
    transformer.setBody(IOUtils.toString(getClass().getResourceAsStream("/PrefixItemTransformer.groovy"), StandardCharsets.UTF_8));
    Response response = implementationService.create(transformer);
    transformer = implementationService.read(transformer.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
    assertNotNull(transformer);
    mappingItem.getTransformers().clear();
    mappingItem.getTransformers().add(transformer.getKey());
    try {
        resourceService.update(resource);
        resourceService.removeSyncToken(resource.getKey(), provision.getAnyType());
        // insert a deleted record in the external resource (SYNCOPE-923), which will be returned
        // as sync event prior to the CREATE_OR_UPDATE events generated by the actions below (before pull)
        JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
        jdbcTemplate.update("INSERT INTO TESTPRINTER (id, printername, location, deleted, lastmodification) VALUES (?,?,?,?,?)", UUID.randomUUID().toString(), "Mysterious Printer", "Nowhere", true, new Date());
        // 1. create printer on external resource
        AnyObjectTO anyObjectTO = AnyObjectITCase.getSampleTO("pull");
        String originalLocation = anyObjectTO.getPlainAttr("location").get().getValues().get(0);
        assertFalse(originalLocation.startsWith(prefix));
        anyObjectTO = createAnyObject(anyObjectTO).getEntity();
        assertNotNull(anyObjectTO);
        // 2. verify that PrefixMappingItemTransformer was applied during propagation
        // (location starts with given prefix on external resource)
        ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
        assertFalse(anyObjectTO.getPlainAttr("location").get().getValues().get(0).startsWith(prefix));
        assertTrue(connObjectTO.getAttr("LOCATION").get().getValues().get(0).startsWith(prefix));
        // 3. unlink any existing printer and delete from Syncope (printer is now only on external resource)
        PagedResult<AnyObjectTO> matchingPrinters = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("pull*").query()).build());
        assertTrue(matchingPrinters.getSize() > 0);
        for (AnyObjectTO printer : matchingPrinters.getResult()) {
            anyObjectService.deassociate(new DeassociationPatch.Builder().key(printer.getKey()).action(ResourceDeassociationAction.UNLINK).resource(RESOURCE_NAME_DBSCRIPTED).build());
            anyObjectService.delete(printer.getKey());
        }
        // ensure that the pull task does not have the DELETE capability (SYNCOPE-923)
        PullTaskTO pullTask = taskService.read(TaskType.PULL, "30cfd653-257b-495f-8665-281281dbcb3d", false);
        assertNotNull(pullTask);
        assertFalse(pullTask.isPerformDelete());
        // 4. pull
        execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        // 5. verify that printer was re-created in Syncope (implies that location does not start with given prefix,
        // hence PrefixItemTransformer was applied during pull)
        matchingPrinters = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("pull*").query()).build());
        assertTrue(matchingPrinters.getSize() > 0);
        // 6. verify that synctoken was updated
        assertNotNull(resourceService.read(RESOURCE_NAME_DBSCRIPTED).getProvision(anyObjectTO.getType()).get().getSyncToken());
    } finally {
        resourceService.update(originalResource);
    }
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Date(java.util.Date) ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) Test(org.junit.jupiter.api.Test)

Aggregations

ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)29 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)28 ItemTO (org.apache.syncope.common.lib.to.ItemTO)25 Test (org.junit.jupiter.api.Test)24 MappingTO (org.apache.syncope.common.lib.to.MappingTO)21 Response (javax.ws.rs.core.Response)12 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)12 UserTO (org.apache.syncope.common.lib.to.UserTO)8 GroupTO (org.apache.syncope.common.lib.to.GroupTO)7 HashSet (java.util.HashSet)6 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)6 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)6 ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)6 ResourceService (org.apache.syncope.common.rest.api.service.ResourceService)6 Optional (java.util.Optional)5 SerializationUtils (org.apache.commons.lang3.SerializationUtils)5 AttrTO (org.apache.syncope.common.lib.to.AttrTO)5 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)5