Search in sources :

Example 11 with GroupTO

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

the class VirAttrITCase method issueSYNCOPE453.

@Test
public void issueSYNCOPE453() {
    String resourceName = "issueSYNCOPE453Res" + getUUIDString();
    String groupKey = null;
    String groupName = "issueSYNCOPE453Group" + getUUIDString();
    try {
        // -------------------------------------------
        // Create a VirAttrITCase ad-hoc
        // -------------------------------------------
        VirSchemaTO rvirtualdata;
        try {
            rvirtualdata = schemaService.read(SchemaType.VIRTUAL, "rvirtualdata");
        } catch (SyncopeClientException e) {
            LOG.warn("rvirtualdata not found, re-creating", e);
            rvirtualdata = new VirSchemaTO();
            rvirtualdata.setKey("rvirtualdata");
            rvirtualdata.setExtAttrName("businessCategory");
            rvirtualdata.setResource(RESOURCE_NAME_LDAP);
            rvirtualdata.setAnyType(AnyTypeKind.GROUP.name());
            rvirtualdata = createSchema(SchemaType.VIRTUAL, rvirtualdata);
        }
        assertNotNull(rvirtualdata);
        if (!"minimal group".equals(rvirtualdata.getAnyTypeClass())) {
            LOG.warn("rvirtualdata not in minimal group, restoring");
            AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
            minimalGroup.getVirSchemas().add(rvirtualdata.getKey());
            anyTypeClassService.update(minimalGroup);
            rvirtualdata = schemaService.read(SchemaType.VIRTUAL, rvirtualdata.getKey());
            assertEquals("minimal group", rvirtualdata.getAnyTypeClass());
        }
        // -------------------------------------------
        // Create a resource ad-hoc
        // -------------------------------------------
        ResourceTO resourceTO = new ResourceTO();
        resourceTO.setKey(resourceName);
        resourceTO.setConnector("be24b061-019d-4e3e-baf0-0a6d0a45cb9c");
        ProvisionTO provisionTO = new ProvisionTO();
        provisionTO.setAnyType(AnyTypeKind.USER.name());
        provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
        resourceTO.getProvisions().add(provisionTO);
        MappingTO mapping = new MappingTO();
        provisionTO.setMapping(mapping);
        ItemTO item = new ItemTO();
        item.setIntAttrName("fullname");
        item.setExtAttrName("ID");
        item.setPurpose(MappingPurpose.PROPAGATION);
        item.setConnObjectKey(true);
        mapping.setConnObjectKeyItem(item);
        item = new ItemTO();
        item.setIntAttrName("username");
        item.setExtAttrName("USERNAME");
        item.setPurpose(MappingPurpose.PROPAGATION);
        mapping.getItems().add(item);
        item = new ItemTO();
        item.setIntAttrName("groups[" + groupName + "].rvirtualdata");
        item.setExtAttrName("EMAIL");
        item.setPurpose(MappingPurpose.PROPAGATION);
        mapping.getItems().add(item);
        assertNotNull(getObject(resourceService.create(resourceTO).getLocation(), ResourceService.class, ResourceTO.class));
        // -------------------------------------------
        GroupTO groupTO = new GroupTO();
        groupTO.setName(groupName);
        groupTO.setRealm("/");
        groupTO.getVirAttrs().add(attrTO(rvirtualdata.getKey(), "ml@group.it"));
        groupTO.getResources().add(RESOURCE_NAME_LDAP);
        groupTO = createGroup(groupTO).getEntity();
        groupKey = groupTO.getKey();
        assertEquals(1, groupTO.getVirAttrs().size());
        assertEquals("ml@group.it", groupTO.getVirAttrs().iterator().next().getValues().get(0));
        // -------------------------------------------
        // -------------------------------------------
        // Create new user
        // -------------------------------------------
        UserTO userTO = UserITCase.getUniqueSampleTO("syn453@syncope.apache.org");
        userTO.getPlainAttrs().add(attrTO("fullname", "123"));
        userTO.getResources().clear();
        userTO.getResources().add(resourceName);
        userTO.getVirAttrs().clear();
        userTO.getMemberships().clear();
        userTO.getMemberships().add(new MembershipTO.Builder().group(groupTO.getKey()).build());
        ProvisioningResult<UserTO> result = createUser(userTO);
        assertEquals(2, result.getPropagationStatuses().size());
        assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
        assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(1).getStatus());
        userTO = result.getEntity();
        JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
        Map<String, Object> actuals = jdbcTemplate.queryForMap("SELECT id, surname, email FROM testpull WHERE id=?", new Object[] { userTO.getPlainAttr("fullname").get().getValues().get(0) });
        assertEquals(userTO.getPlainAttr("fullname").get().getValues().get(0), actuals.get("id").toString());
        assertEquals("ml@group.it", actuals.get("email"));
    // -------------------------------------------
    } catch (Exception e) {
        LOG.error("Unexpected error", e);
    } finally {
        // -------------------------------------------
        // Delete resource and group ad-hoc
        // -------------------------------------------
        resourceService.delete(resourceName);
        if (groupKey != null) {
            groupService.delete(groupKey);
        }
    // -------------------------------------------
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ItemTO(org.apache.syncope.common.lib.to.ItemTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Example 12 with GroupTO

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

the class MembershipITCase method onGroupDelete.

@Test
public void onGroupDelete() {
    // pre: create group with type extension
    TypeExtensionTO typeExtension = new TypeExtensionTO();
    typeExtension.setAnyType(AnyTypeKind.USER.name());
    typeExtension.getAuxClasses().add("csv");
    typeExtension.getAuxClasses().add("other");
    GroupTO groupTO = GroupITCase.getBasicSampleTO("typeExt");
    groupTO.getTypeExtensions().add(typeExtension);
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    // pre: create user with membership to such group
    UserTO user = UserITCase.getUniqueSampleTO("typeExt@apache.org");
    MembershipTO membership = new MembershipTO.Builder().group(groupTO.getKey()).build();
    membership.getPlainAttrs().add(new AttrTO.Builder().schema("aLong").value("1454").build());
    user.getMemberships().add(membership);
    user = createUser(user).getEntity();
    // verify that 'aLong' is correctly populated for user's membership
    assertEquals(1, user.getMemberships().size());
    membership = user.getMembership(groupTO.getKey()).get();
    assertNotNull(membership);
    assertEquals(1, membership.getPlainAttr("aLong").get().getValues().size());
    assertEquals("1454", membership.getPlainAttr("aLong").get().getValues().get(0));
    // verify that derived attrbutes from 'csv' and 'other' are also populated for user's membership
    assertFalse(membership.getDerAttr("csvuserid").get().getValues().isEmpty());
    assertFalse(membership.getDerAttr("noschema").get().getValues().isEmpty());
    // now remove the group -> all related memberships should have been removed as well
    groupService.delete(groupTO.getKey());
    // re-read user and verify that no memberships are available any more
    user = userService.read(user.getKey());
    assertTrue(user.getMemberships().isEmpty());
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 13 with GroupTO

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

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

the class GroupITCase method link.

@Test
public void link() {
    GroupTO groupTO = getSampleTO("link");
    groupTO.getResources().clear();
    GroupTO actual = createGroup(groupTO).getEntity();
    assertNotNull(actual);
    try {
        resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), actual.getKey());
        fail("This should not happen");
    } catch (Exception e) {
        assertNotNull(e);
    }
    AssociationPatch associationPatch = new AssociationPatch.Builder().key(actual.getKey()).action(ResourceAssociationAction.LINK).resource(RESOURCE_NAME_LDAP).build();
    assertNotNull(groupService.associate(associationPatch).readEntity(BulkActionResult.class));
    actual = groupService.read(actual.getKey());
    assertFalse(actual.getResources().isEmpty());
    try {
        resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), actual.getKey());
        fail("This should not happen");
    } catch (Exception e) {
        assertNotNull(e);
    }
}
Also used : BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) AssociationPatch(org.apache.syncope.common.lib.patch.AssociationPatch) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NamingException(javax.naming.NamingException) AccessControlException(java.security.AccessControlException) ForbiddenException(javax.ws.rs.ForbiddenException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 15 with GroupTO

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

the class GroupITCase method patch.

@Test
public void patch() {
    GroupTO original = getBasicSampleTO("patch");
    original.setUDynMembershipCond("(($groups==3;$resources!=ws-target-resource-1);aLong==1)");
    original.getADynMembershipConds().put("PRINTER", "(($groups==7;cool==ss);$resources==ws-target-resource-2);$type==PRINTER");
    GroupTO updated = createGroup(original).getEntity();
    updated.getPlainAttrs().add(new AttrTO.Builder().schema("icon").build());
    updated.getPlainAttrs().add(new AttrTO.Builder().schema("show").build());
    updated.getPlainAttrs().add(new AttrTO.Builder().schema("rderived_sx").value("sx").build());
    updated.getPlainAttrs().add(new AttrTO.Builder().schema("rderived_dx").value("dx").build());
    updated.getPlainAttrs().add(new AttrTO.Builder().schema("title").value("mr").build());
    original = groupService.read(updated.getKey());
    GroupPatch patch = AnyOperations.diff(updated, original, true);
    GroupTO group = updateGroup(patch).getEntity();
    Map<String, AttrTO> attrs = EntityTOUtils.buildAttrMap(group.getPlainAttrs());
    assertFalse(attrs.containsKey("icon"));
    assertFalse(attrs.containsKey("show"));
    assertEquals(Collections.singletonList("sx"), attrs.get("rderived_sx").getValues());
    assertEquals(Collections.singletonList("dx"), attrs.get("rderived_dx").getValues());
    assertEquals(Collections.singletonList("mr"), attrs.get("title").getValues());
}
Also used : AttrTO(org.apache.syncope.common.lib.to.AttrTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) 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