Search in sources :

Example 26 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class UserWorkflowITCase method updateApproval.

@Test
public void updateApproval() {
    assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
    // read forms *before* any operation
    List<WorkflowFormTO> forms = userWorkflowService.getForms();
    assertNotNull(forms);
    int preForms = forms.size();
    UserTO created = createUser(UserITCase.getUniqueSampleTO("updateApproval@syncope.apache.org")).getEntity();
    assertNotNull(created);
    assertEquals("/", created.getRealm());
    assertEquals(0, created.getMemberships().size());
    UserPatch patch = new UserPatch();
    patch.setKey(created.getKey());
    patch.getMemberships().add(new MembershipPatch.Builder().group("b1f7c12d-ec83-441f-a50e-1691daaedf3b").build());
    SyncopeClient client = clientFactory.create(created.getUsername(), "password123");
    Response response = client.getService(UserSelfService.class).update(patch);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals("updateApproval", userService.read(created.getKey()).getStatus());
    forms = userWorkflowService.getForms();
    assertNotNull(forms);
    assertEquals(preForms + 1, forms.size());
    WorkflowFormTO form = userWorkflowService.getFormForUser(created.getKey());
    assertNotNull(form);
    assertNotNull(form.getTaskId());
    assertNull(form.getOwner());
    assertNotNull(form.getUserTO());
    assertNotNull(form.getUserPatch());
    assertEquals(patch, form.getUserPatch());
    // as admin, request for more changes: still pending approval
    patch.setRealm(new StringReplacePatchItem.Builder().value("/even/two").build());
    response = userService.update(patch);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals("updateApproval", userService.read(created.getKey()).getStatus());
    // the patch is updated in the approval form
    form = userWorkflowService.getFormForUser(created.getKey());
    assertEquals(patch, form.getUserPatch());
    // approve the user
    form = userWorkflowService.claimForm(form.getTaskId());
    form.getProperty("approveUpdate").get().setValue(Boolean.TRUE.toString());
    userWorkflowService.submitForm(form);
    // verify that the approved user bears both original and further changes
    UserTO approved = userService.read(created.getKey());
    assertNotNull(approved);
    assertEquals("/even/two", approved.getRealm());
    assertEquals(1, approved.getMemberships().size());
    assertNotNull(approved.getMembership("b1f7c12d-ec83-441f-a50e-1691daaedf3b").get());
}
Also used : Response(javax.ws.rs.core.Response) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) UserSelfService(org.apache.syncope.common.rest.api.service.UserSelfService) UserTO(org.apache.syncope.common.lib.to.UserTO) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) Test(org.junit.jupiter.api.Test)

Example 27 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class VirAttrITCase method issueSYNCOPE442.

@Test
public void issueSYNCOPE442() {
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope442@apache.org");
    userTO.getVirAttrs().clear();
    AttrTO virAttrTO = new AttrTO();
    virAttrTO.setSchema("virtualdata");
    virAttrTO.getValues().add("virattrcache");
    userTO.getVirAttrs().add(virAttrTO);
    userTO.getMemberships().clear();
    userTO.getResources().clear();
    userTO.getResources().add(RESOURCE_NAME_DBVIRATTR);
    // 1. create user
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    // 2. check for virtual attribute value
    userTO = userService.read(userTO.getKey());
    assertEquals("virattrcache", userTO.getVirAttr("virtualdata").get().getValues().get(0));
    // ----------------------------------------
    // 3. change connector URL so that we are sure that any provided value will come from virtual cache
    // ----------------------------------------
    String jdbcURL = null;
    ConnInstanceTO connInstanceTO = connectorService.readByResource(RESOURCE_NAME_DBVIRATTR, Locale.ENGLISH.getLanguage());
    for (ConnConfProperty prop : connInstanceTO.getConf()) {
        if ("jdbcUrlTemplate".equals(prop.getSchema().getName())) {
            jdbcURL = prop.getValues().iterator().next().toString();
            prop.getValues().clear();
            prop.getValues().add("jdbc:h2:tcp://localhost:9092/xxx");
        }
    }
    connectorService.update(connInstanceTO);
    // ----------------------------------------
    // ----------------------------------------
    // 4. update value on external resource
    // ----------------------------------------
    JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
    String value = queryForObject(jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
    assertEquals("virattrcache", value);
    jdbcTemplate.update("UPDATE testpull set USERNAME='virattrcache2' WHERE ID=?", userTO.getKey());
    value = queryForObject(jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
    assertEquals("virattrcache2", value);
    // ----------------------------------------
    userTO = userService.read(userTO.getKey());
    assertEquals("virattrcache", userTO.getVirAttr("virtualdata").get().getValues().get(0));
    // ----------------------------------------
    for (ConnConfProperty prop : connInstanceTO.getConf()) {
        if ("jdbcUrlTemplate".equals(prop.getSchema().getName())) {
            prop.getValues().clear();
            prop.getValues().add(jdbcURL);
        }
    }
    connectorService.update(connInstanceTO);
    // ----------------------------------------
    // cached value still in place...
    userTO = userService.read(userTO.getKey());
    assertEquals("virattrcache", userTO.getVirAttr("virtualdata").get().getValues().get(0));
    // force cache update by adding a resource which has virtualdata mapped for propagation
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_WS2).build());
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    userTO = userService.read(userTO.getKey());
    assertEquals("virattrcache2", userTO.getVirAttr("virtualdata").get().getValues().get(0));
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 28 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class VirAttrITCase method issueSYNCOPE691.

@Test
public void issueSYNCOPE691() {
    ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
    try {
        ProvisionTO provision = ldap.getProvision(AnyTypeKind.USER.name()).orElse(null);
        assertNotNull(provision);
        List<ItemTO> mail = provision.getMapping().getItems().stream().filter(item -> "mail".equals(item.getExtAttrName())).collect(Collectors.toList());
        provision.getMapping().getItems().removeAll(mail);
        provision.getVirSchemas().clear();
        ldap.getProvisions().clear();
        ldap.getProvisions().add(provision);
        ldap.setKey(RESOURCE_NAME_LDAP + "691" + getUUIDString());
        resourceService.create(ldap);
        ldap = resourceService.read(ldap.getKey());
        provision = ldap.getProvision(AnyTypeKind.USER.name()).get();
        assertNotNull(provision);
        // create new virtual schema for the resource below
        VirSchemaTO virSchema = new VirSchemaTO();
        virSchema.setKey("syncope691" + getUUIDString());
        virSchema.setExtAttrName("mail");
        virSchema.setResource(ldap.getKey());
        virSchema.setAnyType(provision.getAnyType());
        virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
        assertNotNull(virSchema);
        AnyTypeClassTO newClass = new AnyTypeClassTO();
        newClass.setKey("syncope691" + getUUIDString());
        newClass.getVirSchemas().add(virSchema.getKey());
        Response response = anyTypeClassService.create(newClass);
        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
        newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
        // create a new user
        UserTO userTO = UserITCase.getUniqueSampleTO("syncope691@syncope.apache.org");
        userTO.getAuxClasses().add(newClass.getKey());
        userTO.getResources().clear();
        userTO.getMemberships().clear();
        userTO.getVirAttrs().clear();
        AttrTO emailTO = new AttrTO();
        emailTO.setSchema(virSchema.getKey());
        emailTO.getValues().add("test@issue691.dom1.org");
        emailTO.getValues().add("test@issue691.dom2.org");
        userTO.getVirAttrs().add(emailTO);
        // assign resource-ldap691 to user
        userTO.getResources().add(ldap.getKey());
        // save user
        userTO = createUser(userTO).getEntity();
        // make std controls about user
        assertNotNull(userTO);
        assertTrue(ldap.getKey().equals(userTO.getResources().iterator().next()));
        assertEquals(2, userTO.getVirAttrs().iterator().next().getValues().size());
        assertTrue(userTO.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom1.org"));
        assertTrue(userTO.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom2.org"));
        // update user
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(userTO.getKey());
        // modify virtual attribute
        userPatch.getVirAttrs().add(new AttrTO.Builder().schema(virSchema.getKey()).value("test@issue691.dom3.org").value("test@issue691.dom4.org").build());
        UserTO updated = updateUser(userPatch).getEntity();
        assertNotNull(updated);
        assertEquals(2, updated.getVirAttrs().iterator().next().getValues().size());
        assertTrue(updated.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom3.org"));
        assertTrue(updated.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom4.org"));
    } finally {
        try {
            resourceService.delete(ldap.getKey());
        } catch (Exception ignore) {
        // ignore
        }
    }
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Autowired(org.springframework.beans.factory.annotation.Autowired) SerializationUtils(org.apache.commons.lang3.SerializationUtils) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Locale(java.util.Locale) Map(java.util.Map) DataSource(javax.sql.DataSource) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) StatusPatchType(org.apache.syncope.common.lib.types.StatusPatchType) MappingTO(org.apache.syncope.common.lib.to.MappingTO) SchemaType(org.apache.syncope.common.lib.types.SchemaType) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) List(java.util.List) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) Response(javax.ws.rs.core.Response) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Example 29 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class VirAttrITCase method issueSYNCOPE397.

@Test
public void issueSYNCOPE397() {
    ResourceTO csv = resourceService.read(RESOURCE_NAME_CSV);
    // change mapping of resource-csv
    MappingTO origMapping = SerializationUtils.clone(csv.getProvisions().get(0).getMapping());
    try {
        // remove this mapping
        Optional<ItemTO> email = csv.getProvisions().get(0).getMapping().getItems().stream().filter(item -> "email".equals(item.getIntAttrName())).findFirst();
        if (email.isPresent()) {
            csv.getProvisions().get(0).getMapping().getItems().remove(email.get());
        }
        resourceService.update(csv);
        csv = resourceService.read(RESOURCE_NAME_CSV);
        assertNotNull(csv.getProvisions().get(0).getMapping());
        // create new virtual schema for the resource below
        ProvisionTO provision = csv.getProvision(AnyTypeKind.USER.name()).get();
        assertNotNull(provision);
        VirSchemaTO virSchema = new VirSchemaTO();
        virSchema.setKey("syncope397" + getUUIDString());
        virSchema.setExtAttrName("email");
        virSchema.setResource(RESOURCE_NAME_CSV);
        virSchema.setAnyType(provision.getAnyType());
        virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
        assertNotNull(virSchema);
        AnyTypeClassTO newClass = new AnyTypeClassTO();
        newClass.setKey("syncope397" + getUUIDString());
        newClass.getVirSchemas().add(virSchema.getKey());
        Response response = anyTypeClassService.create(newClass);
        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
        newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
        // create a new user
        UserTO userTO = UserITCase.getUniqueSampleTO("397@syncope.apache.org");
        userTO.getAuxClasses().add("csv");
        userTO.getAuxClasses().add(newClass.getKey());
        userTO.getResources().clear();
        userTO.getMemberships().clear();
        userTO.getVirAttrs().clear();
        userTO.getVirAttrs().add(attrTO(virSchema.getKey(), "test@testone.org"));
        // assign resource-csv to user
        userTO.getResources().add(RESOURCE_NAME_CSV);
        // save user
        userTO = createUser(userTO).getEntity();
        // make std controls about user
        assertNotNull(userTO);
        assertTrue(RESOURCE_NAME_CSV.equals(userTO.getResources().iterator().next()));
        assertEquals("test@testone.org", userTO.getVirAttrs().iterator().next().getValues().get(0));
        // update user
        UserTO toBeUpdated = userService.read(userTO.getKey());
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(toBeUpdated.getKey());
        userPatch.setPassword(new PasswordPatch.Builder().value("password234").build());
        // assign new resource to user
        userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_WS2).build());
        // modify virtual attribute
        userPatch.getVirAttrs().add(attrTO(virSchema.getKey(), "test@testoneone.com"));
        // check Syncope change password
        userPatch.setPassword(new PasswordPatch.Builder().value("password234").onSyncope(true).resource(RESOURCE_NAME_WS2).build());
        ProvisioningResult<UserTO> result = updateUser(userPatch);
        assertNotNull(result);
        toBeUpdated = result.getEntity();
        assertTrue(toBeUpdated.getVirAttrs().iterator().next().getValues().contains("test@testoneone.com"));
        // check if propagates correctly with assertEquals on size of tasks list
        assertEquals(2, result.getPropagationStatuses().size());
    } finally {
        // restore mapping of resource-csv
        csv.getProvisions().get(0).setMapping(origMapping);
        resourceService.update(csv);
    }
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Autowired(org.springframework.beans.factory.annotation.Autowired) SerializationUtils(org.apache.commons.lang3.SerializationUtils) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Locale(java.util.Locale) Map(java.util.Map) DataSource(javax.sql.DataSource) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) StatusPatchType(org.apache.syncope.common.lib.types.StatusPatchType) MappingTO(org.apache.syncope.common.lib.to.MappingTO) SchemaType(org.apache.syncope.common.lib.types.SchemaType) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) List(java.util.List) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) Response(javax.ws.rs.core.Response) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Response(javax.ws.rs.core.Response) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Example 30 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class PullTaskITCase method issueSYNCOPE313LDAP.

@Test
public void issueSYNCOPE313LDAP() throws Exception {
    // First of all, clear any potential conflict with existing user / group
    ldapCleanup();
    UserTO user = null;
    PullTaskTO pullTask = null;
    ConnInstanceTO resourceConnector = null;
    ConnConfProperty property = null;
    try {
        // 1. create user in LDAP
        String oldCleanPassword = "security123";
        user = UserITCase.getUniqueSampleTO("syncope313-ldap@syncope.apache.org");
        user.setPassword(oldCleanPassword);
        user.getResources().add(RESOURCE_NAME_LDAP);
        user = createUser(user).getEntity();
        assertNotNull(user);
        assertFalse(user.getResources().isEmpty());
        // 2. request to change password only on Syncope and not on LDAP
        String newCleanPassword = "new-security123";
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(user.getKey());
        userPatch.setPassword(new PasswordPatch.Builder().value(newCleanPassword).build());
        user = updateUser(userPatch).getEntity();
        // 3. Check that the Syncope user now has the changed password
        Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(user.getUsername(), newCleanPassword).self();
        assertNotNull(self);
        // 4. Check that the LDAP resource has the old password
        ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
        assertNotNull(getLdapRemoteObject(connObject.getAttr(Name.NAME).get().getValues().get(0), oldCleanPassword, connObject.getAttr(Name.NAME).get().getValues().get(0)));
        // 5. Update the LDAP Connector to retrieve passwords
        ResourceTO ldapResource = resourceService.read(RESOURCE_NAME_LDAP);
        resourceConnector = connectorService.read(ldapResource.getConnector(), Locale.ENGLISH.getLanguage());
        property = resourceConnector.getConf("retrievePasswordsWithSearch").get();
        property.getValues().clear();
        property.getValues().add(Boolean.TRUE);
        connectorService.update(resourceConnector);
        // 6. Pull the user from the resource
        ImplementationTO pullActions = new ImplementationTO();
        pullActions.setKey(LDAPPasswordPullActions.class.getSimpleName());
        pullActions.setEngine(ImplementationEngine.JAVA);
        pullActions.setType(ImplementationType.PULL_ACTIONS);
        pullActions.setBody(LDAPPasswordPullActions.class.getName());
        Response response = implementationService.create(pullActions);
        pullActions = implementationService.read(pullActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
        assertNotNull(pullActions);
        pullTask = new PullTaskTO();
        pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
        pullTask.setName("LDAP Pull Task");
        pullTask.setActive(true);
        pullTask.setPerformCreate(true);
        pullTask.setPerformUpdate(true);
        pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
        pullTask.setResource(RESOURCE_NAME_LDAP);
        pullTask.getActions().add(pullActions.getKey());
        Response taskResponse = taskService.create(TaskType.PULL, pullTask);
        pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
        assertNotNull(pullTask);
        ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
        // 7. Test the pulled user
        self = clientFactory.create(user.getUsername(), oldCleanPassword).self();
        assertNotNull(self);
    } catch (Exception e) {
        fail(e.getMessage());
    } finally {
        // Delete PullTask + user + reset the connector
        if (pullTask != null) {
            taskService.delete(TaskType.PULL, pullTask.getKey());
        }
        if (resourceConnector != null && property != null) {
            property.getValues().clear();
            property.getValues().add(Boolean.FALSE);
            connectorService.update(resourceConnector);
        }
        if (user != null) {
            deleteUser(user.getKey());
        }
    }
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) IOException(java.io.IOException) ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) 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) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Map(java.util.Map) LDAPPasswordPullActions(org.apache.syncope.core.provisioning.java.pushpull.LDAPPasswordPullActions) Test(org.junit.jupiter.api.Test)

Aggregations

UserPatch (org.apache.syncope.common.lib.patch.UserPatch)102 UserTO (org.apache.syncope.common.lib.to.UserTO)73 Test (org.junit.jupiter.api.Test)59 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)37 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)18 AttrTO (org.apache.syncope.common.lib.to.AttrTO)17 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 Response (javax.ws.rs.core.Response)16 Map (java.util.Map)12 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)12 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)11 GroupTO (org.apache.syncope.common.lib.to.GroupTO)11 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)11 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)11 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)11 GenericType (javax.ws.rs.core.GenericType)10 Pair (org.apache.commons.lang3.tuple.Pair)10 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)10 List (java.util.List)9 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)9