Search in sources :

Example 16 with ExternalResource

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

the class ResourceLogic method listConnObjects.

@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_LIST_CONNOBJECT + "')")
@Transactional(readOnly = true)
public Pair<SearchResult, List<ConnObjectTO>> listConnObjects(final String key, final String anyTypeKey, final int size, final String pagedResultsCookie, final List<OrderByClause> orderBy) {
    ExternalResource resource;
    ObjectClass objectClass;
    OperationOptions options;
    if (SyncopeConstants.REALM_ANYTYPE.equals(anyTypeKey)) {
        resource = resourceDAO.authFind(key);
        if (resource == null) {
            throw new NotFoundException("Resource '" + key + "'");
        }
        if (resource.getOrgUnit() == null) {
            throw new NotFoundException("Realm provisioning for resource '" + key + "'");
        }
        objectClass = resource.getOrgUnit().getObjectClass();
        options = MappingUtils.buildOperationOptions(MappingUtils.getPropagationItems(resource.getOrgUnit().getItems()).iterator());
    } else {
        Triple<ExternalResource, AnyType, Provision> init = connObjectInit(key, anyTypeKey);
        resource = init.getLeft();
        objectClass = init.getRight().getObjectClass();
        init.getRight().getMapping().getItems();
        Set<MappingItem> linkinMappingItems = virSchemaDAO.findByProvision(init.getRight()).stream().map(virSchema -> virSchema.asLinkingMappingItem()).collect(Collectors.toSet());
        Iterator<MappingItem> mapItems = new IteratorChain<>(init.getRight().getMapping().getItems().iterator(), linkinMappingItems.iterator());
        options = MappingUtils.buildOperationOptions(mapItems);
    }
    final List<ConnObjectTO> connObjects = new ArrayList<>();
    SearchResult searchResult = connFactory.getConnector(resource).search(objectClass, null, new ResultsHandler() {

        private int count;

        @Override
        public boolean handle(final ConnectorObject connectorObject) {
            connObjects.add(ConnObjectUtils.getConnObjectTO(connectorObject));
            // safety protection against uncontrolled result size
            count++;
            return count < size;
        }
    }, size, pagedResultsCookie, orderBy, options);
    return ImmutablePair.of(searchResult, connObjects);
}
Also used : OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) StringUtils(org.apache.commons.lang3.StringUtils) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) Attribute(org.identityconnectors.framework.common.objects.Attribute) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) ConnObjectUtils(org.apache.syncope.core.provisioning.java.utils.ConnObjectUtils) OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Method(java.lang.reflect.Method) Triple(org.apache.commons.lang3.tuple.Triple) ResultsHandler(org.identityconnectors.framework.common.objects.ResultsHandler) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Set(java.util.Set) ConnInstanceDAO(org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO) ResourceDataBinder(org.apache.syncope.core.provisioning.api.data.ResourceDataBinder) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) Connector(org.apache.syncope.core.provisioning.api.Connector) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttributeUtil(org.identityconnectors.framework.common.objects.AttributeUtil) AttributeBuilder(org.identityconnectors.framework.common.objects.AttributeBuilder) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) ConnectorFactory(org.apache.syncope.core.provisioning.api.ConnectorFactory) Optional(java.util.Optional) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) ArrayUtils(org.apache.commons.lang3.ArrayUtils) ConnInstanceDataBinder(org.apache.syncope.core.provisioning.api.data.ConnInstanceDataBinder) ArrayList(java.util.ArrayList) RealmUtils(org.apache.syncope.core.provisioning.api.utils.RealmUtils) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) MappingManager(org.apache.syncope.core.provisioning.api.MappingManager) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) Iterator(java.util.Iterator) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) Uid(org.identityconnectors.framework.common.objects.Uid) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Name(org.identityconnectors.framework.common.objects.Name) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Component(org.springframework.stereotype.Component) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) SearchResult(org.identityconnectors.framework.common.objects.SearchResult) Any(org.apache.syncope.core.persistence.api.entity.Any) Transactional(org.springframework.transaction.annotation.Transactional) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) ArrayList(java.util.ArrayList) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) SearchResult(org.identityconnectors.framework.common.objects.SearchResult) ResultsHandler(org.identityconnectors.framework.common.objects.ResultsHandler) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with ExternalResource

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

the class ResourceLogic method setLatestSyncToken.

@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_UPDATE + "')")
public void setLatestSyncToken(final String key, final String anyTypeKey) {
    ExternalResource resource = resourceDAO.authFind(key);
    if (resource == null) {
        throw new NotFoundException("Resource '" + key + "'");
    }
    Connector connector;
    try {
        connector = connFactory.getConnector(resource);
    } catch (Exception e) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidConnInstance);
        sce.getElements().add(e.getMessage());
        throw sce;
    }
    if (SyncopeConstants.REALM_ANYTYPE.equals(anyTypeKey)) {
        if (resource.getOrgUnit() == null) {
            throw new NotFoundException("Realm provision not enabled for Resource '" + key + "'");
        }
        resource.getOrgUnit().setSyncToken(connector.getLatestSyncToken(resource.getOrgUnit().getObjectClass()));
    } else {
        AnyType anyType = anyTypeDAO.find(anyTypeKey);
        if (anyType == null) {
            throw new NotFoundException("AnyType '" + anyTypeKey + "'");
        }
        Optional<? extends Provision> provision = resource.getProvision(anyType);
        if (!provision.isPresent()) {
            throw new NotFoundException("Provision for AnyType '" + anyTypeKey + "' in Resource '" + key + "'");
        }
        provision.get().setSyncToken(connector.getLatestSyncToken(provision.get().getObjectClass()));
    }
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_UPDATE), resource.getConnector().getAdminRealm().getFullPath());
    securityChecks(effectiveRealms, resource.getConnector().getAdminRealm().getFullPath(), resource.getKey());
    resourceDAO.save(resource);
}
Also used : Connector(org.apache.syncope.core.provisioning.api.Connector) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 18 with ExternalResource

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

the class ResourceLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_DELETE + "')")
public ResourceTO delete(final String key) {
    ExternalResource resource = resourceDAO.authFind(key);
    if (resource == null) {
        throw new NotFoundException("Resource '" + key + "'");
    }
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_DELETE), resource.getConnector().getAdminRealm().getFullPath());
    securityChecks(effectiveRealms, resource.getConnector().getAdminRealm().getFullPath(), resource.getKey());
    ResourceTO resourceToDelete = binder.getResourceTO(resource);
    resourceDAO.delete(key);
    return resourceToDelete;
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 19 with ExternalResource

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

the class ResourceLogic method removeSyncToken.

@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_UPDATE + "')")
public void removeSyncToken(final String key, final String anyTypeKey) {
    ExternalResource resource = resourceDAO.authFind(key);
    if (resource == null) {
        throw new NotFoundException("Resource '" + key + "'");
    }
    if (SyncopeConstants.REALM_ANYTYPE.equals(anyTypeKey)) {
        if (resource.getOrgUnit() == null) {
            throw new NotFoundException("Realm provision not enabled for Resource '" + key + "'");
        }
        resource.getOrgUnit().setSyncToken(null);
    } else {
        AnyType anyType = anyTypeDAO.find(anyTypeKey);
        if (anyType == null) {
            throw new NotFoundException("AnyType '" + anyTypeKey + "'");
        }
        Optional<? extends Provision> provision = resource.getProvision(anyType);
        if (!provision.isPresent()) {
            throw new NotFoundException("Provision for AnyType '" + anyTypeKey + "' in Resource '" + key + "'");
        }
        provision.get().setSyncToken(null);
    }
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_UPDATE), resource.getConnector().getAdminRealm().getFullPath());
    securityChecks(effectiveRealms, resource.getConnector().getAdminRealm().getFullPath(), resource.getKey());
    resourceDAO.save(resource);
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 20 with ExternalResource

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

the class ResourceLogic method update.

@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_UPDATE + "')")
public ResourceTO update(final ResourceTO resourceTO) {
    ExternalResource resource = resourceDAO.authFind(resourceTO.getKey());
    if (resource == null) {
        throw new NotFoundException("Resource '" + resourceTO.getKey() + "'");
    }
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_UPDATE), resource.getConnector().getAdminRealm().getFullPath());
    securityChecks(effectiveRealms, resource.getConnector().getAdminRealm().getFullPath(), resource.getKey());
    return binder.getResourceTO(resourceDAO.save(binder.update(resource, resourceTO)));
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)59 Test (org.junit.jupiter.api.Test)30 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)28 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)23 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)21 ConnInstance (org.apache.syncope.core.persistence.api.entity.ConnInstance)15 List (java.util.List)14 Collectors (java.util.stream.Collectors)14 HashSet (java.util.HashSet)13 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 Set (java.util.Set)12 Transactional (org.springframework.transaction.annotation.Transactional)12 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)10 ExternalResourceDAO (org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO)10 Collections (java.util.Collections)9 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)9 Realm (org.apache.syncope.core.persistence.api.entity.Realm)9 PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)9 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)8