Search in sources :

Example 26 with ConnInstance

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

the class JPAConnInstanceDAO method authFind.

@Override
public ConnInstance authFind(final String key) {
    ConnInstance connInstance = find(key);
    if (connInstance == null) {
        return null;
    }
    Set<String> authRealms = AuthContextUtils.getAuthorizations().get(StandardEntitlement.CONNECTOR_READ);
    if (authRealms == null || authRealms.isEmpty() || !authRealms.stream().anyMatch(realm -> connInstance.getAdminRealm().getFullPath().startsWith(realm))) {
        throw new DelegatedAdministrationException(connInstance.getAdminRealm().getFullPath(), ConnInstance.class.getSimpleName(), connInstance.getKey());
    }
    return connInstance;
}
Also used : DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) JPAConnInstance(org.apache.syncope.core.persistence.jpa.entity.JPAConnInstance)

Example 27 with ConnInstance

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

the class JPAConnInstanceDAO method delete.

@Override
public void delete(final String key) {
    ConnInstance connInstance = find(key);
    if (connInstance == null) {
        return;
    }
    connInstance.getResources().stream().map(Entity::getKey).collect(Collectors.toList()).forEach(resource -> resourceDAO.delete(resource));
    connInstanceHistoryConfDAO.deleteByEntity(connInstance);
    entityManager().remove(connInstance);
    connRegistry.unregisterConnector(key);
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) JPAConnInstance(org.apache.syncope.core.persistence.jpa.entity.JPAConnInstance)

Example 28 with ConnInstance

use of org.apache.syncope.core.persistence.api.entity.ConnInstance 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 29 with ConnInstance

use of org.apache.syncope.core.persistence.api.entity.ConnInstance 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 30 with ConnInstance

use of org.apache.syncope.core.persistence.api.entity.ConnInstance 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)

Aggregations

ConnInstance (org.apache.syncope.core.persistence.api.entity.ConnInstance)34 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)17 Test (org.junit.jupiter.api.Test)17 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)13 Mapping (org.apache.syncope.core.persistence.api.entity.resource.Mapping)11 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)11 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)10 Transactional (org.springframework.transaction.annotation.Transactional)8 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)7 HashSet (java.util.HashSet)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)5 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Date (java.util.Date)4 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)4 PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 Set (java.util.Set)3