Search in sources :

Example 46 with GroupTO

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

the class PullTaskITCase method issueSYNCOPE1062.

@Test
public void issueSYNCOPE1062() {
    GroupTO propagationGroup = null;
    PullTaskTO pullTask = null;
    UserTO user = null;
    GroupTO group = null;
    try {
        // 1. create group with resource for propagation
        propagationGroup = GroupITCase.getBasicSampleTO("SYNCOPE1062");
        propagationGroup.getResources().add(RESOURCE_NAME_DBPULL);
        propagationGroup = createGroup(propagationGroup).getEntity();
        // 2. create pull task for another resource, with user template assigning the group above
        pullTask = new PullTaskTO();
        pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
        pullTask.setName("SYNCOPE1062");
        pullTask.setActive(true);
        pullTask.setPerformCreate(true);
        pullTask.setPerformUpdate(true);
        pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
        pullTask.setResource(RESOURCE_NAME_LDAP);
        UserTO template = new UserTO();
        template.getAuxClasses().add("minimal group");
        template.getMemberships().add(new MembershipTO.Builder().group(propagationGroup.getKey()).build());
        template.getPlainAttrs().add(attrTO("firstname", "'fixed'"));
        pullTask.getTemplates().put(AnyTypeKind.USER.name(), template);
        Response taskResponse = taskService.create(TaskType.PULL, pullTask);
        pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
        assertNotNull(pullTask);
        assertFalse(pullTask.getTemplates().isEmpty());
        // 3. exec the pull task
        ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
        // the user is successfully pulled...
        user = userService.read("pullFromLDAP");
        assertNotNull(user);
        assertEquals("pullFromLDAP@syncope.apache.org", user.getPlainAttr("email").get().getValues().get(0));
        group = groupService.read("testLDAPGroup");
        assertNotNull(group);
        ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
        assertNotNull(connObject);
        assertEquals("pullFromLDAP@syncope.apache.org", connObject.getAttr("mail").get().getValues().get(0));
        AttrTO userDn = connObject.getAttr(Name.NAME).get();
        assertNotNull(userDn);
        assertEquals(1, userDn.getValues().size());
        assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, userDn.getValues().get(0)));
        // ...and propagated
        PagedResult<TaskTO> propagationTasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).resource(RESOURCE_NAME_DBPULL).anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
        assertEquals(1, propagationTasks.getSize());
        // 4. update the user on the external resource
        updateLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, userDn.getValues().get(0), Pair.of("mail", "pullFromLDAP2@syncope.apache.org"));
        connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
        assertNotNull(connObject);
        assertEquals("pullFromLDAP2@syncope.apache.org", connObject.getAttr("mail").get().getValues().get(0));
        // 5. exec the pull task again
        execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
        // the internal is updated...
        user = userService.read("pullFromLDAP");
        assertNotNull(user);
        assertEquals("pullFromLDAP2@syncope.apache.org", user.getPlainAttr("email").get().getValues().get(0));
        // ...and propagated
        propagationTasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).resource(RESOURCE_NAME_DBPULL).anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
        assertEquals(2, propagationTasks.getSize());
    } catch (Exception e) {
        LOG.error("Unexpected during issueSYNCOPE1062()", e);
        fail(e.getMessage());
    } finally {
        if (pullTask != null) {
            taskService.delete(TaskType.PULL, pullTask.getKey());
        }
        if (propagationGroup != null) {
            groupService.delete(propagationGroup.getKey());
        }
        if (group != null) {
            groupService.delete(group.getKey());
        }
        if (user != null) {
            userService.delete(user.getKey());
        }
    }
}
Also used : TaskTO(org.apache.syncope.common.lib.to.TaskTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) IOException(java.io.IOException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Response(javax.ws.rs.core.Response) 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) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Example 47 with GroupTO

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

the class PullTaskITCase method create.

@Test
public void create() {
    PullTaskTO task = new PullTaskTO();
    task.setName("Test create Pull");
    task.setDestinationRealm("/");
    task.setResource(RESOURCE_NAME_WS2);
    task.setPullMode(PullMode.FULL_RECONCILIATION);
    UserTO userTemplate = new UserTO();
    userTemplate.getResources().add(RESOURCE_NAME_WS2);
    userTemplate.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
    task.getTemplates().put(AnyTypeKind.USER.name(), userTemplate);
    GroupTO groupTemplate = new GroupTO();
    groupTemplate.getResources().add(RESOURCE_NAME_LDAP);
    task.getTemplates().put(AnyTypeKind.GROUP.name(), groupTemplate);
    Response response = taskService.create(TaskType.PULL, task);
    PullTaskTO actual = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
    assertNotNull(actual);
    task = taskService.read(TaskType.PULL, actual.getKey(), true);
    assertNotNull(task);
    assertEquals(actual.getKey(), task.getKey());
    assertEquals(actual.getJobDelegate(), task.getJobDelegate());
    assertEquals(userTemplate, task.getTemplates().get(AnyTypeKind.USER.name()));
    assertEquals(groupTemplate, task.getTemplates().get(AnyTypeKind.GROUP.name()));
}
Also used : Response(javax.ws.rs.core.Response) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 48 with GroupTO

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

the class GroupReportlet method doExtract.

private void doExtract(final ContentHandler handler, final List<Group> groups) throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    for (Group group : groups) {
        atts.clear();
        for (Feature feature : conf.getFeatures()) {
            String type = null;
            String value = null;
            switch(feature) {
                case key:
                    type = ReportXMLConst.XSD_STRING;
                    value = group.getKey();
                    break;
                case name:
                    type = ReportXMLConst.XSD_STRING;
                    value = String.valueOf(group.getName());
                    break;
                case groupOwner:
                    type = ReportXMLConst.XSD_STRING;
                    value = group.getGroupOwner().getKey();
                    break;
                case userOwner:
                    type = ReportXMLConst.XSD_STRING;
                    value = group.getUserOwner().getKey();
                    break;
                default:
            }
            if (type != null && value != null) {
                atts.addAttribute("", "", feature.name(), type, value);
            }
        }
        handler.startElement("", "", "group", atts);
        // Using GroupTO for attribute values, since the conversion logic of
        // values to String is already encapsulated there
        GroupTO groupTO = groupDataBinder.getGroupTO(group, true);
        doExtractAttributes(handler, groupTO, conf.getPlainAttrs(), conf.getDerAttrs(), conf.getVirAttrs());
        // to get resources associated to a group
        if (conf.getFeatures().contains(Feature.resources)) {
            doExtractResources(handler, groupTO);
        }
        // to get users asscoiated to a group is preferred GroupDAO to GroupTO
        if (conf.getFeatures().contains(Feature.users)) {
            handler.startElement("", "", "users", null);
            for (UMembership memb : groupDAO.findUMemberships(group)) {
                atts.clear();
                atts.addAttribute("", "", "key", ReportXMLConst.XSD_STRING, memb.getLeftEnd().getKey());
                atts.addAttribute("", "", "username", ReportXMLConst.XSD_STRING, String.valueOf(memb.getLeftEnd().getUsername()));
                handler.startElement("", "", "user", atts);
                handler.endElement("", "", "user");
            }
            handler.endElement("", "", "users");
        }
        handler.endElement("", "", "group");
    }
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) AttributesImpl(org.xml.sax.helpers.AttributesImpl) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) Feature(org.apache.syncope.common.lib.report.GroupReportletConf.Feature) GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 49 with GroupTO

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

the class SearchITCase method searchByDynGroup.

@Test
public void searchByDynGroup() {
    GroupTO group = GroupITCase.getBasicSampleTO("dynMembership");
    group.setUDynMembershipCond("cool==true");
    group = createGroup(group).getEntity();
    assertNotNull(group);
    if (ElasticsearchDetector.isElasticSearchEnabled(syncopeService)) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException ex) {
        // ignore
        }
    }
    PagedResult<UserTO> matchingUsers = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().inGroups(group.getKey()).query()).build());
    assertNotNull(matchingUsers);
    assertFalse(matchingUsers.getResult().isEmpty());
    assertTrue(matchingUsers.getResult().stream().anyMatch(user -> "c9b2dec2-00a7-4855-97c0-d854842b4b24".equals(user.getKey())));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ElasticsearchDetector(org.apache.syncope.fit.ElasticsearchDetector) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) RoleTO(org.apache.syncope.common.lib.to.RoleTO) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) PagedResult(org.apache.syncope.common.lib.to.PagedResult) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) RoleService(org.apache.syncope.common.rest.api.service.RoleService) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) Response(javax.ws.rs.core.Response) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) UserTO(org.apache.syncope.common.lib.to.UserTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 50 with GroupTO

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

the class PullTaskITCase method reconcileFromLDAP.

@Test
public void reconcileFromLDAP() {
    // First of all, clear any potential conflict with existing user / group
    ldapCleanup();
    // 0. pull
    ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, "1e419ca4-ea81-4493-a14f-28b90113686d", 50, false);
    // 1. verify execution status
    assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
    // 2. verify that pulled group is found
    PagedResult<GroupTO> matchingGroups = groupService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo("testLDAPGroup").query()).build());
    assertNotNull(matchingGroups);
    assertEquals(1, matchingGroups.getResult().size());
    // SYNCOPE-898
    PullTaskTO task = taskService.read(TaskType.PULL, "1e419ca4-ea81-4493-a14f-28b90113686d", false);
    assertEquals("/", task.getDestinationRealm());
    assertEquals("/", matchingGroups.getResult().get(0).getRealm());
    // 3. verify that pulled user is found
    PagedResult<UserTO> matchingUsers = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").query()).build());
    assertNotNull(matchingUsers);
    assertEquals(1, matchingUsers.getResult().size());
    // SYNCOPE-898
    assertEquals("/odd", matchingUsers.getResult().get(0).getRealm());
    // Check for SYNCOPE-436
    assertEquals("pullFromLDAP", matchingUsers.getResult().get(0).getVirAttr("virtualReadOnly").get().getValues().get(0));
    // Check for SYNCOPE-270
    assertNotNull(matchingUsers.getResult().get(0).getPlainAttr("obscure"));
    // Check for SYNCOPE-123
    assertNotNull(matchingUsers.getResult().get(0).getPlainAttr("photo"));
    GroupTO groupTO = matchingGroups.getResult().iterator().next();
    assertNotNull(groupTO);
    assertEquals("testLDAPGroup", groupTO.getName());
    assertEquals("true", groupTO.getPlainAttr("show").get().getValues().get(0));
    assertEquals(matchingUsers.getResult().iterator().next().getKey(), groupTO.getUserOwner());
    assertNull(groupTO.getGroupOwner());
    // SYNCOPE-317
    execProvisioningTask(taskService, TaskType.PULL, "1e419ca4-ea81-4493-a14f-28b90113686d", 50, false);
    // 4. verify that LDAP group membership is propagated as Syncope membership
    int i = 0;
    int maxit = 50;
    PagedResult<UserTO> members;
    do {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        members = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().inGroups(groupTO.getKey()).query()).build());
        assertNotNull(members);
        i++;
    } while (members.getResult().isEmpty() && i < maxit);
    if (i == maxit) {
        fail("Timeout while checking for memberships of " + groupTO.getName());
    }
    assertEquals(1, members.getResult().size());
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) UserTO(org.apache.syncope.common.lib.to.UserTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Aggregations

GroupTO (org.apache.syncope.common.lib.to.GroupTO)90 Test (org.junit.jupiter.api.Test)47 UserTO (org.apache.syncope.common.lib.to.UserTO)34 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)27 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)23 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)16 List (java.util.List)15 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)14 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)14 Response (javax.ws.rs.core.Response)13 NamingException (javax.naming.NamingException)12 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 Map (java.util.Map)11 ForbiddenException (javax.ws.rs.ForbiddenException)11 AccessControlException (java.security.AccessControlException)10 BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Collections (java.util.Collections)9