Search in sources :

Example 21 with ConnInstance

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

the class ResourceTest method delete.

@Test
public void delete() {
    ExternalResource resource = resourceDAO.find("resource-testdb");
    assertNotNull(resource);
    // -------------------------------------
    // Get originally associated connector
    // -------------------------------------
    ConnInstance connector = resource.getConnector();
    assertNotNull(connector);
    // -------------------------------------
    // -------------------------------------
    // Get originally associated users
    // -------------------------------------
    List<User> users = userDAO.findByResource(resource);
    assertNotNull(users);
    Set<String> userKeys = users.stream().map(Entity::getKey).collect(Collectors.toSet());
    // -------------------------------------
    // Get tasks
    List<PropagationTask> propagationTasks = taskDAO.findAll(TaskType.PROPAGATION, resource, null, null, null, -1, -1, Collections.<OrderByClause>emptyList());
    assertFalse(propagationTasks.isEmpty());
    // delete resource
    resourceDAO.delete(resource.getKey());
    // close the transaction
    resourceDAO.flush();
    // resource must be removed
    ExternalResource actual = resourceDAO.find("resource-testdb");
    assertNull(actual);
    // resource must be not referenced any more from users
    userKeys.stream().map(key -> userDAO.find(key)).map(actualUser -> {
        assertNotNull(actualUser);
        return actualUser;
    }).forEachOrdered((actualUser) -> {
        userDAO.findAllResources(actualUser).forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
    });
    // resource must be not referenced any more from the connector
    ConnInstance actualConnector = connInstanceDAO.find(connector.getKey());
    assertNotNull(actualConnector);
    actualConnector.getResources().forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
    // there must be no tasks
    propagationTasks.forEach(task -> assertNull(taskDAO.find(task.getKey())));
}
Also used : JPAMappingItem(org.apache.syncope.core.persistence.jpa.entity.resource.JPAMappingItem) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) TaskDAO(org.apache.syncope.core.persistence.api.dao.TaskDAO) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) JPAOrgUnit(org.apache.syncope.core.persistence.jpa.entity.resource.JPAOrgUnit) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Set(java.util.Set) User(org.apache.syncope.core.persistence.api.entity.user.User) ConnInstanceDAO(org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO) 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) 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) PolicyDAO(org.apache.syncope.core.persistence.api.dao.PolicyDAO) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest) Collections(java.util.Collections) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) TaskType(org.apache.syncope.common.lib.types.TaskType) Transactional(org.springframework.transaction.annotation.Transactional) User(org.apache.syncope.core.persistence.api.entity.user.User) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) 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 22 with ConnInstance

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

the class DBPasswordPullActions method parseEncodedPassword.

private void parseEncodedPassword(final String password, final Connector connector) {
    if (password != null) {
        ConnInstance connInstance = connector.getConnInstance();
        String cipherAlgorithm = getCipherAlgorithm(connInstance);
        if (!CLEARTEXT.equals(cipherAlgorithm)) {
            try {
                encodedPassword = password;
                cipher = CipherAlgorithm.valueOf(cipherAlgorithm);
            } catch (IllegalArgumentException e) {
                LOG.error("Cipher algorithm not allowed: {}", cipherAlgorithm, e);
                encodedPassword = null;
            }
        }
    }
}
Also used : ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance)

Example 23 with ConnInstance

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

the class ConnInstanceDataBinderImpl method update.

@Override
public ConnInstance update(final ConnInstanceTO connInstanceTO) {
    ConnInstance connInstance = connInstanceDAO.authFind(connInstanceTO.getKey());
    if (connInstance == null) {
        throw new NotFoundException("Connector '" + connInstanceTO.getKey() + "'");
    }
    ConnInstanceTO current = getConnInstanceTO(connInstance);
    if (!current.equals(connInstanceTO)) {
        // 1. save the current configuration, before update
        ConnInstanceHistoryConf connInstanceHistoryConf = entityFactory.newEntity(ConnInstanceHistoryConf.class);
        connInstanceHistoryConf.setCreator(AuthContextUtils.getUsername());
        connInstanceHistoryConf.setCreation(new Date());
        connInstanceHistoryConf.setEntity(connInstance);
        connInstanceHistoryConf.setConf(current);
        connInstanceHistoryConfDAO.save(connInstanceHistoryConf);
        // 2. ensure the maximum history size is not exceeded
        List<ConnInstanceHistoryConf> history = connInstanceHistoryConfDAO.findByEntity(connInstance);
        long maxHistorySize = confDAO.find("connector.conf.history.size", 10L);
        if (maxHistorySize < history.size()) {
            // always remove the last item since history was obtained  by a query with ORDER BY creation DESC
            for (int i = 0; i < history.size() - maxHistorySize; i++) {
                connInstanceHistoryConfDAO.delete(history.get(history.size() - 1).getKey());
            }
        }
    }
    // 3. actual update
    connInstance.getCapabilities().clear();
    connInstance.getCapabilities().addAll(connInstanceTO.getCapabilities());
    if (connInstanceTO.getAdminRealm() != null) {
        Realm realm = realmDAO.findByFullPath(connInstanceTO.getAdminRealm());
        if (realm == null) {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
            sce.getElements().add("Invalid or null realm specified: " + connInstanceTO.getAdminRealm());
            throw sce;
        }
        connInstance.setAdminRealm(realm);
    }
    if (connInstanceTO.getLocation() != null) {
        connInstance.setLocation(connInstanceTO.getLocation());
    }
    if (connInstanceTO.getBundleName() != null) {
        connInstance.setBundleName(connInstanceTO.getBundleName());
    }
    if (connInstanceTO.getVersion() != null) {
        connInstance.setVersion(connInstanceTO.getVersion());
    }
    if (connInstanceTO.getConnectorName() != null) {
        connInstance.setConnectorName(connInstanceTO.getConnectorName());
    }
    if (connInstanceTO.getConf() != null && !connInstanceTO.getConf().isEmpty()) {
        connInstance.setConf(connInstanceTO.getConf());
    }
    if (connInstanceTO.getDisplayName() != null) {
        connInstance.setDisplayName(connInstanceTO.getDisplayName());
    }
    if (connInstanceTO.getConnRequestTimeout() != null) {
        connInstance.setConnRequestTimeout(connInstanceTO.getConnRequestTimeout());
    }
    if (connInstanceTO.getPoolConf() == null) {
        connInstance.setPoolConf(null);
    } else {
        connInstance.setPoolConf(ConnPoolConfUtils.getConnPoolConf(connInstanceTO.getPoolConf(), entityFactory.newConnPoolConf()));
    }
    try {
        connInstance = connInstanceDAO.save(connInstance);
    } catch (Exception e) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidConnInstance);
        sce.getElements().add(e.getMessage());
        throw sce;
    }
    return connInstance;
}
Also used : ConnInstanceHistoryConf(org.apache.syncope.core.persistence.api.entity.ConnInstanceHistoryConf) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Date(java.util.Date) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException)

Example 24 with ConnInstance

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

the class ConnectorManager method buildConnInstanceOverride.

@Override
public ConnInstance buildConnInstanceOverride(final ConnInstanceTO connInstance, final Collection<ConnConfProperty> confOverride, final Collection<ConnectorCapability> capabilitiesOverride) {
    synchronized (this) {
        if (entityFactory == null) {
            entityFactory = ApplicationContextProvider.getApplicationContext().getBean(EntityFactory.class);
        }
    }
    ConnInstance override = entityFactory.newEntity(ConnInstance.class);
    override.setAdminRealm(realmDAO.findByFullPath(connInstance.getAdminRealm()));
    override.setConnectorName(connInstance.getConnectorName());
    override.setDisplayName(connInstance.getDisplayName());
    override.setBundleName(connInstance.getBundleName());
    override.setVersion(connInstance.getVersion());
    override.setLocation(connInstance.getLocation());
    override.setConf(connInstance.getConf());
    override.getCapabilities().addAll(connInstance.getCapabilities());
    override.setConnRequestTimeout(connInstance.getConnRequestTimeout());
    Map<String, ConnConfProperty> overridable = new HashMap<>();
    Set<ConnConfProperty> conf = new HashSet<>();
    for (ConnConfProperty prop : override.getConf()) {
        if (prop.isOverridable()) {
            overridable.put(prop.getSchema().getName(), prop);
        } else {
            conf.add(prop);
        }
    }
    // add override properties
    for (ConnConfProperty prop : confOverride) {
        if (overridable.containsKey(prop.getSchema().getName()) && !prop.getValues().isEmpty()) {
            conf.add(prop);
            overridable.remove(prop.getSchema().getName());
        }
    }
    // add override properties not substituted
    conf.addAll(overridable.values());
    override.setConf(conf);
    // replace capabilities
    if (capabilitiesOverride != null) {
        override.getCapabilities().clear();
        override.getCapabilities().addAll(capabilitiesOverride);
    }
    return override;
}
Also used : HashMap(java.util.HashMap) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) HashSet(java.util.HashSet)

Example 25 with ConnInstance

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

the class ResourceLogic method create.

@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_CREATE + "')")
public ResourceTO create(final ResourceTO resourceTO) {
    if (StringUtils.isBlank(resourceTO.getKey())) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
        sce.getElements().add("Resource key");
        throw sce;
    }
    ConnInstance connInstance = connInstanceDAO.authFind(resourceTO.getConnector());
    if (connInstance == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidExternalResource);
        sce.getElements().add("Connector " + resourceTO.getConnector());
        throw sce;
    }
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_CREATE), connInstance.getAdminRealm().getFullPath());
    securityChecks(effectiveRealms, connInstance.getAdminRealm().getFullPath(), null);
    if (resourceDAO.authFind(resourceTO.getKey()) != null) {
        throw new DuplicateException(resourceTO.getKey());
    }
    return binder.getResourceTO(resourceDAO.save(binder.create(resourceTO)));
}
Also used : DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

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