Search in sources :

Example 6 with Mapping

use of org.apache.syncope.core.persistence.api.entity.resource.Mapping in project syncope by apache.

the class ResourceTest method save.

@Test
public void save() {
    ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
    resource.setKey("ws-target-resource-save");
    // specify the connector
    ConnInstance connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
    assertNotNull(connector);
    resource.setConnector(connector);
    Provision provision = entityFactory.newEntity(Provision.class);
    provision.setAnyType(anyTypeDAO.findUser());
    provision.setObjectClass(ObjectClass.ACCOUNT);
    provision.setResource(resource);
    resource.add(provision);
    Mapping mapping = entityFactory.newEntity(Mapping.class);
    mapping.setProvision(provision);
    provision.setMapping(mapping);
    // specify mappings
    for (int i = 0; i < 3; i++) {
        MappingItem item = entityFactory.newEntity(MappingItem.class);
        item.setExtAttrName("test" + i);
        item.setIntAttrName("nonexistent" + i);
        item.setMandatoryCondition("false");
        item.setPurpose(MappingPurpose.PULL);
        mapping.add(item);
        item.setMapping(mapping);
    }
    MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
    connObjectKey.setExtAttrName("username");
    connObjectKey.setIntAttrName("username");
    connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
    mapping.setConnObjectKeyItem(connObjectKey);
    connObjectKey.setMapping(mapping);
    // map a derived attribute
    MappingItem derived = entityFactory.newEntity(MappingItem.class);
    derived.setConnObjectKey(false);
    derived.setExtAttrName("fullname");
    derived.setIntAttrName("cn");
    derived.setPurpose(MappingPurpose.PROPAGATION);
    mapping.add(derived);
    derived.setMapping(mapping);
    // save the resource
    ExternalResource actual = resourceDAO.save(resource);
    assertNotNull(actual);
    assertNotNull(actual.getProvision(anyTypeDAO.findUser()).get().getMapping());
    resourceDAO.flush();
    resourceDAO.detach(actual);
    connInstanceDAO.detach(connector);
    // assign the new resource to an user
    User user = userDAO.findByUsername("rossini");
    assertNotNull(user);
    user.add(actual);
    resourceDAO.flush();
    // retrieve resource
    resource = resourceDAO.find(actual.getKey());
    assertNotNull(resource);
    resourceDAO.refresh(resource);
    // check connector
    connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
    assertNotNull(connector);
    assertNotNull(connector.getResources());
    assertNotNull(resource.getConnector());
    assertTrue(resource.getConnector().equals(connector));
    // check mappings
    List<? extends MappingItem> items = resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems();
    assertNotNull(items);
    assertEquals(5, items.size());
    // check user
    user = userDAO.findByUsername("rossini");
    assertNotNull(user);
    assertNotNull(user.getResources());
    assertTrue(user.getResources().contains(actual));
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) JPAMappingItem(org.apache.syncope.core.persistence.jpa.entity.resource.JPAMappingItem) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) User(org.apache.syncope.core.persistence.api.entity.user.User) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 7 with Mapping

use of org.apache.syncope.core.persistence.api.entity.resource.Mapping in project syncope by apache.

the class ResourceTest method findById.

@Test
public void findById() {
    ExternalResource resource = resourceDAO.find("ws-target-resource-1");
    assertNotNull(resource);
    ConnInstance connector = resource.getConnector();
    assertNotNull(connector);
    assertEquals("net.tirasa.connid.bundles.soap.WebServiceConnector", connector.getConnectorName());
    assertEquals("net.tirasa.connid.bundles.soap", connector.getBundleName());
    Mapping mapping = resource.getProvision(anyTypeDAO.findUser()).get().getMapping();
    assertFalse(mapping.getItems().isEmpty());
    assertTrue(mapping.getItems().stream().anyMatch(item -> "7f55b09c-b573-41dc-a9eb-ccd80bd3ea7a".equals(item.getKey())));
    try {
        resourceDAO.authFind("ws-target-resource-1");
        fail("This should not happen");
    } catch (DelegatedAdministrationException e) {
        assertNotNull(e);
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Autowired(org.springframework.beans.factory.annotation.Autowired) SyncopeGrantedAuthority(org.apache.syncope.core.spring.security.SyncopeGrantedAuthority) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) EntityViolationType(org.apache.syncope.common.lib.types.EntityViolationType) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) SyncopeAuthenticationDetails(org.apache.syncope.core.spring.security.SyncopeAuthenticationDetails) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Test(org.junit.jupiter.api.Test) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) Transactional(org.springframework.transaction.annotation.Transactional) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 8 with Mapping

use of org.apache.syncope.core.persistence.api.entity.resource.Mapping in project syncope by apache.

the class ResourceTest method save.

@Test
public void save() {
    ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
    resource.setKey("ws-target-resource-basic-save");
    resource.setPropagationPriority(2);
    Provision provision = entityFactory.newEntity(Provision.class);
    provision.setAnyType(anyTypeDAO.findUser());
    provision.setObjectClass(ObjectClass.ACCOUNT);
    provision.setResource(resource);
    resource.add(provision);
    Mapping mapping = entityFactory.newEntity(Mapping.class);
    mapping.setProvision(provision);
    provision.setMapping(mapping);
    MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
    connObjectKey.setExtAttrName("username");
    connObjectKey.setIntAttrName("fullname");
    connObjectKey.setPurpose(MappingPurpose.BOTH);
    mapping.setConnObjectKeyItem(connObjectKey);
    ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
    resource.setConnector(connector);
    // save the resource
    ExternalResource actual = resourceDAO.save(resource);
    assertNotNull(actual);
    assertNotNull(actual.getConnector());
    assertNotNull(actual.getProvision(anyTypeDAO.findUser()).get().getMapping());
    assertFalse(actual.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().isEmpty());
    assertEquals(Integer.valueOf(2), actual.getPropagationPriority());
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 9 with Mapping

use of org.apache.syncope.core.persistence.api.entity.resource.Mapping in project syncope by apache.

the class ResourceTest method saveInvalidMappingIntAttr.

@Test
public void saveInvalidMappingIntAttr() {
    assertThrows(InvalidEntityException.class, () -> {
        ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
        resource.setKey("ws-target-resource-basic-save-invalid");
        ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
        resource.setConnector(connector);
        Provision provision = entityFactory.newEntity(Provision.class);
        provision.setAnyType(anyTypeDAO.findUser());
        provision.setObjectClass(ObjectClass.ACCOUNT);
        provision.setResource(resource);
        resource.add(provision);
        Mapping mapping = entityFactory.newEntity(Mapping.class);
        mapping.setProvision(provision);
        provision.setMapping(mapping);
        MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
        connObjectKey.setConnObjectKey(true);
        mapping.add(connObjectKey);
        // save the resource
        resourceDAO.save(resource);
    });
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 10 with Mapping

use of org.apache.syncope.core.persistence.api.entity.resource.Mapping in project syncope by apache.

the class ResourceTest method saveWithGroupMappingType.

@Test
public void saveWithGroupMappingType() {
    ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
    resource.setKey("ws-target-resource-basic-save-invalid");
    ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
    resource.setConnector(connector);
    Provision provision = entityFactory.newEntity(Provision.class);
    provision.setAnyType(anyTypeDAO.findUser());
    provision.setObjectClass(ObjectClass.ACCOUNT);
    provision.setResource(resource);
    resource.add(provision);
    Mapping mapping = entityFactory.newEntity(Mapping.class);
    mapping.setProvision(provision);
    provision.setMapping(mapping);
    MappingItem item = entityFactory.newEntity(MappingItem.class);
    item.setIntAttrName("fullname");
    item.setExtAttrName("fullname");
    item.setPurpose(MappingPurpose.BOTH);
    mapping.setConnObjectKeyItem(item);
    item = entityFactory.newEntity(MappingItem.class);
    item.setIntAttrName("icon");
    item.setExtAttrName("icon");
    item.setPurpose(MappingPurpose.BOTH);
    mapping.add(item);
    item = entityFactory.newEntity(MappingItem.class);
    item.setIntAttrName("mderiveddata");
    item.setExtAttrName("mderiveddata");
    item.setPurpose(MappingPurpose.PROPAGATION);
    mapping.add(item);
    // save the resource
    ExternalResource actual = resourceDAO.save(resource);
    assertNotNull(actual);
    assertEquals(3, actual.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().size());
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

Mapping (org.apache.syncope.core.persistence.api.entity.resource.Mapping)12 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)12 ConnInstance (org.apache.syncope.core.persistence.api.entity.ConnInstance)10 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)10 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)8 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)7 Test (org.junit.jupiter.api.Test)7 Date (java.util.Date)3 List (java.util.List)3 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)3 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)3 ParseException (java.text.ParseException)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Collectors (java.util.stream.Collectors)2 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 IteratorChain (org.apache.syncope.common.lib.collections.IteratorChain)2 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)2 ItemTO (org.apache.syncope.common.lib.to.ItemTO)2