Search in sources :

Example 11 with ResourceTO

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

the class GroupITCase method capabilitiesOverride.

@Test
public void capabilitiesOverride() {
    // resource with no capability override
    ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
    assertNotNull(ldap);
    assertFalse(ldap.isOverrideCapabilities());
    assertTrue(ldap.getCapabilitiesOverride().isEmpty());
    // connector with all required for create and update
    ConnInstanceTO conn = connectorService.read(ldap.getConnector(), null);
    assertNotNull(conn);
    assertTrue(conn.getCapabilities().contains(ConnectorCapability.CREATE));
    assertTrue(conn.getCapabilities().contains(ConnectorCapability.UPDATE));
    try {
        // 1. create succeeds
        GroupTO group = getSampleTO("syncope714");
        group.getPlainAttrs().add(attrTO("title", "first"));
        group.getResources().add(RESOURCE_NAME_LDAP);
        ProvisioningResult<GroupTO> result = createGroup(group);
        assertNotNull(result);
        assertEquals(1, result.getPropagationStatuses().size());
        assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
        assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
        group = result.getEntity();
        // 2. update succeeds
        GroupPatch patch = new GroupPatch();
        patch.setKey(group.getKey());
        patch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("title", "second")).build());
        result = updateGroup(patch);
        assertNotNull(result);
        assertEquals(1, result.getPropagationStatuses().size());
        assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
        assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
        group = result.getEntity();
        // 3. set capability override with only search allowed, but not enable
        ldap.getCapabilitiesOverride().add(ConnectorCapability.SEARCH);
        resourceService.update(ldap);
        ldap = resourceService.read(RESOURCE_NAME_LDAP);
        assertNotNull(ldap);
        assertFalse(ldap.isOverrideCapabilities());
        assertEquals(1, ldap.getCapabilitiesOverride().size());
        assertTrue(ldap.getCapabilitiesOverride().contains(ConnectorCapability.SEARCH));
        // 4. update succeeds again
        patch = new GroupPatch();
        patch.setKey(group.getKey());
        patch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("title", "third")).build());
        result = updateGroup(patch);
        assertNotNull(result);
        assertEquals(1, result.getPropagationStatuses().size());
        assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
        assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
        group = result.getEntity();
        // 5. enable capability override
        ldap.setOverrideCapabilities(true);
        resourceService.update(ldap);
        ldap = resourceService.read(RESOURCE_NAME_LDAP);
        assertNotNull(ldap);
        assertTrue(ldap.isOverrideCapabilities());
        assertEquals(1, ldap.getCapabilitiesOverride().size());
        assertTrue(ldap.getCapabilitiesOverride().contains(ConnectorCapability.SEARCH));
        // 6. update now fails
        patch = new GroupPatch();
        patch.setKey(group.getKey());
        patch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("title", "fourth")).build());
        result = updateGroup(patch);
        assertNotNull(result);
        assertEquals(1, result.getPropagationStatuses().size());
        assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
        assertEquals(PropagationTaskExecStatus.NOT_ATTEMPTED, result.getPropagationStatuses().get(0).getStatus());
    } finally {
        ldap.getCapabilitiesOverride().clear();
        ldap.setOverrideCapabilities(false);
        resourceService.update(ldap);
    }
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 12 with ResourceTO

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

the class ResourceITCase method issueSYNCOPE493.

@Test
public void issueSYNCOPE493() {
    // create resource with attribute mapping set to NONE and check its propagation
    String resourceKey = RESOURCE_NAME_CREATE_NONE;
    ResourceTO resourceTO = new ResourceTO();
    resourceTO.setKey(resourceKey);
    resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
    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("key");
    item.setExtAttrName("userId");
    item.setConnObjectKey(true);
    item.setPurpose(MappingPurpose.PROPAGATION);
    mapping.setConnObjectKeyItem(item);
    ItemTO item2 = new ItemTO();
    item2.setConnObjectKey(false);
    item2.setIntAttrName("gender");
    item2.setExtAttrName("gender");
    item2.setPurpose(MappingPurpose.NONE);
    mapping.add(item2);
    Response response = resourceService.create(resourceTO);
    ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
    assertNotNull(actual);
    assertNotNull(actual.getProvision(AnyTypeKind.USER.name()).get().getMapping());
    assertNotNull(actual.getProvision(AnyTypeKind.USER.name()).get().getMapping().getItems());
    assertEquals(MappingPurpose.PROPAGATION, actual.getProvision(AnyTypeKind.USER.name()).get().getMapping().getConnObjectKeyItem().getPurpose());
    actual.getProvision(AnyTypeKind.USER.name()).get().getMapping().getItems().stream().filter(itemTO -> ("gender".equals(itemTO.getIntAttrName()))).forEach(itemTO -> assertEquals(MappingPurpose.NONE, itemTO.getPurpose()));
}
Also used : Response(javax.ws.rs.core.Response) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) PagedConnObjectTOResult(org.apache.syncope.common.lib.to.PagedConnObjectTOResult) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) SerializationUtils(org.apache.commons.lang3.SerializationUtils) ResourceHistoryConfTO(org.apache.syncope.common.lib.to.ResourceHistoryConfTO) ConnConfPropSchema(org.apache.syncope.common.lib.types.ConnConfPropSchema) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ItemTO(org.apache.syncope.common.lib.to.ItemTO) ImplementationType(org.apache.syncope.common.lib.types.ImplementationType) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) EntityViolationType(org.apache.syncope.common.lib.types.EntityViolationType) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) MappingTO(org.apache.syncope.common.lib.to.MappingTO) Collection(java.util.Collection) Set(java.util.Set) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) ConnIdSpecialName(org.apache.syncope.client.console.commons.ConnIdSpecialName) Test(org.junit.jupiter.api.Test) List(java.util.List) Response(javax.ws.rs.core.Response) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ConnObjectTOListQuery(org.apache.syncope.common.rest.api.beans.ConnObjectTOListQuery) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) OrgUnitTO(org.apache.syncope.common.lib.to.OrgUnitTO) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) TraceLevel(org.apache.syncope.common.lib.types.TraceLevel) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Test(org.junit.jupiter.api.Test)

Example 13 with ResourceTO

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

the class ResourceITCase method delete.

@Test
public void delete() {
    String resourceKey = "tobedeleted";
    ResourceTO resource = buildResourceTO(resourceKey);
    Response response = resourceService.create(resource);
    ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
    assertNotNull(actual);
    resourceService.delete(resourceKey);
    try {
        resourceService.read(resourceKey);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
    }
}
Also used : Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 14 with ResourceTO

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

the class ResourceITCase method createWithInvalidMapping.

@Test
public void createWithInvalidMapping() {
    String resourceKey = RESOURCE_NAME_CREATE_WRONG;
    ResourceTO resourceTO = new ResourceTO();
    resourceTO.setKey(resourceKey);
    resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
    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("key");
    item.setExtAttrName("userId");
    item.setConnObjectKey(true);
    mapping.setConnObjectKeyItem(item);
    item = new ItemTO();
    item.setExtAttrName("email");
    // missing intAttrName ...
    mapping.add(item);
    try {
        createResource(resourceTO);
        fail("Create should not have worked");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
        assertEquals("intAttrName", e.getElements().iterator().next());
    }
}
Also used : MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Test(org.junit.jupiter.api.Test)

Example 15 with ResourceTO

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

the class ResourceITCase method issueSYNCOPE368.

@Test
public void issueSYNCOPE368() {
    final String name = "SYNCOPE368-" + getUUIDString();
    ResourceTO resourceTO = new ResourceTO();
    resourceTO.setKey(name);
    resourceTO.setConnector("74141a3b-0762-4720-a4aa-fc3e374ef3ef");
    ProvisionTO provisionTO = new ProvisionTO();
    provisionTO.setAnyType(AnyTypeKind.GROUP.name());
    provisionTO.setObjectClass(ObjectClass.GROUP_NAME);
    resourceTO.getProvisions().add(provisionTO);
    MappingTO mapping = new MappingTO();
    provisionTO.setMapping(mapping);
    ItemTO item = new ItemTO();
    item.setIntAttrName("name");
    item.setExtAttrName("cn");
    item.setPurpose(MappingPurpose.BOTH);
    mapping.setConnObjectKeyItem(item);
    item = new ItemTO();
    item.setIntAttrName("userOwner");
    item.setExtAttrName("owner");
    item.setPurpose(MappingPurpose.BOTH);
    mapping.add(item);
    resourceTO = createResource(resourceTO);
    assertNotNull(resourceTO);
    assertEquals(2, resourceTO.getProvision(AnyTypeKind.GROUP.name()).get().getMapping().getItems().size());
}
Also used : MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)61 Test (org.junit.jupiter.api.Test)49 ItemTO (org.apache.syncope.common.lib.to.ItemTO)32 ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)29 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)27 Response (javax.ws.rs.core.Response)23 MappingTO (org.apache.syncope.common.lib.to.MappingTO)23 UserTO (org.apache.syncope.common.lib.to.UserTO)17 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)14 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)12 ResourceService (org.apache.syncope.common.rest.api.service.ResourceService)11 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)10 GroupTO (org.apache.syncope.common.lib.to.GroupTO)10 ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)9 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)9 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)8 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)8 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)8 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)8 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)8