Search in sources :

Example 1 with ConnInstance

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

the class JPAConnInstanceDAO method save.

@Override
public ConnInstance save(final ConnInstance connector) {
    final ConnInstance merged = entityManager().merge(connector);
    merged.getResources().forEach(resource -> {
        try {
            connRegistry.registerConnector(resource);
        } catch (NotFoundException e) {
            LOG.error("While registering connector for resource", e);
        }
    });
    return merged;
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) JPAConnInstance(org.apache.syncope.core.persistence.jpa.entity.JPAConnInstance)

Example 2 with ConnInstance

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

the class LDAPPasswordPropagationActions method before.

@Transactional(readOnly = true)
@Override
public void before(final PropagationTask task, final ConnectorObject beforeObj) {
    if (AnyTypeKind.USER == task.getAnyTypeKind()) {
        User user = userDAO.find(task.getEntityKey());
        if (user != null && user.getPassword() != null) {
            Attribute missing = AttributeUtil.find(PropagationTaskExecutor.MANDATORY_MISSING_ATTR_NAME, task.getAttributes());
            ConnInstance connInstance = task.getResource().getConnector();
            String cipherAlgorithm = getCipherAlgorithm(connInstance);
            if (missing != null && missing.getValue() != null && missing.getValue().size() == 1 && missing.getValue().get(0).equals(OperationalAttributes.PASSWORD_NAME) && cipherAlgorithmMatches(getCipherAlgorithm(connInstance), user.getCipherAlgorithm())) {
                String password = user.getPassword().toLowerCase();
                byte[] decodedPassword = DatatypeConverter.parseHexBinary(password);
                String base64EncodedPassword = Base64.getEncoder().encodeToString(decodedPassword);
                String cipherPlusPassword = ("{" + cipherAlgorithm.toLowerCase() + "}" + base64EncodedPassword);
                Attribute passwordAttribute = AttributeBuilder.buildPassword(new GuardedString(cipherPlusPassword.toCharArray()));
                Set<Attribute> attributes = new HashSet<>(task.getAttributes());
                attributes.add(passwordAttribute);
                attributes.remove(missing);
                task.setAttributes(attributes);
            }
        }
    }
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) Attribute(org.identityconnectors.framework.common.objects.Attribute) GuardedString(org.identityconnectors.common.security.GuardedString) GuardedString(org.identityconnectors.common.security.GuardedString) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ConnInstance

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

the class ConnectorManager method registerConnector.

@Override
public void registerConnector(final ExternalResource resource) {
    ConnInstance connInstance = buildConnInstanceOverride(connInstanceDataBinder.getConnInstanceTO(resource.getConnector()), resource.getConfOverride(), resource.isOverrideCapabilities() ? resource.getCapabilitiesOverride() : null);
    Connector connector = createConnector(connInstance);
    LOG.debug("Connector to be registered: {}", connector);
    String beanName = getBeanName(resource);
    if (ApplicationContextProvider.getBeanFactory().containsSingleton(beanName)) {
        unregisterConnector(beanName);
    }
    ApplicationContextProvider.getBeanFactory().registerSingleton(beanName, connector);
    LOG.debug("Successfully registered bean {}", beanName);
}
Also used : Connector(org.apache.syncope.core.provisioning.api.Connector) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance)

Example 4 with ConnInstance

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

the class ConnInstanceDataBinderImpl method getConnInstance.

@Override
public ConnInstance getConnInstance(final ConnInstanceTO connInstanceTO) {
    SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
    if (connInstanceTO.getLocation() == null) {
        sce.getElements().add("location");
    }
    if (connInstanceTO.getBundleName() == null) {
        sce.getElements().add("bundlename");
    }
    if (connInstanceTO.getVersion() == null) {
        sce.getElements().add("bundleversion");
    }
    if (connInstanceTO.getConnectorName() == null) {
        sce.getElements().add("connectorname");
    }
    if (connInstanceTO.getConf().isEmpty()) {
        sce.getElements().add("configuration");
    }
    ConnInstance connInstance = entityFactory.newEntity(ConnInstance.class);
    BeanUtils.copyProperties(connInstanceTO, connInstance, IGNORE_PROPERTIES);
    if (connInstanceTO.getAdminRealm() != null) {
        connInstance.setAdminRealm(realmDAO.findByFullPath(connInstanceTO.getAdminRealm()));
    }
    if (connInstance.getAdminRealm() == null) {
        sce.getElements().add("Invalid or null realm specified: " + connInstanceTO.getAdminRealm());
    }
    if (connInstanceTO.getLocation() != null) {
        connInstance.setLocation(connInstanceTO.getLocation());
    }
    connInstance.setConf(connInstanceTO.getConf());
    if (connInstanceTO.getPoolConf() != null) {
        connInstance.setPoolConf(ConnPoolConfUtils.getConnPoolConf(connInstanceTO.getPoolConf(), entityFactory.newConnPoolConf()));
    }
    // Throw exception if there is at least one element set
    if (!sce.isEmpty()) {
        throw sce;
    }
    return connInstance;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance)

Example 5 with ConnInstance

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

the class ResourceDataBinderImpl method getResourceTO.

@Override
public ResourceTO getResourceTO(final ExternalResource resource) {
    ResourceTO resourceTO = new ResourceTO();
    // set the resource name
    resourceTO.setKey(resource.getKey());
    // set the connector instance
    ConnInstance connector = resource.getConnector();
    resourceTO.setConnector(connector == null ? null : connector.getKey());
    resourceTO.setConnectorDisplayName(connector == null ? null : connector.getDisplayName());
    // set the provision information
    resource.getProvisions().stream().map(provision -> {
        ProvisionTO provisionTO = new ProvisionTO();
        provisionTO.setKey(provision.getKey());
        provisionTO.setAnyType(provision.getAnyType().getKey());
        provisionTO.setObjectClass(provision.getObjectClass().getObjectClassValue());
        provisionTO.getAuxClasses().addAll(provision.getAuxClasses().stream().map(cls -> cls.getKey()).collect(Collectors.toList()));
        provisionTO.setSyncToken(provision.getSerializedSyncToken());
        if (provision.getMapping() != null) {
            MappingTO mappingTO = new MappingTO();
            provisionTO.setMapping(mappingTO);
            mappingTO.setConnObjectLink(provision.getMapping().getConnObjectLink());
            populateItems(provision.getMapping().getItems(), mappingTO);
        }
        virSchemaDAO.findByProvision(provision).forEach(virSchema -> {
            provisionTO.getVirSchemas().add(virSchema.getKey());
            MappingItem linkingMappingItem = virSchema.asLinkingMappingItem();
            ItemTO itemTO = new ItemTO();
            itemTO.setKey(linkingMappingItem.getKey());
            BeanUtils.copyProperties(linkingMappingItem, itemTO, ITEM_IGNORE_PROPERTIES);
            provisionTO.getMapping().getLinkingItems().add(itemTO);
        });
        return provisionTO;
    }).forEachOrdered(provisionTO -> {
        resourceTO.getProvisions().add(provisionTO);
    });
    if (resource.getOrgUnit() != null) {
        OrgUnit orgUnit = resource.getOrgUnit();
        OrgUnitTO orgUnitTO = new OrgUnitTO();
        orgUnitTO.setKey(orgUnit.getKey());
        orgUnitTO.setObjectClass(orgUnit.getObjectClass().getObjectClassValue());
        orgUnitTO.setSyncToken(orgUnit.getSerializedSyncToken());
        orgUnitTO.setConnObjectLink(orgUnit.getConnObjectLink());
        populateItems(orgUnit.getItems(), orgUnitTO);
        resourceTO.setOrgUnit(orgUnitTO);
    }
    resourceTO.setEnforceMandatoryCondition(resource.isEnforceMandatoryCondition());
    resourceTO.setPropagationPriority(resource.getPropagationPriority());
    resourceTO.setRandomPwdIfNotProvided(resource.isRandomPwdIfNotProvided());
    resourceTO.setCreateTraceLevel(resource.getCreateTraceLevel());
    resourceTO.setUpdateTraceLevel(resource.getUpdateTraceLevel());
    resourceTO.setDeleteTraceLevel(resource.getDeleteTraceLevel());
    resourceTO.setProvisioningTraceLevel(resource.getProvisioningTraceLevel());
    resourceTO.setPasswordPolicy(resource.getPasswordPolicy() == null ? null : resource.getPasswordPolicy().getKey());
    resourceTO.setAccountPolicy(resource.getAccountPolicy() == null ? null : resource.getAccountPolicy().getKey());
    resourceTO.setPullPolicy(resource.getPullPolicy() == null ? null : resource.getPullPolicy().getKey());
    resourceTO.getConfOverride().addAll(resource.getConfOverride());
    Collections.sort(resourceTO.getConfOverride());
    resourceTO.setOverrideCapabilities(resource.isOverrideCapabilities());
    resourceTO.getCapabilitiesOverride().addAll(resource.getCapabilitiesOverride());
    resourceTO.getPropagationActions().addAll(resource.getPropagationActions().stream().map(Entity::getKey).collect(Collectors.toList()));
    return resourceTO;
}
Also used : ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PullPolicy(org.apache.syncope.core.persistence.api.entity.policy.PullPolicy) Date(java.util.Date) 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) JexlUtils(org.apache.syncope.core.provisioning.java.jexl.JexlUtils) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) ParseException(java.text.ParseException) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) MappingTO(org.apache.syncope.common.lib.to.MappingTO) OrgUnitItem(org.apache.syncope.core.persistence.api.entity.resource.OrgUnitItem) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) SchemaType(org.apache.syncope.common.lib.types.SchemaType) ConnInstanceDAO(org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO) ResourceDataBinder(org.apache.syncope.core.provisioning.api.data.ResourceDataBinder) Collectors(java.util.stream.Collectors) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PolicyDAO(org.apache.syncope.core.persistence.api.dao.PolicyDAO) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) ExternalResourceHistoryConfDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceHistoryConfDAO) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) ResourceHistoryConfTO(org.apache.syncope.common.lib.to.ResourceHistoryConfTO) BeanUtils(org.apache.syncope.core.spring.BeanUtils) HashSet(java.util.HashSet) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ItemTO(org.apache.syncope.common.lib.to.ItemTO) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Item(org.apache.syncope.core.persistence.api.entity.resource.Item) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ItemContainerTO(org.apache.syncope.common.lib.to.ItemContainerTO) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) ExternalResourceHistoryConf(org.apache.syncope.core.persistence.api.entity.resource.ExternalResourceHistoryConf) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Component(org.springframework.stereotype.Component) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) OrgUnitTO(org.apache.syncope.common.lib.to.OrgUnitTO) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) IntAttrNameParser(org.apache.syncope.core.provisioning.java.IntAttrNameParser) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) Entity(org.apache.syncope.core.persistence.api.entity.Entity) MappingTO(org.apache.syncope.common.lib.to.MappingTO) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) OrgUnitTO(org.apache.syncope.common.lib.to.OrgUnitTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance)

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