Search in sources :

Example 1 with PullPolicyTO

use of org.apache.syncope.common.lib.policy.PullPolicyTO in project syncope by apache.

the class PolicyITCase method buildPullPolicyTO.

private PullPolicyTO buildPullPolicyTO() throws IOException {
    ImplementationTO corrRule = null;
    try {
        corrRule = implementationService.read(ImplementationType.PULL_CORRELATION_RULE, "TestPullRule");
    } catch (SyncopeClientException e) {
        if (e.getType().getResponseStatus() == Response.Status.NOT_FOUND) {
            corrRule = new ImplementationTO();
            corrRule.setKey("TestPullRule");
            corrRule.setEngine(ImplementationEngine.GROOVY);
            corrRule.setType(ImplementationType.PULL_CORRELATION_RULE);
            corrRule.setBody(IOUtils.toString(getClass().getResourceAsStream("/TestPullRule.groovy"), StandardCharsets.UTF_8));
            Response response = implementationService.create(corrRule);
            corrRule = implementationService.read(corrRule.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
            assertNotNull(corrRule);
        }
    }
    assertNotNull(corrRule);
    PullPolicyTO policy = new PullPolicyTO();
    policy.getCorrelationRules().put(AnyTypeKind.USER.name(), corrRule.getKey());
    policy.setDescription("Pull policy");
    return policy;
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) PullPolicyTO(org.apache.syncope.common.lib.policy.PullPolicyTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException)

Example 2 with PullPolicyTO

use of org.apache.syncope.common.lib.policy.PullPolicyTO in project syncope by apache.

the class PolicyITCase method create.

@Test
public void create() throws IOException {
    PullPolicyTO policyTO = createPolicy(PolicyType.PULL, buildPullPolicyTO());
    assertNotNull(policyTO);
    assertEquals("TestPullRule", policyTO.getCorrelationRules().get(AnyTypeKind.USER.name()));
}
Also used : PullPolicyTO(org.apache.syncope.common.lib.policy.PullPolicyTO) Test(org.junit.jupiter.api.Test)

Example 3 with PullPolicyTO

use of org.apache.syncope.common.lib.policy.PullPolicyTO in project syncope by apache.

the class PolicyITCase method getPullPolicy.

@Test
public void getPullPolicy() {
    PullPolicyTO policyTO = policyService.read(PolicyType.PULL, "66691e96-285f-4464-bc19-e68384ea4c85");
    assertNotNull(policyTO);
    assertTrue(policyTO.getUsedByRealms().isEmpty());
}
Also used : PullPolicyTO(org.apache.syncope.common.lib.policy.PullPolicyTO) Test(org.junit.jupiter.api.Test)

Example 4 with PullPolicyTO

use of org.apache.syncope.common.lib.policy.PullPolicyTO in project syncope by apache.

the class PolicyITCase method delete.

@Test
public void delete() throws IOException {
    PullPolicyTO policy = buildPullPolicyTO();
    PullPolicyTO policyTO = createPolicy(PolicyType.PULL, policy);
    assertNotNull(policyTO);
    policyService.delete(PolicyType.PULL, policyTO.getKey());
    try {
        policyService.read(PolicyType.PULL, policyTO.getKey());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertNotNull(e);
    }
}
Also used : PullPolicyTO(org.apache.syncope.common.lib.policy.PullPolicyTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 5 with PullPolicyTO

use of org.apache.syncope.common.lib.policy.PullPolicyTO in project syncope by apache.

the class PullTaskITCase method issueSYNCOPE258.

@Test
public void issueSYNCOPE258() throws IOException {
    // -----------------------------
    // Add a custom correlation rule
    // -----------------------------
    ImplementationTO corrRule = null;
    try {
        corrRule = implementationService.read(ImplementationType.PULL_CORRELATION_RULE, "TestPullRule");
    } catch (SyncopeClientException e) {
        if (e.getType().getResponseStatus() == Response.Status.NOT_FOUND) {
            corrRule = new ImplementationTO();
            corrRule.setKey("TestPullRule");
            corrRule.setEngine(ImplementationEngine.GROOVY);
            corrRule.setType(ImplementationType.PULL_CORRELATION_RULE);
            corrRule.setBody(IOUtils.toString(getClass().getResourceAsStream("/TestPullRule.groovy"), StandardCharsets.UTF_8));
            Response response = implementationService.create(corrRule);
            corrRule = implementationService.read(corrRule.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
            assertNotNull(corrRule);
        }
    }
    assertNotNull(corrRule);
    PullPolicyTO policyTO = policyService.read(PolicyType.PULL, "9454b0d7-2610-400a-be82-fc23cf553dd6");
    policyTO.getCorrelationRules().put(AnyTypeKind.USER.name(), corrRule.getKey());
    policyService.update(PolicyType.PULL, policyTO);
    // -----------------------------
    PullTaskTO task = new PullTaskTO();
    task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
    task.setName("Test Pull Rule");
    task.setActive(true);
    task.setResource(RESOURCE_NAME_WS2);
    task.setPullMode(PullMode.FULL_RECONCILIATION);
    task.setPerformCreate(true);
    task.setPerformDelete(true);
    task.setPerformUpdate(true);
    Response response = taskService.create(TaskType.PULL, task);
    task = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
    UserTO userTO = UserITCase.getUniqueSampleTO("s258_1@apache.org");
    userTO.getResources().clear();
    userTO.getResources().add(RESOURCE_NAME_WS2);
    createUser(userTO);
    userTO = UserITCase.getUniqueSampleTO("s258_2@apache.org");
    userTO.getResources().clear();
    userTO.getResources().add(RESOURCE_NAME_WS2);
    userTO = createUser(userTO).getEntity();
    // change email in order to unmatch the second user
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("email", "s258@apache.org"));
    userService.update(userPatch);
    execProvisioningTask(taskService, TaskType.PULL, task.getKey(), 50, false);
    PullTaskTO executed = taskService.read(TaskType.PULL, task.getKey(), true);
    assertEquals(1, executed.getExecutions().size());
    // asser for just one match
    assertTrue(executed.getExecutions().get(0).getMessage().contains("[updated/failures]: 1/0"), executed.getExecutions().get(0).getMessage().substring(0, 55) + "...");
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) PullPolicyTO(org.apache.syncope.common.lib.policy.PullPolicyTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Aggregations

PullPolicyTO (org.apache.syncope.common.lib.policy.PullPolicyTO)7 Test (org.junit.jupiter.api.Test)4 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3 Response (javax.ws.rs.core.Response)2 AccountPolicyTO (org.apache.syncope.common.lib.policy.AccountPolicyTO)2 PasswordPolicyTO (org.apache.syncope.common.lib.policy.PasswordPolicyTO)2 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)2 Entity (org.apache.syncope.core.persistence.api.entity.Entity)2 Realm (org.apache.syncope.core.persistence.api.entity.Realm)2 AccountPolicy (org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy)2 PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)2 PullPolicy (org.apache.syncope.core.persistence.api.entity.policy.PullPolicy)2 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)2 Collectors (java.util.stream.Collectors)1 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)1 PolicyTO (org.apache.syncope.common.lib.policy.PolicyTO)1 PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)1 UserTO (org.apache.syncope.common.lib.to.UserTO)1 TaskService (org.apache.syncope.common.rest.api.service.TaskService)1 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)1