Search in sources :

Example 6 with ConnInstance

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

Example 7 with ConnInstance

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

the class ConnectorLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_DELETE + "')")
public ConnInstanceTO delete(final String key) {
    ConnInstance connInstance = connInstanceDAO.authFind(key);
    if (connInstance == null) {
        throw new NotFoundException("Connector '" + key + "'");
    }
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.CONNECTOR_DELETE), connInstance.getAdminRealm().getFullPath());
    securityChecks(effectiveRealms, connInstance.getAdminRealm().getFullPath(), connInstance.getKey());
    if (!connInstance.getResources().isEmpty()) {
        SyncopeClientException associatedResources = SyncopeClientException.build(ClientExceptionType.AssociatedResources);
        connInstance.getResources().forEach(resource -> {
            associatedResources.getElements().add(resource.getKey());
        });
        throw associatedResources;
    }
    ConnInstanceTO deleted = binder.getConnInstanceTO(connInstance);
    connInstanceDAO.delete(key);
    return deleted;
}
Also used : ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) 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)

Example 8 with ConnInstance

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

the class ConnectorLogic method buildObjectClassInfo.

@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_READ + "')")
public List<ConnIdObjectClassTO> buildObjectClassInfo(final ConnInstanceTO connInstanceTO, final boolean includeSpecial) {
    ConnInstanceTO actual = connInstanceTO;
    ConnInstance existing = connInstanceDAO.find(connInstanceTO.getKey());
    if (existing != null) {
        actual = binder.getConnInstanceTO(existing);
    }
    Set<ObjectClassInfo> objectClassInfo = connFactory.createConnector(connFactory.buildConnInstanceOverride(actual, connInstanceTO.getConf(), null)).getObjectClassInfo();
    return objectClassInfo.stream().map(info -> {
        ConnIdObjectClassTO connIdObjectClassTO = new ConnIdObjectClassTO();
        connIdObjectClassTO.setType(info.getType());
        connIdObjectClassTO.setAuxiliary(info.isAuxiliary());
        connIdObjectClassTO.setContainer(info.isContainer());
        connIdObjectClassTO.getAttributes().addAll(info.getAttributeInfo().stream().filter(attrInfo -> includeSpecial || !AttributeUtil.isSpecialName(attrInfo.getName())).map(AttributeInfo::getName).collect(Collectors.toList()));
        return connIdObjectClassTO;
    }).collect(Collectors.toList());
}
Also used : StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayUtils(org.apache.commons.lang3.ArrayUtils) ConfigurationProperties(org.identityconnectors.framework.api.ConfigurationProperties) StringUtils(org.apache.commons.lang3.StringUtils) 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) Locale(java.util.Locale) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Method(java.lang.reflect.Method) AttributeInfo(org.identityconnectors.framework.common.objects.AttributeInfo) ConnectorKey(org.identityconnectors.framework.api.ConnectorKey) Set(java.util.Set) ConnInstanceDAO(org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO) ConnIdObjectClassTO(org.apache.syncope.common.lib.to.ConnIdObjectClassTO) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) CurrentLocale(org.identityconnectors.common.l10n.CurrentLocale) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) ObjectClassInfo(org.identityconnectors.framework.common.objects.ObjectClassInfo) Component(org.springframework.stereotype.Component) AttributeUtil(org.identityconnectors.framework.common.objects.AttributeUtil) ConnIdBundleManager(org.apache.syncope.core.provisioning.api.ConnIdBundleManager) ConnectorFactory(org.apache.syncope.core.provisioning.api.ConnectorFactory) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) ConnBundleTO(org.apache.syncope.common.lib.to.ConnBundleTO) Transactional(org.springframework.transaction.annotation.Transactional) ConnIdObjectClassTO(org.apache.syncope.common.lib.to.ConnIdObjectClassTO) ObjectClassInfo(org.identityconnectors.framework.common.objects.ObjectClassInfo) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 9 with ConnInstance

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

the class ConnectorLogic method read.

@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_READ + "')")
@Transactional(readOnly = true)
public ConnInstanceTO read(final String key, final String lang) {
    CurrentLocale.set(StringUtils.isBlank(lang) ? Locale.ENGLISH : new Locale(lang));
    ConnInstance connInstance = connInstanceDAO.authFind(key);
    if (connInstance == null) {
        throw new NotFoundException("Connector '" + key + "'");
    }
    return binder.getConnInstanceTO(connInstance);
}
Also used : Locale(java.util.Locale) CurrentLocale(org.identityconnectors.common.l10n.CurrentLocale) 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)

Example 10 with ConnInstance

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

the class ResourceTest method createWithPasswordPolicy.

@Test
public void createWithPasswordPolicy() {
    final String resourceName = "resourceWithPasswordPolicy";
    PasswordPolicy policy = policyDAO.find("986d1236-3ac5-4a19-810c-5ab21d79cba1");
    ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
    resource.setKey(resourceName);
    resource.setPasswordPolicy(policy);
    ConnInstance connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
    assertNotNull(connector);
    resource.setConnector(connector);
    ExternalResource actual = resourceDAO.save(resource);
    assertNotNull(actual);
    actual = resourceDAO.find(actual.getKey());
    assertNotNull(actual);
    assertNotNull(actual.getPasswordPolicy());
    resourceDAO.delete(resourceName);
    assertNull(resourceDAO.find(resourceName));
    assertNotNull(policyDAO.find("986d1236-3ac5-4a19-810c-5ab21d79cba1"));
}
Also used : PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) 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