Search in sources :

Example 6 with ImplementationTO

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

the class NotificationTaskITCase method issueSYNCOPE446.

@Test
public void issueSYNCOPE446() throws Exception {
    // 1. Create notification
    ImplementationTO recipientsProvider = new ImplementationTO();
    recipientsProvider.setKey(TestNotificationRecipientsProvider.class.getSimpleName());
    recipientsProvider.setEngine(ImplementationEngine.JAVA);
    recipientsProvider.setType(ImplementationType.RECIPIENTS_PROVIDER);
    recipientsProvider.setBody(TestNotificationRecipientsProvider.class.getName());
    Response response = implementationService.create(recipientsProvider);
    recipientsProvider = implementationService.read(recipientsProvider.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
    assertNotNull(recipientsProvider);
    NotificationTO notification = new NotificationTO();
    notification.setTraceLevel(TraceLevel.ALL);
    notification.getEvents().add("[LOGIC]:[GroupLogic]:[]:[create]:[SUCCESS]");
    String groupName = "group" + getUUIDString();
    notification.getAbouts().put(AnyTypeKind.GROUP.name(), SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo(groupName).query());
    notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
    notification.setSelfAsRecipient(false);
    notification.setRecipientAttrName("email");
    notification.getStaticRecipients().add("notificationtest@syncope.apache.org");
    notification.setRecipientsProvider(recipientsProvider.getKey());
    String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
    notification.setSender(sender);
    String subject = "Test notification " + getUUIDString();
    notification.setSubject(subject);
    notification.setTemplate("optin");
    notification.setActive(true);
    response = notificationService.create(notification);
    notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
    assertNotNull(notification);
    assertEquals(recipientsProvider.getKey(), notification.getRecipientsProvider());
    // 2. create group
    GroupTO groupTO = new GroupTO();
    groupTO.setName(groupName);
    groupTO.setRealm("/even/two");
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    // 3. verify
    NotificationTaskTO taskTO = findNotificationTask(notification.getKey(), 50);
    assertNotNull(taskTO);
    assertNotNull(taskTO.getNotification());
    assertTrue(taskTO.getRecipients().containsAll(new TestNotificationRecipientsProvider().provideRecipients(null)));
    NotificationTaskTO foundViaList = taskService.<NotificationTaskTO>search(new TaskQuery.Builder(TaskType.NOTIFICATION).notification(notification.getKey()).build()).getResult().get(0);
    assertEquals(taskTO, foundViaList);
    execNotificationTask(taskService, taskTO.getKey(), 50);
    assertTrue(verifyMail(sender, subject, "notificationtest@syncope.apache.org"));
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) NotificationTO(org.apache.syncope.common.lib.to.NotificationTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) NotificationService(org.apache.syncope.common.rest.api.service.NotificationService) TestNotificationRecipientsProvider(org.apache.syncope.fit.core.reference.TestNotificationRecipientsProvider) GroupTO(org.apache.syncope.common.lib.to.GroupTO) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) Test(org.junit.jupiter.api.Test)

Example 7 with ImplementationTO

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

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

the class PolicyITCase method update.

@Test
public void update() {
    PasswordPolicyTO globalPolicy = policyService.read(PolicyType.PASSWORD, "ce93fcda-dc3a-4369-a7b0-a6108c261c85");
    PasswordPolicyTO policy = SerializationUtils.clone(globalPolicy);
    policy.setDescription("A simple password policy");
    // create a new password policy using the former as a template
    policy = createPolicy(PolicyType.PASSWORD, policy);
    assertNotNull(policy);
    assertNotEquals("ce93fcda-dc3a-4369-a7b0-a6108c261c85", policy.getKey());
    ImplementationTO rule = implementationService.read(ImplementationType.PASSWORD_RULE, policy.getRules().get(0));
    assertNotNull(rule);
    DefaultPasswordRuleConf ruleConf = POJOHelper.deserialize(rule.getBody(), DefaultPasswordRuleConf.class);
    ruleConf.setMaxLength(22);
    rule.setBody(POJOHelper.serialize(ruleConf));
    // update new password policy
    policyService.update(PolicyType.PASSWORD, policy);
    policy = policyService.read(PolicyType.PASSWORD, policy.getKey());
    assertNotNull(policy);
    ruleConf = POJOHelper.deserialize(rule.getBody(), DefaultPasswordRuleConf.class);
    assertEquals(22, ruleConf.getMaxLength());
    assertEquals(8, ruleConf.getMinLength());
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) DefaultPasswordRuleConf(org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf) PasswordPolicyTO(org.apache.syncope.common.lib.policy.PasswordPolicyTO) Test(org.junit.jupiter.api.Test)

Example 9 with ImplementationTO

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

Example 10 with ImplementationTO

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

the class PullTaskITCase method testPullActionsSetup.

@BeforeAll
public static void testPullActionsSetup() {
    ImplementationTO pullActions = null;
    try {
        pullActions = implementationService.read(ImplementationType.PULL_ACTIONS, TestPullActions.class.getSimpleName());
    } catch (SyncopeClientException e) {
        if (e.getType().getResponseStatus() == Response.Status.NOT_FOUND) {
            pullActions = new ImplementationTO();
            pullActions.setKey(TestPullActions.class.getSimpleName());
            pullActions.setEngine(ImplementationEngine.JAVA);
            pullActions.setType(ImplementationType.PULL_ACTIONS);
            pullActions.setBody(TestPullActions.class.getName());
            Response response = implementationService.create(pullActions);
            pullActions = implementationService.read(pullActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
            assertNotNull(pullActions);
        }
    }
    assertNotNull(pullActions);
    PullTaskTO pullTask = taskService.read(TaskType.PULL, PULL_TASK_KEY, true);
    pullTask.getActions().add(pullActions.getKey());
    taskService.update(TaskType.PULL, pullTask);
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) BeforeAll(org.junit.jupiter.api.BeforeAll)

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