Search in sources :

Example 26 with ProvisionTO

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

the class ResourceITCase method read.

@Test
public void read() {
    ResourceTO resource = resourceService.read(RESOURCE_NAME_DBVIRATTR);
    assertNotNull(resource);
    Optional<ProvisionTO> provision = resource.getProvision(AnyTypeKind.USER.name());
    assertTrue(provision.isPresent());
    assertFalse(provision.get().getMapping().getItems().isEmpty());
    assertFalse(provision.get().getMapping().getLinkingItems().isEmpty());
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) Test(org.junit.jupiter.api.Test)

Example 27 with ProvisionTO

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

the class GroupITCase method issueSYNCOPE632.

@Test
public void issueSYNCOPE632() {
    DerSchemaTO orig = schemaService.read(SchemaType.DERIVED, "displayProperty");
    DerSchemaTO modified = SerializationUtils.clone(orig);
    modified.setExpression("icon + '_' + show");
    GroupTO groupTO = GroupITCase.getSampleTO("lastGroup");
    try {
        schemaService.update(SchemaType.DERIVED, modified);
        // 0. create group
        groupTO.getPlainAttrs().add(attrTO("icon", "anIcon"));
        groupTO.getPlainAttrs().add(attrTO("show", "true"));
        groupTO.getResources().clear();
        groupTO = createGroup(groupTO).getEntity();
        assertNotNull(groupTO);
        // 1. create new LDAP resource having ConnObjectKey mapped to a derived attribute
        ResourceTO newLDAP = resourceService.read(RESOURCE_NAME_LDAP);
        newLDAP.setKey("new-ldap");
        newLDAP.setPropagationPriority(0);
        for (ProvisionTO provision : newLDAP.getProvisions()) {
            provision.getVirSchemas().clear();
        }
        MappingTO mapping = newLDAP.getProvision(AnyTypeKind.GROUP.name()).get().getMapping();
        ItemTO connObjectKey = mapping.getConnObjectKeyItem();
        connObjectKey.setIntAttrName("displayProperty");
        connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
        mapping.setConnObjectKeyItem(connObjectKey);
        mapping.setConnObjectLink("'cn=' + displayProperty + ',ou=groups,o=isp'");
        ItemTO description = new ItemTO();
        description.setIntAttrName("key");
        description.setExtAttrName("description");
        description.setPurpose(MappingPurpose.PROPAGATION);
        mapping.add(description);
        newLDAP = createResource(newLDAP);
        assertNotNull(newLDAP);
        // 2. update group and give the resource created above
        GroupPatch patch = new GroupPatch();
        patch.setKey(groupTO.getKey());
        patch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value("new-ldap").build());
        groupTO = updateGroup(patch).getEntity();
        assertNotNull(groupTO);
        // 3. update the group
        GroupPatch groupPatch = new GroupPatch();
        groupPatch.setKey(groupTO.getKey());
        groupPatch.getPlainAttrs().add(attrAddReplacePatch("icon", "anotherIcon"));
        groupTO = updateGroup(groupPatch).getEntity();
        assertNotNull(groupTO);
        // 4. check that a single group exists in LDAP for the group created and updated above
        int entries = 0;
        DirContext ctx = null;
        try {
            ctx = getLdapResourceDirContext(null, null);
            SearchControls ctls = new SearchControls();
            ctls.setReturningAttributes(new String[] { "*", "+" });
            ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
            NamingEnumeration<SearchResult> result = ctx.search("ou=groups,o=isp", "(description=" + groupTO.getKey() + ")", ctls);
            while (result.hasMore()) {
                result.next();
                entries++;
            }
        } catch (Exception e) {
        // ignore
        } finally {
            if (ctx != null) {
                try {
                    ctx.close();
                } catch (NamingException e) {
                // ignore
                }
            }
        }
        assertEquals(1, entries);
    } finally {
        schemaService.update(SchemaType.DERIVED, orig);
        if (groupTO.getKey() != null) {
            groupService.delete(groupTO.getKey());
        }
        resourceService.delete("new-ldap");
    }
}
Also used : SearchResult(javax.naming.directory.SearchResult) DirContext(javax.naming.directory.DirContext) ItemTO(org.apache.syncope.common.lib.to.ItemTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) 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) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SearchControls(javax.naming.directory.SearchControls) NamingException(javax.naming.NamingException) Test(org.junit.jupiter.api.Test)

Example 28 with ProvisionTO

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

the class ConnectorITCase method issueSYNCOPE112.

@Test
public void issueSYNCOPE112() {
    // ----------------------------------------
    // Create a new connector
    // ----------------------------------------
    ConnInstanceTO connectorTO = new ConnInstanceTO();
    connectorTO.setAdminRealm(SyncopeConstants.ROOT_REALM);
    connectorTO.setLocation(connectorService.read("88a7a819-dab5-46b4-9b90-0b9769eabdb8", Locale.ENGLISH.getLanguage()).getLocation());
    // set connector version
    connectorTO.setVersion(connIdSoapVersion);
    // set connector name
    connectorTO.setConnectorName("net.tirasa.connid.bundles.soap.WebServiceConnector");
    // set bundle name
    connectorTO.setBundleName("net.tirasa.connid.bundles.soap");
    // set display name
    connectorTO.setDisplayName("WSSoap");
    // set the connector configuration using PropertyTO
    Set<ConnConfProperty> conf = new HashSet<>();
    ConnConfPropSchema userSchema = new ConnConfPropSchema();
    userSchema.setName("endpoint");
    userSchema.setType(String.class.getName());
    userSchema.setRequired(true);
    ConnConfProperty endpoint = new ConnConfProperty();
    endpoint.setSchema(userSchema);
    endpoint.getValues().add("http://localhost:9080/does_not_work");
    endpoint.setOverridable(true);
    ConnConfPropSchema keyColumnSchema = new ConnConfPropSchema();
    keyColumnSchema.setName("servicename");
    keyColumnSchema.setType(String.class.getName());
    keyColumnSchema.setRequired(true);
    ConnConfProperty servicename = new ConnConfProperty();
    servicename.setSchema(keyColumnSchema);
    servicename.getValues().add("net.tirasa.connid.bundles.soap.provisioning.interfaces.Provisioning");
    servicename.setOverridable(false);
    conf.add(endpoint);
    conf.add(servicename);
    // set connector configuration
    connectorTO.getConf().addAll(conf);
    try {
        try {
            connectorService.check(connectorTO);
            fail("This should not happen");
        } catch (Exception e) {
            assertNotNull(e);
        }
        Response response = connectorService.create(connectorTO);
        if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
            throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
        }
        connectorTO = getObject(response.getLocation(), ConnectorService.class, ConnInstanceTO.class);
        assertNotNull(connectorTO);
        // ----------------------------------------
        // ----------------------------------------
        // create a resourceTO
        // ----------------------------------------
        String resourceName = "checkForPropOverriding";
        ResourceTO resourceTO = new ResourceTO();
        resourceTO.setKey(resourceName);
        resourceTO.setConnector(connectorTO.getKey());
        conf = new HashSet<>();
        endpoint.getValues().clear();
        endpoint.getValues().add("http://localhost:9080/syncope-fit-build-tools/cxf/soap/provisioning");
        conf.add(endpoint);
        resourceTO.getConfOverride().addAll(conf);
        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 mapItem = new ItemTO();
        mapItem.setExtAttrName("uid");
        mapItem.setIntAttrName("userId");
        mapItem.setConnObjectKey(true);
        mapping.setConnObjectKeyItem(mapItem);
        // ----------------------------------------
        try {
            resourceService.check(resourceTO);
        } catch (Exception e) {
            fail(ExceptionUtils.getStackTrace(e));
        }
    // ----------------------------------------
    } finally {
        // Remove connector from db to make test re-runnable
        connectorService.delete(connectorTO.getKey());
    }
}
Also used : ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) GuardedString(org.identityconnectors.common.security.GuardedString) ItemTO(org.apache.syncope.common.lib.to.ItemTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) IOException(java.io.IOException) ConnectorService(org.apache.syncope.common.rest.api.service.ConnectorService) Response(javax.ws.rs.core.Response) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ConnConfPropSchema(org.apache.syncope.common.lib.types.ConnConfPropSchema) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 29 with ProvisionTO

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

the class VirAttrITCase method issueSYNCOPE260.

@Test
public void issueSYNCOPE260() {
    // create new virtual schema for the resource below
    ResourceTO ws2 = resourceService.read(RESOURCE_NAME_WS2);
    ProvisionTO provision = ws2.getProvision(AnyTypeKind.USER.name()).get();
    assertNotNull(provision);
    VirSchemaTO virSchema = new VirSchemaTO();
    virSchema.setKey("syncope260" + getUUIDString());
    virSchema.setExtAttrName("companyName");
    virSchema.setResource(RESOURCE_NAME_WS2);
    virSchema.setAnyType(provision.getAnyType());
    virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
    assertNotNull(virSchema);
    AnyTypeClassTO newClass = new AnyTypeClassTO();
    newClass.setKey("syncope260" + getUUIDString());
    newClass.getVirSchemas().add(virSchema.getKey());
    Response response = anyTypeClassService.create(newClass);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
    newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
    // ----------------------------------
    // create user and check virtual attribute value propagation
    // ----------------------------------
    UserTO userTO = UserITCase.getUniqueSampleTO("260@a.com");
    userTO.getAuxClasses().add(newClass.getKey());
    userTO.getVirAttrs().add(attrTO(virSchema.getKey(), "virtualvalue"));
    userTO.getResources().add(RESOURCE_NAME_WS2);
    ProvisioningResult<UserTO> result = createUser(userTO);
    assertNotNull(result);
    assertFalse(result.getPropagationStatuses().isEmpty());
    assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("virtualvalue", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
    // ----------------------------------
    // ----------------------------------
    // update user virtual attribute and check virtual attribute value update propagation
    // ----------------------------------
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getVirAttrs().add(attrTO(virSchema.getKey(), "virtualvalue2"));
    result = updateUser(userPatch);
    assertNotNull(result);
    assertFalse(result.getPropagationStatuses().isEmpty());
    assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
    // ----------------------------------
    // ----------------------------------
    // suspend/reactivate user and check virtual attribute value (unchanged)
    // ----------------------------------
    StatusPatch statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.SUSPEND).build();
    userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertEquals("suspended", userTO.getStatus());
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
    statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.REACTIVATE).build();
    userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertEquals("active", userTO.getStatus());
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
    // ----------------------------------
    // ----------------------------------
    // update user attribute and check virtual attribute value (unchanged)
    // ----------------------------------
    userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "Surname2"));
    result = updateUser(userPatch);
    assertNotNull(result);
    assertFalse(result.getPropagationStatuses().isEmpty());
    assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("Surname2", connObjectTO.getAttr("SURNAME").get().getValues().get(0));
    // virtual attribute value did not change
    assertFalse(connObjectTO.getAttr("COMPANYNAME").get().getValues().isEmpty());
    assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
}
Also used : ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) UserTO(org.apache.syncope.common.lib.to.UserTO) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Aggregations

ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)29 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)28 ItemTO (org.apache.syncope.common.lib.to.ItemTO)25 Test (org.junit.jupiter.api.Test)24 MappingTO (org.apache.syncope.common.lib.to.MappingTO)21 Response (javax.ws.rs.core.Response)12 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)12 UserTO (org.apache.syncope.common.lib.to.UserTO)8 GroupTO (org.apache.syncope.common.lib.to.GroupTO)7 HashSet (java.util.HashSet)6 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)6 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)6 ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)6 ResourceService (org.apache.syncope.common.rest.api.service.ResourceService)6 Optional (java.util.Optional)5 SerializationUtils (org.apache.commons.lang3.SerializationUtils)5 AttrTO (org.apache.syncope.common.lib.to.AttrTO)5 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)5