Search in sources :

Example 11 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class PolicyDataBinderImpl method getPolicy.

@SuppressWarnings("unchecked")
private <T extends Policy> T getPolicy(final T policy, final PolicyTO policyTO) {
    T result = policy;
    if (policyTO instanceof PasswordPolicyTO) {
        if (result == null) {
            result = (T) entityFactory.newEntity(PasswordPolicy.class);
        }
        PasswordPolicy passwordPolicy = PasswordPolicy.class.cast(result);
        PasswordPolicyTO passwordPolicyTO = PasswordPolicyTO.class.cast(policyTO);
        passwordPolicy.setAllowNullPassword(passwordPolicyTO.isAllowNullPassword());
        passwordPolicy.setHistoryLength(passwordPolicyTO.getHistoryLength());
        passwordPolicyTO.getRules().forEach(ruleKey -> {
            Implementation rule = implementationDAO.find(ruleKey);
            if (rule == null) {
                LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", ruleKey);
            } else {
                passwordPolicy.add(rule);
            }
        });
        // remove all implementations not contained in the TO
        passwordPolicy.getRules().removeIf(implementation -> !passwordPolicyTO.getRules().contains(implementation.getKey()));
    } else if (policyTO instanceof AccountPolicyTO) {
        if (result == null) {
            result = (T) entityFactory.newEntity(AccountPolicy.class);
        }
        AccountPolicy accountPolicy = AccountPolicy.class.cast(result);
        AccountPolicyTO accountPolicyTO = AccountPolicyTO.class.cast(policyTO);
        accountPolicy.setMaxAuthenticationAttempts(accountPolicyTO.getMaxAuthenticationAttempts());
        accountPolicy.setPropagateSuspension(accountPolicyTO.isPropagateSuspension());
        accountPolicyTO.getRules().forEach(ruleKey -> {
            Implementation rule = implementationDAO.find(ruleKey);
            if (rule == null) {
                LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", ruleKey);
            } else {
                accountPolicy.add(rule);
            }
        });
        // remove all implementations not contained in the TO
        accountPolicy.getRules().removeIf(implementation -> !accountPolicyTO.getRules().contains(implementation.getKey()));
        accountPolicy.getResources().clear();
        accountPolicyTO.getPassthroughResources().forEach(resourceName -> {
            ExternalResource resource = resourceDAO.find(resourceName);
            if (resource == null) {
                LOG.debug("Ignoring invalid resource {} ", resourceName);
            } else {
                accountPolicy.add(resource);
            }
        });
    } else if (policyTO instanceof PullPolicyTO) {
        if (result == null) {
            result = (T) entityFactory.newEntity(PullPolicy.class);
        }
        PullPolicy pullPolicy = PullPolicy.class.cast(result);
        PullPolicyTO pullPolicyTO = PullPolicyTO.class.cast(policyTO);
        pullPolicy.setConflictResolutionAction(pullPolicyTO.getConflictResolutionAction());
        pullPolicyTO.getCorrelationRules().forEach((type, impl) -> {
            AnyType anyType = anyTypeDAO.find(type);
            if (anyType == null) {
                LOG.debug("Invalid AnyType {} specified, ignoring...", type);
            } else {
                CorrelationRule correlationRule = pullPolicy.getCorrelationRule(anyType).orElse(null);
                if (correlationRule == null) {
                    correlationRule = entityFactory.newEntity(CorrelationRule.class);
                    correlationRule.setAnyType(anyType);
                    correlationRule.setPullPolicy(pullPolicy);
                    pullPolicy.add(correlationRule);
                }
                Implementation rule = implementationDAO.find(impl);
                if (rule == null) {
                    throw new NotFoundException("Implementation " + type);
                }
                correlationRule.setImplementation(rule);
            }
        });
        // remove all rules not contained in the TO
        pullPolicy.getCorrelationRules().removeIf(anyFilter -> !pullPolicyTO.getCorrelationRules().containsKey(anyFilter.getAnyType().getKey()));
    }
    if (result != null) {
        result.setDescription(policyTO.getDescription());
    }
    return result;
}
Also used : PullPolicy(org.apache.syncope.core.persistence.api.entity.policy.PullPolicy) Realm(org.apache.syncope.core.persistence.api.entity.Realm) LoggerFactory(org.slf4j.LoggerFactory) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) PolicyDataBinder(org.apache.syncope.core.provisioning.api.data.PolicyDataBinder) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) PolicyTO(org.apache.syncope.common.lib.policy.PolicyTO) PasswordPolicyTO(org.apache.syncope.common.lib.policy.PasswordPolicyTO) Logger(org.slf4j.Logger) Policy(org.apache.syncope.core.persistence.api.entity.policy.Policy) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) Component(org.springframework.stereotype.Component) CorrelationRule(org.apache.syncope.core.persistence.api.entity.policy.CorrelationRule) AccountPolicyTO(org.apache.syncope.common.lib.policy.AccountPolicyTO) PullPolicyTO(org.apache.syncope.common.lib.policy.PullPolicyTO) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) PullPolicyTO(org.apache.syncope.common.lib.policy.PullPolicyTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) AccountPolicyTO(org.apache.syncope.common.lib.policy.AccountPolicyTO) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) PullPolicy(org.apache.syncope.core.persistence.api.entity.policy.PullPolicy) CorrelationRule(org.apache.syncope.core.persistence.api.entity.policy.CorrelationRule) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) PasswordPolicyTO(org.apache.syncope.common.lib.policy.PasswordPolicyTO)

Example 12 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class ConnIdBundleManagerImpl method initLocal.

private void initLocal(final URI location) {
    // 1. Find bundles inside local directory
    File bundleDirectory = new File(location);
    String[] bundleFiles = bundleDirectory.list();
    if (bundleFiles == null) {
        throw new NotFoundException("Local bundles directory " + location);
    }
    List<URL> bundleFileURLs = new ArrayList<>();
    for (String file : bundleFiles) {
        try {
            bundleFileURLs.add(IOUtil.makeURL(bundleDirectory, file));
        } catch (IOException ignore) {
            // ignore exception and don't add bundle
            LOG.debug("{}/{} is not a valid connector bundle", bundleDirectory.toString(), file, ignore);
        }
    }
    if (bundleFileURLs.isEmpty()) {
        LOG.warn("No connector bundles found in {}", location);
    }
    LOG.debug("Configuring local connector server:" + "\n\tFiles: {}", bundleFileURLs);
    // 2. Get connector info manager
    ConnectorInfoManager manager = ConnectorInfoManagerFactory.getInstance().getLocalManager(bundleFileURLs.toArray(new URL[bundleFileURLs.size()]));
    if (manager == null) {
        throw new NotFoundException("Local ConnectorInfoManager");
    }
    connInfoManagers.put(location, manager);
}
Also used : ConnectorInfoManager(org.identityconnectors.framework.api.ConnectorInfoManager) ArrayList(java.util.ArrayList) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) GuardedString(org.identityconnectors.common.security.GuardedString) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 13 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class ConnIdBundleManagerImpl method getConnectorInfo.

@Override
public Pair<URI, ConnectorInfo> getConnectorInfo(final ConnInstance connInstance) {
    // check ConnIdLocation
    URI uriLocation = null;
    try {
        uriLocation = URIUtils.buildForConnId(connInstance.getLocation());
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid ConnId location " + connInstance.getLocation(), e);
    }
    // create key for search all properties
    ConnectorKey key = new ConnectorKey(connInstance.getBundleName(), connInstance.getVersion(), connInstance.getConnectorName());
    if (LOG.isDebugEnabled()) {
        LOG.debug("\nBundle name: " + key.getBundleName() + "\nBundle version: " + key.getBundleVersion() + "\nBundle class: " + key.getConnectorName());
    }
    // get the specified connector
    ConnectorInfo info = null;
    if (getConnManagers().containsKey(uriLocation)) {
        info = getConnManagers().get(uriLocation).findConnectorInfo(key);
    }
    if (info == null) {
        throw new NotFoundException("ConnectorInfo for location " + connInstance.getLocation() + " and key " + key);
    }
    return Pair.of(uriLocation, info);
}
Also used : ConnectorKey(org.identityconnectors.framework.api.ConnectorKey) ConnectorInfo(org.identityconnectors.framework.api.ConnectorInfo) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) URI(java.net.URI) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException)

Example 14 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException 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 15 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class ResourceLogic method check.

@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_READ + "')")
@Transactional(readOnly = true)
public void check(final ResourceTO resourceTO) {
    ConnInstance connInstance = connInstanceDAO.find(resourceTO.getConnector());
    if (connInstance == null) {
        throw new NotFoundException("Connector '" + resourceTO.getConnector() + "'");
    }
    connFactory.createConnector(connFactory.buildConnInstanceOverride(connInstanceDataBinder.getConnInstanceTO(connInstance), resourceTO.getConfOverride(), resourceTO.isOverrideCapabilities() ? resourceTO.getCapabilitiesOverride() : null)).test();
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)110 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)87 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)41 Transactional (org.springframework.transaction.annotation.Transactional)21 Date (java.util.Date)12 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)10 SchedulerException (org.quartz.SchedulerException)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)8 Report (org.apache.syncope.core.persistence.api.entity.Report)8 SchedTask (org.apache.syncope.core.persistence.api.entity.task.SchedTask)8 User (org.apache.syncope.core.persistence.api.entity.user.User)8 HashMap (java.util.HashMap)7 Collectors (java.util.stream.Collectors)7 Pair (org.apache.commons.lang3.tuple.Pair)7 ExecTO (org.apache.syncope.common.lib.to.ExecTO)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 StringUtils (org.apache.commons.lang3.StringUtils)6 DuplicateException (org.apache.syncope.core.persistence.api.dao.DuplicateException)6