Search in sources :

Example 11 with ImplementationTO

use of org.apache.syncope.common.lib.to.ImplementationTO 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)

Example 12 with ImplementationTO

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

the class RealmITCase method deletingAccountPolicy.

@Test
public void deletingAccountPolicy() {
    // 1. create account policy
    DefaultAccountRuleConf ruleConf = new DefaultAccountRuleConf();
    ruleConf.setMinLength(3);
    ruleConf.setMaxLength(8);
    ImplementationTO rule = new ImplementationTO();
    rule.setKey("DefaultAccountRuleConf" + UUID.randomUUID().toString());
    rule.setEngine(ImplementationEngine.JAVA);
    rule.setType(ImplementationType.ACCOUNT_RULE);
    rule.setBody(POJOHelper.serialize(ruleConf));
    Response response = implementationService.create(rule);
    rule.setKey(response.getHeaderString(RESTHeaders.RESOURCE_KEY));
    AccountPolicyTO policy = new AccountPolicyTO();
    policy.setDescription("deletingAccountPolicy");
    policy.getRules().add(rule.getKey());
    policy = createPolicy(PolicyType.ACCOUNT, policy);
    assertNotNull(policy);
    // 2. create realm with policy assigned
    RealmTO realm = new RealmTO();
    realm.setName("withppolicy");
    response = realmService.create(SyncopeConstants.ROOT_REALM, realm);
    RealmTO[] actuals = getObject(response.getLocation(), RealmService.class, RealmTO[].class);
    assertNotNull(actuals);
    assertTrue(actuals.length > 0);
    realm = actuals[0];
    String existingAccountPolicy = realm.getAccountPolicy();
    realm.setAccountPolicy(policy.getKey());
    realmService.update(realm);
    actuals = getObject(response.getLocation(), RealmService.class, RealmTO[].class);
    assertNotNull(actuals);
    assertTrue(actuals.length > 0);
    RealmTO actual = actuals[0];
    assertEquals(policy.getKey(), actual.getAccountPolicy());
    // 3. remove policy
    policyService.delete(PolicyType.ACCOUNT, policy.getKey());
    // 4. verify
    actual = getRealm(actual.getFullPath()).get();
    assertEquals(existingAccountPolicy, actual.getAccountPolicy());
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) DefaultAccountRuleConf(org.apache.syncope.common.lib.policy.DefaultAccountRuleConf) RealmService(org.apache.syncope.common.rest.api.service.RealmService) RealmTO(org.apache.syncope.common.lib.to.RealmTO) AccountPolicyTO(org.apache.syncope.common.lib.policy.AccountPolicyTO) Test(org.junit.jupiter.api.Test)

Example 13 with ImplementationTO

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

the class ImplementationDataBinderImpl method getImplementationTO.

@Override
public ImplementationTO getImplementationTO(final Implementation implementation) {
    ImplementationTO implementationTO = new ImplementationTO();
    BeanUtils.copyProperties(implementation, implementationTO);
    return implementationTO;
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO)

Example 14 with ImplementationTO

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

the class ReportletWizardBuilder method onApplyInternal.

@Override
protected Serializable onApplyInternal(final ReportletWrapper modelObject) {
    if (modelObject.getImplementationEngine() == ImplementationEngine.JAVA) {
        ImplementationTO reportlet = implementationClient.read(ImplementationType.REPORTLET, modelObject.getImplementationKey());
        try {
            reportlet.setBody(MAPPER.writeValueAsString(modelObject.getConf()));
            implementationClient.update(reportlet);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    ReportTO reportTO = restClient.read(report);
    if (modelObject.isNew()) {
        reportTO.getReportlets().add(modelObject.getImplementationKey());
    }
    restClient.update(reportTO);
    return modelObject;
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) ReportTO(org.apache.syncope.common.lib.to.ReportTO)

Example 15 with ImplementationTO

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

the class PolicyRuleWizardBuilder method onApplyInternal.

@Override
protected Serializable onApplyInternal(final PolicyRuleWrapper modelObject) {
    PolicyTO policyTO = restClient.getPolicy(type, policy);
    ComposablePolicy composable;
    if (policyTO instanceof ComposablePolicy) {
        composable = (ComposablePolicy) policyTO;
    } else {
        throw new IllegalStateException("Non composable policy");
    }
    if (modelObject.getImplementationEngine() == ImplementationEngine.JAVA) {
        ImplementationTO rule = implementationClient.read(implementationType, modelObject.getImplementationKey());
        try {
            rule.setBody(MAPPER.writeValueAsString(modelObject.getConf()));
            implementationClient.update(rule);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    if (modelObject.isNew()) {
        composable.getRules().add(modelObject.getImplementationKey());
    }
    restClient.updatePolicy(type, policyTO);
    return modelObject;
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) ComposablePolicy(org.apache.syncope.common.lib.policy.ComposablePolicy) PolicyTO(org.apache.syncope.common.lib.policy.PolicyTO)

Aggregations

ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)30 Response (javax.ws.rs.core.Response)24 Test (org.junit.jupiter.api.Test)24 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)10 UserTO (org.apache.syncope.common.lib.to.UserTO)9 PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)7 TaskService (org.apache.syncope.common.rest.api.service.TaskService)6 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)5 ReportTO (org.apache.syncope.common.lib.to.ReportTO)5 AccountPolicyTO (org.apache.syncope.common.lib.policy.AccountPolicyTO)4 ExecTO (org.apache.syncope.common.lib.to.ExecTO)4 RealmTO (org.apache.syncope.common.lib.to.RealmTO)4 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)4 DefaultAccountRuleConf (org.apache.syncope.common.lib.policy.DefaultAccountRuleConf)3 PasswordPolicyTO (org.apache.syncope.common.lib.policy.PasswordPolicyTO)3 UserReportletConf (org.apache.syncope.common.lib.report.UserReportletConf)3 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)3 SchedTaskTO (org.apache.syncope.common.lib.to.SchedTaskTO)3 TestSampleJobDelegate (org.apache.syncope.fit.core.reference.TestSampleJobDelegate)3 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)3