Search in sources :

Example 11 with ProvisionTO

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

the class ResourceITCase method createWithPasswordPolicy.

@Test
public void createWithPasswordPolicy() {
    String resourceKey = "res-with-password-policy";
    ResourceTO resourceTO = new ResourceTO();
    resourceTO.setKey(resourceKey);
    resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
    resourceTO.setPasswordPolicy("986d1236-3ac5-4a19-810c-5ab21d79cba1");
    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.setExtAttrName("userId");
    item.setIntAttrName("userId");
    item.setConnObjectKey(true);
    item.setPurpose(MappingPurpose.BOTH);
    mapping.setConnObjectKeyItem(item);
    Response response = resourceService.create(resourceTO);
    ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
    assertNotNull(actual);
    // check the existence
    actual = resourceService.read(resourceKey);
    assertNotNull(actual);
    assertNotNull(actual.getPasswordPolicy());
    assertEquals("986d1236-3ac5-4a19-810c-5ab21d79cba1", actual.getPasswordPolicy());
}
Also used : Response(javax.ws.rs.core.Response) 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 12 with ProvisionTO

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

the class ResourceITCase method createWithoutExtAttr.

@Test
public void createWithoutExtAttr() {
    assertThrows(SyncopeClientException.class, () -> {
        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.setIntAttrName("usernane");
        // missing extAttrName ...
        mapping.add(item);
        createResource(resourceTO);
    });
}
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)

Example 13 with ProvisionTO

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

the class ResourceITCase method history.

@Test
public void history() {
    List<ResourceHistoryConfTO> history = resourceHistoryService.list(RESOURCE_NAME_LDAP);
    assertNotNull(history);
    int pre = history.size();
    ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
    TraceLevel originalTraceLevel = SerializationUtils.clone(ldap.getUpdateTraceLevel());
    assertEquals(TraceLevel.ALL, originalTraceLevel);
    ProvisionTO originalProvision = SerializationUtils.clone(ldap.getProvision(AnyTypeKind.USER.name()).get());
    assertEquals(ObjectClass.ACCOUNT_NAME, originalProvision.getObjectClass());
    boolean originalFlag = ldap.isRandomPwdIfNotProvided();
    assertTrue(originalFlag);
    ldap.setUpdateTraceLevel(TraceLevel.FAILURES);
    ldap.getProvision(AnyTypeKind.USER.name()).get().setObjectClass("ANOTHER");
    ldap.setRandomPwdIfNotProvided(false);
    resourceService.update(ldap);
    ldap = resourceService.read(RESOURCE_NAME_LDAP);
    assertNotEquals(originalTraceLevel, ldap.getUpdateTraceLevel());
    assertNotEquals(originalProvision.getObjectClass(), ldap.getProvision(AnyTypeKind.USER.name()).get().getObjectClass());
    assertNotEquals(originalFlag, ldap.isRandomPwdIfNotProvided());
    history = resourceHistoryService.list(RESOURCE_NAME_LDAP);
    assertEquals(pre + 1, history.size());
    resourceHistoryService.restore(history.get(0).getKey());
    ldap = resourceService.read(RESOURCE_NAME_LDAP);
    assertEquals(originalTraceLevel, ldap.getUpdateTraceLevel());
    assertEquals(originalProvision.getObjectClass(), ldap.getProvision(AnyTypeKind.USER.name()).get().getObjectClass());
    assertEquals(originalFlag, ldap.isRandomPwdIfNotProvided());
}
Also used : ResourceHistoryConfTO(org.apache.syncope.common.lib.to.ResourceHistoryConfTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) TraceLevel(org.apache.syncope.common.lib.types.TraceLevel) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) Test(org.junit.jupiter.api.Test)

Example 14 with ProvisionTO

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

the class ResourceITCase method createWithSingleMappingItem.

@Test
public void createWithSingleMappingItem() {
    String resourceKey = RESOURCE_NAME_CREATE_SINGLE;
    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);
    provisionTO = new ProvisionTO();
    provisionTO.setAnyType(AnyTypeKind.GROUP.name());
    provisionTO.setObjectClass(ObjectClass.GROUP_NAME);
    resourceTO.getProvisions().add(provisionTO);
    mapping = new MappingTO();
    provisionTO.setMapping(mapping);
    item = new ItemTO();
    item.setIntAttrName("key");
    item.setExtAttrName("groupId");
    item.setConnObjectKey(true);
    item.setPurpose(MappingPurpose.PULL);
    mapping.setConnObjectKeyItem(item);
    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());
    assertNotNull(actual.getProvision(AnyTypeKind.GROUP.name()).get().getMapping());
    assertNotNull(actual.getProvision(AnyTypeKind.GROUP.name()).get().getMapping().getItems());
    assertEquals(MappingPurpose.PULL, actual.getProvision(AnyTypeKind.GROUP.name()).get().getMapping().getConnObjectKeyItem().getPurpose());
    assertEquals(MappingPurpose.PROPAGATION, actual.getProvision(AnyTypeKind.USER.name()).get().getMapping().getConnObjectKeyItem().getPurpose());
}
Also used : Response(javax.ws.rs.core.Response) 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 15 with ProvisionTO

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

the class ResourceDataBinderTest method issue42.

@Test
public void issue42() {
    PlainSchema userId = plainSchemaDAO.find("userId");
    Set<MappingItem> beforeUserIdMappings = new HashSet<>();
    for (ExternalResource res : resourceDAO.findAll()) {
        if (res.getProvision(anyTypeDAO.findUser()).isPresent() && res.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : res.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if (userId.getKey().equals(mapItem.getIntAttrName())) {
                    beforeUserIdMappings.add(mapItem);
                }
            }
        }
    }
    ResourceTO resourceTO = new ResourceTO();
    resourceTO.setKey("resource-issue42");
    resourceTO.setConnector("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
    resourceTO.setEnforceMandatoryCondition(true);
    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("userId");
    item.setExtAttrName("campo1");
    item.setConnObjectKey(true);
    item.setMandatoryCondition("false");
    item.setPurpose(MappingPurpose.BOTH);
    mapping.setConnObjectKeyItem(item);
    ExternalResource resource = resourceDataBinder.create(resourceTO);
    resource = resourceDAO.save(resource);
    assertNotNull(resource);
    assertNotNull(resource.getProvision(anyTypeDAO.findUser()).get().getMapping());
    assertEquals(1, resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().size());
    resourceDAO.flush();
    ExternalResource actual = resourceDAO.find("resource-issue42");
    assertNotNull(actual);
    assertEquals(resource, actual);
    userId = plainSchemaDAO.find("userId");
    Set<MappingItem> afterUserIdMappings = new HashSet<>();
    for (ExternalResource res : resourceDAO.findAll()) {
        if (res.getProvision(anyTypeDAO.findUser()).isPresent() && res.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : res.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if (userId.getKey().equals(mapItem.getIntAttrName())) {
                    afterUserIdMappings.add(mapItem);
                }
            }
        }
    }
    assertEquals(beforeUserIdMappings.size(), afterUserIdMappings.size() - 1);
}
Also used : MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ItemTO(org.apache.syncope.common.lib.to.ItemTO) HashSet(java.util.HashSet) 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