Search in sources :

Example 1 with PropagationTaskTO

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

the class UserITCase method createUserWithNoPropagation.

@Test
public void createUserWithNoPropagation() {
    // create a new user
    UserTO userTO = getUniqueSampleTO("xxx@xxx.xxx");
    userTO.setPassword("password123");
    userTO.getResources().add(RESOURCE_NAME_NOPROPAGATION);
    userTO = createUser(userTO).getEntity();
    // get the propagation task just created
    PagedResult<PropagationTaskTO> tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).anyTypeKind(AnyTypeKind.USER).entityKey(userTO.getKey()).page(1).size(1).build());
    assertNotNull(tasks);
    assertFalse(tasks.getResult().isEmpty());
    PropagationTaskTO taskTO = tasks.getResult().get(0);
    assertNotNull(taskTO);
    assertFalse(taskTO.getExecutions().isEmpty());
    assertEquals(PropagationTaskExecStatus.NOT_ATTEMPTED.name(), taskTO.getExecutions().get(0).getStatus());
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) UserTO(org.apache.syncope.common.lib.to.UserTO) Test(org.junit.jupiter.api.Test)

Example 2 with PropagationTaskTO

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

the class UserITCase method verifyTaskRegistration.

@SuppressWarnings("unchecked")
@Test
public void verifyTaskRegistration() {
    // get task list
    PagedResult<PropagationTaskTO> tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
    assertNotNull(tasks);
    assertFalse(tasks.getResult().isEmpty());
    String maxKey = tasks.getResult().iterator().next().getKey();
    // --------------------------------------
    // Create operation
    // --------------------------------------
    UserTO userTO = getUniqueSampleTO("t@p.mode");
    // add a membership
    userTO.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
    // 1. create user
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    // get the new task list
    tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
    assertNotNull(tasks);
    assertFalse(tasks.getResult().isEmpty());
    String newMaxKey = tasks.getResult().iterator().next().getKey();
    // default configuration for ws-target-resource2 during create:
    // only failed executions have to be registered
    // --> no more tasks/executions should be added
    assertEquals(newMaxKey, maxKey);
    // --------------------------------------
    // Update operation
    // --------------------------------------
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "surname2"));
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    // get the new task list
    tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
    // default configuration for ws-target-resource2 during update:
    // all update executions have to be registered
    newMaxKey = tasks.getResult().iterator().next().getKey();
    PropagationTaskTO taskTO = taskService.read(TaskType.PROPAGATION, newMaxKey, true);
    assertNotNull(taskTO);
    assertEquals(1, taskTO.getExecutions().size());
    // --------------------------------------
    // Delete operation
    // --------------------------------------
    userService.delete(userTO.getKey());
    // get the new task list
    tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
    maxKey = newMaxKey;
    newMaxKey = tasks.getResult().iterator().next().getKey();
    // default configuration for ws-target-resource2: no delete executions have to be registered
    // --> no more tasks/executions should be added
    assertEquals(newMaxKey, maxKey);
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) UserTO(org.apache.syncope.common.lib.to.UserTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 3 with PropagationTaskTO

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

the class UserITCase method create.

@Test
public void create() {
    // get task list
    PagedResult<PropagationTaskTO> tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
    assertNotNull(tasks);
    assertFalse(tasks.getResult().isEmpty());
    String maxKey = tasks.getResult().iterator().next().getKey();
    PropagationTaskTO taskTO = taskService.read(TaskType.PROPAGATION, maxKey, true);
    assertNotNull(taskTO);
    int maxTaskExecutions = taskTO.getExecutions().size();
    UserTO userTO = getUniqueSampleTO("a.b@c.com");
    // add a membership
    userTO.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
    // add an attribute with a non-existing schema: must be ignored
    AttrTO attrWithInvalidSchemaTO = attrTO("invalid schema", "a value");
    userTO.getPlainAttrs().add(attrWithInvalidSchemaTO);
    // add an attribute with null value: must be ignored
    userTO.getPlainAttrs().add(attrTO("activationDate", null));
    // 1. create user
    UserTO newUserTO = createUser(userTO).getEntity();
    assertNotNull(newUserTO);
    // issue SYNCOPE-15
    assertNotNull(newUserTO.getCreationDate());
    assertNotNull(newUserTO.getCreator());
    assertNotNull(newUserTO.getLastChangeDate());
    assertNotNull(newUserTO.getLastModifier());
    assertEquals(newUserTO.getCreationDate(), newUserTO.getLastChangeDate());
    assertFalse(newUserTO.getPlainAttrs().contains(attrWithInvalidSchemaTO));
    // check for changePwdDate
    assertNotNull(newUserTO.getCreationDate());
    // get the new task list
    tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
    assertNotNull(tasks);
    assertFalse(tasks.getResult().isEmpty());
    String newMaxKey = tasks.getResult().iterator().next().getKey();
    // default configuration for ws-target-resource2:
    // only failed executions have to be registered
    // --> no more tasks/executions should be added
    assertEquals(newMaxKey, maxKey);
    // get last task
    taskTO = taskService.read(TaskType.PROPAGATION, newMaxKey, true);
    assertNotNull(taskTO);
    assertEquals(maxTaskExecutions, taskTO.getExecutions().size());
    // 3. verify password
    try {
        Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(newUserTO.getUsername(), "password123").self();
        assertNotNull(self);
    } catch (AccessControlException e) {
        fail("Credentials should be valid and not cause AccessControlException");
    }
    try {
        clientFactory.create(newUserTO.getUsername(), "passwordXX").getService(UserSelfService.class);
        fail("Credentials are invalid, thus request should raise AccessControlException");
    } catch (AccessControlException e) {
        assertNotNull(e);
    }
    // 4. try (and fail) to create another user with same (unique) values
    userTO = getSampleTO(userTO.getUsername());
    AttrTO userIdAttr = userTO.getPlainAttr("userId").get();
    userIdAttr.getValues().clear();
    userIdAttr.getValues().add("a.b@c.com");
    try {
        createUser(userTO);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.EntityExists, e.getType());
    }
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AccessControlException(java.security.AccessControlException) UserTO(org.apache.syncope.common.lib.to.UserTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 4 with PropagationTaskTO

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

the class PropagationTaskITCase method issueSYNCOPE741.

@Test
public void issueSYNCOPE741() {
    for (int i = 0; i < 3; i++) {
        taskService.execute(new ExecuteQuery.Builder().key("1e697572-b896-484c-ae7f-0c8f63fcbc6c").build());
        taskService.execute(new ExecuteQuery.Builder().key("316285cc-ae52-4ea2-a33b-7355e189ac3f").build());
    }
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
    // ignore
    }
    // check list
    PagedResult<TaskTO> tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(2).details(false).build());
    for (TaskTO item : tasks.getResult()) {
        assertTrue(item.getExecutions().isEmpty());
    }
    tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(2).details(true).build());
    for (TaskTO item : tasks.getResult()) {
        assertFalse(item.getExecutions().isEmpty());
    }
    // check read
    PropagationTaskTO task = taskService.read(TaskType.PROPAGATION, "1e697572-b896-484c-ae7f-0c8f63fcbc6c", false);
    assertNotNull(task);
    assertEquals("1e697572-b896-484c-ae7f-0c8f63fcbc6c", task.getKey());
    assertTrue(task.getExecutions().isEmpty());
    task = taskService.read(TaskType.PROPAGATION, "1e697572-b896-484c-ae7f-0c8f63fcbc6c", true);
    assertNotNull(task);
    assertEquals("1e697572-b896-484c-ae7f-0c8f63fcbc6c", task.getKey());
    assertFalse(task.getExecutions().isEmpty());
    // check list executions
    PagedResult<ExecTO> execs = taskService.listExecutions(new ExecQuery.Builder().key("1e697572-b896-484c-ae7f-0c8f63fcbc6c").page(1).size(2).build());
    assertTrue(execs.getTotalCount() >= execs.getResult().size());
}
Also used : TaskTO(org.apache.syncope.common.lib.to.TaskTO) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) ExecTO(org.apache.syncope.common.lib.to.ExecTO) ExecQuery(org.apache.syncope.common.rest.api.beans.ExecQuery) ExecuteQuery(org.apache.syncope.common.rest.api.beans.ExecuteQuery) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) Test(org.junit.jupiter.api.Test)

Example 5 with PropagationTaskTO

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

the class CreateProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
        Object actual = exchange.getProperty("actual");
        Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
        Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
        if (actual instanceof UserTO) {
            WorkflowResult<Pair<String, Boolean>> created = (WorkflowResult<Pair<String, Boolean>>) exchange.getIn().getBody();
            List<PropagationTaskTO> tasks = getPropagationManager().getUserCreateTasks(created.getResult().getKey(), ((UserTO) actual).getPassword(), created.getResult().getValue(), created.getPropByRes(), ((UserTO) actual).getVirAttrs(), excludedResources);
            PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
            exchange.getOut().setBody(Pair.of(created.getResult().getKey(), propagationReporter.getStatuses()));
        } else if (actual instanceof AnyTO) {
            WorkflowResult<String> created = (WorkflowResult<String>) exchange.getIn().getBody();
            if (actual instanceof GroupTO && isPull()) {
                Map<String, String> groupOwnerMap = exchange.getProperty("groupOwnerMap", Map.class);
                Optional<AttrTO> groupOwner = ((GroupTO) actual).getPlainAttr(StringUtils.EMPTY);
                if (groupOwner.isPresent()) {
                    groupOwnerMap.put(created.getResult(), groupOwner.get().getValues().iterator().next());
                }
                List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
                getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(Pair.of(created.getResult(), null));
            } else {
                List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(actual instanceof AnyObjectTO ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
                PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(Pair.of(created.getResult(), propagationReporter.getStatuses()));
            }
        }
    }
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) Optional(java.util.Optional) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) UserTO(org.apache.syncope.common.lib.to.UserTO) List(java.util.List) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)48 PropagationReporter (org.apache.syncope.core.provisioning.api.propagation.PropagationReporter)29 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)21 Transactional (org.springframework.transaction.annotation.Transactional)11 Pair (org.apache.commons.lang3.tuple.Pair)10 ArrayList (java.util.ArrayList)9 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)9 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)9 List (java.util.List)8 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)8 Map (java.util.Map)7 Test (org.junit.jupiter.api.Test)7 RealmTO (org.apache.syncope.common.lib.to.RealmTO)6 Realm (org.apache.syncope.core.persistence.api.entity.Realm)6 HashSet (java.util.HashSet)5 Collectors (java.util.stream.Collectors)5 UserTO (org.apache.syncope.common.lib.to.UserTO)5 TaskQuery (org.apache.syncope.common.rest.api.beans.TaskQuery)5 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)5