Search in sources :

Example 16 with ConnInstanceTO

use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.

the class TopologyTogglePanel method getConnectorFragment.

private Fragment getConnectorFragment(final TopologyNode node, final PageReference pageRef) {
    Fragment fragment = new Fragment("actions", "connectorActions", this);
    AjaxLink<String> delete = new IndicatingOnConfirmAjaxLink<String>("delete", true) {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            try {
                connectorRestClient.delete(String.class.cast(node.getKey()));
                target.appendJavaScript(String.format("jsPlumb.remove('%s');", node.getKey()));
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                toggle(target, false);
            } catch (SyncopeClientException e) {
                LOG.error("While deleting resource {}", node.getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(delete, RENDER, StandardEntitlement.CONNECTOR_DELETE);
    fragment.add(delete);
    AjaxLink<String> create = new IndicatingAjaxLink<String>("create") {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            final ResourceTO modelObject = new ResourceTO();
            modelObject.setConnector(String.class.cast(node.getKey()));
            modelObject.setConnectorDisplayName(node.getDisplayName());
            final IModel<ResourceTO> model = new CompoundPropertyModel<>(modelObject);
            modal.setFormModel(model);
            target.add(modal.setContent(new ResourceWizardBuilder(modelObject, pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.CREATE)));
            modal.header(new Model<>(MessageFormat.format(getString("resource.new"), node.getKey())));
            modal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(create, RENDER, StandardEntitlement.RESOURCE_CREATE);
    fragment.add(create);
    AjaxLink<String> edit = new IndicatingAjaxLink<String>("edit") {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            ConnInstanceTO connInstance = connectorRestClient.read(String.class.cast(node.getKey()));
            final IModel<ConnInstanceTO> model = new CompoundPropertyModel<>(connInstance);
            modal.setFormModel(model);
            target.add(modal.setContent(new ConnectorWizardBuilder(connInstance, pageRef).build(BaseModal.CONTENT_ID, SyncopeConsoleSession.get().owns(StandardEntitlement.CONNECTOR_UPDATE, connInstance.getAdminRealm()) ? AjaxWizard.Mode.EDIT : AjaxWizard.Mode.READONLY)));
            modal.header(new Model<>(MessageFormat.format(getString("connector.edit"), connInstance.getDisplayName())));
            modal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(edit, RENDER, StandardEntitlement.CONNECTOR_READ);
    fragment.add(edit);
    AjaxLink<String> history = new IndicatingAjaxLink<String>("history") {

        private static final long serialVersionUID = -1876519166660008562L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            String connKey = String.class.cast(node.getKey());
            ConnInstanceTO connInstance = connectorRestClient.read(connKey);
            target.add(historyModal.setContent(new HistoryConfList<>(historyModal, connKey, pageRef, connInstance)));
            historyModal.header(new Model<>(MessageFormat.format(getString("connector.menu.history"), node.getDisplayName())));
            historyModal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(history, RENDER, StandardEntitlement.CONNECTOR_HISTORY_LIST);
    fragment.add(history);
    return fragment;
}
Also used : HistoryConfList(org.apache.syncope.client.console.panels.HistoryConfList) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) IndicatingOnConfirmAjaxLink(org.apache.syncope.client.console.wicket.markup.html.form.IndicatingOnConfirmAjaxLink) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Fragment(org.apache.wicket.markup.html.panel.Fragment) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ConnectorWizardBuilder(org.apache.syncope.client.console.wizards.resources.ConnectorWizardBuilder) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) AbstractResourceWizardBuilder(org.apache.syncope.client.console.wizards.resources.AbstractResourceWizardBuilder) ResourceWizardBuilder(org.apache.syncope.client.console.wizards.resources.ResourceWizardBuilder) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO)

Example 17 with ConnInstanceTO

use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.

the class TopologyTogglePanel method getLocationFragment.

private Fragment getLocationFragment(final TopologyNode node, final PageReference pageRef) {
    Fragment fragment = new Fragment("actions", "locationActions", this);
    AjaxLink<String> create = new IndicatingAjaxLink<String>("create") {

        private static final long serialVersionUID = 3776750333491622263L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            final ConnInstanceTO modelObject = new ConnInstanceTO();
            modelObject.setLocation(node.getKey());
            final IModel<ConnInstanceTO> model = new CompoundPropertyModel<>(modelObject);
            modal.setFormModel(model);
            target.add(modal.setContent(new ConnectorWizardBuilder(modelObject, pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.CREATE)));
            modal.header(new Model<>(MessageFormat.format(getString("connector.new"), node.getKey())));
            modal.show(true);
        }

        @Override
        public String getAjaxIndicatorMarkupId() {
            return Constants.VEIL_INDICATOR_MARKUP_ID;
        }
    };
    fragment.add(create);
    MetaDataRoleAuthorizationStrategy.authorize(create, RENDER, StandardEntitlement.CONNECTOR_CREATE);
    return fragment;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) ConnectorWizardBuilder(org.apache.syncope.client.console.wizards.resources.ConnectorWizardBuilder) IndicatingAjaxLink(org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) Fragment(org.apache.wicket.markup.html.panel.Fragment)

Example 18 with ConnInstanceTO

use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.

the class ConnInstanceDataBinderImpl method getConnInstanceTO.

@Override
public ConnInstanceTO getConnInstanceTO(final ConnInstance connInstance) {
    ConnInstanceTO connInstanceTO = new ConnInstanceTO();
    Pair<URI, ConnectorInfo> info = connIdBundleManager.getConnectorInfo(connInstance);
    BeanUtils.copyProperties(connInstance, connInstanceTO, IGNORE_PROPERTIES);
    connInstanceTO.setAdminRealm(connInstance.getAdminRealm().getFullPath());
    connInstanceTO.setLocation(info.getLeft().toASCIIString());
    connInstanceTO.getConf().addAll(connInstance.getConf());
    // refresh stored properties in the given connInstance with direct information from underlying connector
    ConfigurationProperties properties = connIdBundleManager.getConfigurationProperties(info.getRight());
    properties.getPropertyNames().forEach(propName -> {
        ConnConfPropSchema schema = build(properties.getProperty(propName));
        Optional<ConnConfProperty> property = connInstanceTO.getConf(propName);
        if (!property.isPresent()) {
            property = Optional.of(new ConnConfProperty());
            connInstanceTO.getConf().add(property.get());
        }
        property.get().setSchema(schema);
    });
    Collections.sort(connInstanceTO.getConf());
    // pool configuration
    if (connInstance.getPoolConf() != null && (connInstance.getPoolConf().getMaxIdle() != null || connInstance.getPoolConf().getMaxObjects() != null || connInstance.getPoolConf().getMaxWait() != null || connInstance.getPoolConf().getMinEvictableIdleTimeMillis() != null || connInstance.getPoolConf().getMinIdle() != null)) {
        ConnPoolConfTO poolConf = new ConnPoolConfTO();
        BeanUtils.copyProperties(connInstance.getPoolConf(), poolConf);
        connInstanceTO.setPoolConf(poolConf);
    }
    return connInstanceTO;
}
Also used : ConnectorInfo(org.identityconnectors.framework.api.ConnectorInfo) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) ConfigurationProperties(org.identityconnectors.framework.api.ConfigurationProperties) ConnPoolConfTO(org.apache.syncope.common.lib.to.ConnPoolConfTO) URI(java.net.URI) ConnConfPropSchema(org.apache.syncope.common.lib.types.ConnConfPropSchema)

Example 19 with ConnInstanceTO

use of org.apache.syncope.common.lib.to.ConnInstanceTO 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 20 with ConnInstanceTO

use of org.apache.syncope.common.lib.to.ConnInstanceTO 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)

Aggregations

ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)42 Test (org.junit.jupiter.api.Test)21 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)15 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)14 ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)14 ConnectorService (org.apache.syncope.common.rest.api.service.ConnectorService)11 Response (javax.ws.rs.core.Response)10 HashSet (java.util.HashSet)8 ConnConfPropSchema (org.apache.syncope.common.lib.types.ConnConfPropSchema)8 GuardedString (org.identityconnectors.common.security.GuardedString)8 IOException (java.io.IOException)7 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 ConnBundleTO (org.apache.syncope.common.lib.to.ConnBundleTO)6 ConnPoolConfTO (org.apache.syncope.common.lib.to.ConnPoolConfTO)6 ItemTO (org.apache.syncope.common.lib.to.ItemTO)6 ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)6 Locale (java.util.Locale)5 Properties (java.util.Properties)5