Search in sources :

Example 1 with RemediationTO

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

the class RemediationDataBinderImpl method getRemediationTO.

@Override
public RemediationTO getRemediationTO(final Remediation remediation) {
    RemediationTO remediationTO = new RemediationTO();
    BeanUtils.copyProperties(remediation, remediationTO);
    switch(remediation.getOperation()) {
        case CREATE:
            remediationTO.setAnyTOPayload(remediation.getPayloadAsTO(remediation.getAnyType().getKind().getTOClass()));
            break;
        case UPDATE:
            remediationTO.setAnyPatchPayload(remediation.getPayloadAsPatch(remediation.getAnyType().getKind().getPatchClass()));
            break;
        case DELETE:
            remediationTO.setKeyPayload(remediation.getPayloadAsKey());
            break;
        default:
    }
    remediationTO.setAnyType(remediation.getAnyType().getKey());
    if (remediation.getPullTask() != null) {
        remediationTO.setPullTask(remediation.getPullTask().getKey());
        remediationTO.setResource(remediation.getPullTask().getResource().getKey());
    }
    return remediationTO;
}
Also used : RemediationTO(org.apache.syncope.common.lib.to.RemediationTO)

Example 2 with RemediationTO

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

the class PullTaskITCase method remediation.

@Test
public void remediation() {
    // First of all, clear any potential conflict with existing user / group
    ldapCleanup();
    // 1. create ldap cloned resource, where 'userId' (mandatory on Syncope) is removed from mapping
    ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
    ldap.setKey("ldapForRemediation");
    ProvisionTO provision = ldap.getProvision(AnyTypeKind.USER.name()).get();
    provision.getVirSchemas().clear();
    provision.getMapping().getItems().removeIf(item -> "userId".equals(item.getIntAttrName()));
    ldap = createResource(ldap);
    // 2. create PullTask with remediation enabled, for the new resource
    PullTaskTO pullTask = (PullTaskTO) taskService.search(new TaskQuery.Builder(TaskType.PULL).resource(RESOURCE_NAME_LDAP).build()).getResult().get(0);
    assertNotNull(pullTask);
    pullTask.setResource(ldap.getKey());
    pullTask.setRemediation(true);
    pullTask.getActions().clear();
    Response response = taskService.create(TaskType.PULL, pullTask);
    if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
        throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
    }
    pullTask = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
    assertNotNull(pullTask);
    try {
        // 3. execute the pull task and verify that:
        ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
        // 3a. user was not pulled
        try {
            userService.read("pullFromLDAP");
            fail("This should never happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.NotFound, e.getType());
        }
        // 3b. remediation was created
        Optional<RemediationTO> remediation = remediationService.list().stream().filter(r -> "uid=pullFromLDAP,ou=People,o=isp".equalsIgnoreCase(r.getRemoteName())).findFirst();
        assertTrue(remediation.isPresent());
        assertEquals(AnyTypeKind.USER.name(), remediation.get().getAnyType());
        assertEquals(ResourceOperation.CREATE, remediation.get().getOperation());
        assertNotNull(remediation.get().getAnyTOPayload());
        assertNull(remediation.get().getAnyPatchPayload());
        assertNull(remediation.get().getKeyPayload());
        assertTrue(remediation.get().getError().contains("RequiredValuesMissing [userId]"));
        // 4. remedy by copying the email value to userId
        UserTO user = (UserTO) remediation.get().getAnyTOPayload();
        user.getResources().clear();
        String email = user.getPlainAttr("email").get().getValues().get(0);
        user.getPlainAttrs().add(new AttrTO.Builder().schema("userId").value(email).build());
        remediationService.remedy(remediation.get().getKey(), user);
        // 5. user is now found
        user = userService.read("pullFromLDAP");
        assertNotNull(user);
        assertEquals(email, user.getPlainAttr("userId").get().getValues().get(0));
        // 6. remediation was removed
        try {
            remediationService.read(remediation.get().getKey());
            fail("This should never happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.NotFound, e.getType());
        }
    } finally {
        resourceService.delete(ldap.getKey());
    }
}
Also used : ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TaskTO(org.apache.syncope.common.lib.to.TaskTO) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) ResourceDeassociationAction(org.apache.syncope.common.lib.types.ResourceDeassociationAction) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) LDAPPasswordPullActions(org.apache.syncope.core.provisioning.java.pushpull.LDAPPasswordPullActions) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Pair(org.apache.commons.lang3.tuple.Pair) BeforeAll(org.junit.jupiter.api.BeforeAll) Locale(java.util.Locale) Map(java.util.Map) RESTHeaders(org.apache.syncope.common.rest.api.RESTHeaders) PagedResult(org.apache.syncope.common.lib.to.PagedResult) FlowableDetector(org.apache.syncope.fit.FlowableDetector) ExecTO(org.apache.syncope.common.lib.to.ExecTO) PullMode(org.apache.syncope.common.lib.types.PullMode) DBPasswordPullActions(org.apache.syncope.core.provisioning.java.pushpull.DBPasswordPullActions) Set(java.util.Set) UUID(java.util.UUID) GroupTO(org.apache.syncope.common.lib.to.GroupTO) StandardCharsets(java.nio.charset.StandardCharsets) ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Test(org.junit.jupiter.api.Test) IOUtils(org.apache.commons.io.IOUtils) ImplementationEngine(org.apache.syncope.common.lib.types.ImplementationEngine) Response(javax.ws.rs.core.Response) DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) TestPullActions(org.apache.syncope.fit.core.reference.TestPullActions) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) RemediationTO(org.apache.syncope.common.lib.to.RemediationTO) PullPolicyTO(org.apache.syncope.common.lib.policy.PullPolicyTO) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) TaskService(org.apache.syncope.common.rest.api.service.TaskService) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) SerializationUtils(org.apache.commons.lang3.SerializationUtils) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) HashSet(java.util.HashSet) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) DataSource(javax.sql.DataSource) ItemTO(org.apache.syncope.common.lib.to.ItemTO) ImplementationType(org.apache.syncope.common.lib.types.ImplementationType) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) CipherAlgorithm(org.apache.syncope.common.lib.types.CipherAlgorithm) OutputStream(java.io.OutputStream) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) Properties(java.util.Properties) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) Encryptor(org.apache.syncope.core.spring.security.Encryptor) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Name(org.identityconnectors.framework.common.objects.Name) PolicyType(org.apache.syncope.common.lib.types.PolicyType) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) ConnectorCapability(org.apache.syncope.common.lib.types.ConnectorCapability) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ConnectorService(org.apache.syncope.common.rest.api.service.ConnectorService) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserTO(org.apache.syncope.common.lib.to.UserTO) InputStream(java.io.InputStream) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) TaskType(org.apache.syncope.common.lib.types.TaskType) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RemediationTO(org.apache.syncope.common.lib.to.RemediationTO) Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) Test(org.junit.jupiter.api.Test)

Example 3 with RemediationTO

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

the class RemediationServiceImpl method check.

private void check(final String key, final String anyKey) {
    RemediationTO remediation = logic.read(key);
    AnyDAO<?> anyDAO;
    switch(remediation.getAnyType()) {
        case "USER":
            anyDAO = userDAO;
            break;
        case "GROUP":
            anyDAO = groupDAO;
            break;
        default:
            anyDAO = anyObjectDAO;
    }
    Date etagDate = anyDAO.findLastChange(anyKey);
    if (etagDate == null) {
        throw new NotFoundException(remediation.getAnyType() + " for " + key);
    }
    checkETag(String.valueOf(etagDate.getTime()));
}
Also used : RemediationTO(org.apache.syncope.common.lib.to.RemediationTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Date(java.util.Date)

Example 4 with RemediationTO

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

the class RemediationDirectoryPanel method getActions.

@Override
protected ActionsPanel<RemediationTO> getActions(final IModel<RemediationTO> model) {
    ActionsPanel<RemediationTO> panel = super.getActions(model);
    panel.add(new ActionLink<RemediationTO>() {

        private static final long serialVersionUID = 6193210574968203299L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RemediationTO ignore) {
            modal.header(new ResourceModel("error"));
            modal.setContent(new ExecMessageModal(model.getObject().getError()));
            modal.show(true);
            target.add(modal);
        }
    }, ActionLink.ActionType.VIEW_DETAILS, StandardEntitlement.REMEDIATION_READ);
    if (model.getObject().getOperation() == ResourceOperation.DELETE) {
        String entitlements = StringUtils.join(new String[] { StandardEntitlement.REMEDIATION_REMEDY, AnyTypeKind.USER.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.USER_DELETE : AnyTypeKind.GROUP.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.GROUP_DELETE : AnyEntitlement.DELETE.getFor(model.getObject().getAnyType()) }, ",");
        panel.add(new ActionLink<RemediationTO>() {

            private static final long serialVersionUID = 6193210574968203299L;

            @Override
            public void onClick(final AjaxRequestTarget target, final RemediationTO ignore) {
                try {
                    restClient.remedy(model.getObject().getKey(), model.getObject().getKeyPayload());
                    SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                    target.add(container);
                } catch (SyncopeClientException e) {
                    LOG.error("While performing remediation {}", model.getObject().getKey(), e);
                    SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                }
                ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
            }
        }, ActionLink.ActionType.CLOSE, entitlements, true);
    } else {
        String entitlements = model.getObject().getOperation() == ResourceOperation.CREATE ? StringUtils.join(new String[] { StandardEntitlement.REMEDIATION_REMEDY, AnyTypeKind.USER.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.USER_CREATE : AnyTypeKind.GROUP.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.GROUP_CREATE : AnyEntitlement.CREATE.getFor(model.getObject().getAnyType()) }, ",") : StringUtils.join(new String[] { StandardEntitlement.REMEDIATION_REMEDY, AnyTypeKind.USER.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.USER_UPDATE : AnyTypeKind.GROUP.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.GROUP_UPDATE : AnyEntitlement.UPDATE.getFor(model.getObject().getAnyType()) }, ",");
        panel.add(new ActionLink<RemediationTO>() {

            private static final long serialVersionUID = 6193210574968203299L;

            @Override
            public void onClick(final AjaxRequestTarget target, final RemediationTO ignore) {
                modal.setFormModel(new CompoundPropertyModel<>(model.getObject()));
                RemediationTO remediationTO = model.getObject();
                switch(remediationTO.getAnyType()) {
                    case "USER":
                        UserTO newUserTO;
                        UserTO previousUserTO;
                        if (remediationTO.getAnyPatchPayload() == null) {
                            newUserTO = (UserTO) remediationTO.getAnyTOPayload();
                            previousUserTO = null;
                        } else {
                            previousUserTO = new UserRestClient().read(remediationTO.getAnyPatchPayload().getKey());
                            newUserTO = AnyOperations.patch(previousUserTO, (UserPatch) remediationTO.getAnyPatchPayload());
                        }
                        AjaxWizard.EditItemActionEvent<UserTO> userEvent = new AjaxWizard.EditItemActionEvent<>(newUserTO, target);
                        userEvent.forceModalPanel(new RemediationUserWizardBuilder(model.getObject(), previousUserTO, newUserTO, new AnyTypeRestClient().read(remediationTO.getAnyType()).getClasses(), FormLayoutInfoUtils.fetch(Arrays.asList(remediationTO.getAnyType())).getLeft(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
                        send(RemediationDirectoryPanel.this, Broadcast.EXACT, userEvent);
                        break;
                    case "GROUP":
                        GroupTO newGroupTO;
                        GroupTO previousGroupTO;
                        if (remediationTO.getAnyPatchPayload() == null) {
                            newGroupTO = (GroupTO) remediationTO.getAnyTOPayload();
                            previousGroupTO = null;
                        } else {
                            previousGroupTO = new GroupRestClient().read(remediationTO.getAnyPatchPayload().getKey());
                            newGroupTO = AnyOperations.patch(previousGroupTO, (GroupPatch) remediationTO.getAnyPatchPayload());
                        }
                        AjaxWizard.EditItemActionEvent<GroupTO> groupEvent = new AjaxWizard.EditItemActionEvent<>(newGroupTO, target);
                        groupEvent.forceModalPanel(new RemediationGroupWizardBuilder(model.getObject(), previousGroupTO, newGroupTO, new AnyTypeRestClient().read(remediationTO.getAnyType()).getClasses(), FormLayoutInfoUtils.fetch(Arrays.asList(remediationTO.getAnyType())).getMiddle(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
                        send(RemediationDirectoryPanel.this, Broadcast.EXACT, groupEvent);
                        break;
                    default:
                        AnyObjectTO newAnyObjectTO;
                        AnyObjectTO previousAnyObjectTO;
                        if (remediationTO.getAnyPatchPayload() == null) {
                            newAnyObjectTO = (AnyObjectTO) remediationTO.getAnyTOPayload();
                            previousAnyObjectTO = null;
                        } else {
                            previousAnyObjectTO = new AnyObjectRestClient().read(remediationTO.getAnyPatchPayload().getKey());
                            newAnyObjectTO = AnyOperations.patch(previousAnyObjectTO, (AnyObjectPatch) remediationTO.getAnyPatchPayload());
                        }
                        AjaxWizard.EditItemActionEvent<AnyObjectTO> anyObjectEvent = new AjaxWizard.EditItemActionEvent<>(newAnyObjectTO, target);
                        anyObjectEvent.forceModalPanel(new RemediationAnyObjectWizardBuilder(model.getObject(), previousAnyObjectTO, newAnyObjectTO, new AnyTypeRestClient().read(remediationTO.getAnyType()).getClasses(), FormLayoutInfoUtils.fetch(Arrays.asList(remediationTO.getAnyType())).getRight().values().iterator().next(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
                        send(RemediationDirectoryPanel.this, Broadcast.EXACT, anyObjectEvent);
                }
            }
        }, ActionLink.ActionType.EDIT, entitlements);
    }
    panel.add(new ActionLink<RemediationTO>() {

        private static final long serialVersionUID = 6193210574968203299L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RemediationTO ignore) {
            try {
                restClient.delete(model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (SyncopeClientException e) {
                LOG.error("While deleting {}", model.getObject().getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionLink.ActionType.DELETE, StandardEntitlement.REMEDIATION_DELETE, true);
    return panel;
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ResourceModel(org.apache.wicket.model.ResourceModel) StringResourceModel(org.apache.wicket.model.StringResourceModel) GroupRestClient(org.apache.syncope.client.console.rest.GroupRestClient) AnyObjectRestClient(org.apache.syncope.client.console.rest.AnyObjectRestClient) BasePage(org.apache.syncope.client.console.pages.BasePage) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) AjaxWizard(org.apache.syncope.client.console.wizards.AjaxWizard) AnyTypeRestClient(org.apache.syncope.client.console.rest.AnyTypeRestClient) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RemediationTO(org.apache.syncope.common.lib.to.RemediationTO) UserRestClient(org.apache.syncope.client.console.rest.UserRestClient) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) UserTO(org.apache.syncope.common.lib.to.UserTO)

Aggregations

RemediationTO (org.apache.syncope.common.lib.to.RemediationTO)4 Date (java.util.Date)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)2 GroupTO (org.apache.syncope.common.lib.to.GroupTO)2 UserTO (org.apache.syncope.common.lib.to.UserTO)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Set (java.util.Set)1 UUID (java.util.UUID)1 DataSource (javax.sql.DataSource)1