Search in sources :

Example 11 with RealmTO

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

the class RealmChoicePanel method reloadRealmTree.

public final void reloadRealmTree() {
    final Label realmLabel = new Label("realmLabel", new Model<>());
    realmLabel.setOutputMarkupId(true);
    container.addOrReplace(realmLabel);
    if (model.getObject().getFullPath().startsWith(SyncopeConstants.ROOT_REALM)) {
        realmLabel.setDefaultModel(new ResourceModel("realmLabel", "Realm"));
    } else {
        realmLabel.setDefaultModel(new ResourceModel("dynRealmLabel", "Dynamic Realm"));
    }
    final Label label = new Label("realm", model.getObject().getFullPath());
    label.setOutputMarkupId(true);
    container.addOrReplace(label);
    final DropDownButton realms = new DropDownButton("realms", new ResourceModel("select", ""), new Model<IconType>(GlyphIconType.folderopen)) {

        private static final long serialVersionUID = -5560086780455361131L;

        @Override
        protected List<AbstractLink> newSubMenuButtons(final String buttonMarkupId) {
            RealmChoicePanel.this.links.clear();
            RealmChoicePanel.this.links.add(new BootstrapAjaxLink<RealmTO>(ButtonList.getButtonMarkupId(), new Model<RealmTO>(), Buttons.Type.Link, new ResourceModel("realms", "Realms")) {

                private static final long serialVersionUID = -7978723352517770744L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                }

                @Override
                public boolean isEnabled() {
                    return false;
                }

                @Override
                protected void onComponentTag(final ComponentTag tag) {
                    tag.put("class", "panel box box-primary box-header with-border");
                    tag.put("style", "margin: 20px 5px 0px 5px; width: 90%");
                }
            });
            for (Pair<String, RealmTO> link : realmTree.getObject()) {
                final RealmTO realmTO = link.getValue();
                RealmChoicePanel.this.links.add(new BootstrapAjaxLink<RealmTO>(ButtonList.getButtonMarkupId(), Model.of(realmTO), Buttons.Type.Link, new Model<>(link.getKey())) {

                    private static final long serialVersionUID = -7978723352517770644L;

                    @Override
                    public void onClick(final AjaxRequestTarget target) {
                        model.setObject(realmTO);
                        label.setDefaultModelObject(model.getObject().getFullPath());
                        realmLabel.setDefaultModel(new ResourceModel("realmLabel", "Realm"));
                        target.add(label);
                        send(pageRef.getPage(), Broadcast.EXACT, new ChosenRealm<>(realmTO, target));
                    }

                    @Override
                    public boolean isEnabled() {
                        return availableRealms.stream().anyMatch(availableRealm -> realmTO.getFullPath().startsWith(availableRealm));
                    }
                });
            }
            if (!dynRealmTree.getObject().isEmpty()) {
                RealmChoicePanel.this.links.add(new BootstrapAjaxLink<RealmTO>(ButtonList.getButtonMarkupId(), new Model<RealmTO>(), Buttons.Type.Link, new ResourceModel("dynrealms", "Dynamic Realms")) {

                    private static final long serialVersionUID = -7978723352517770744L;

                    @Override
                    public void onClick(final AjaxRequestTarget target) {
                    }

                    @Override
                    public boolean isEnabled() {
                        return false;
                    }

                    @Override
                    protected void onComponentTag(final ComponentTag tag) {
                        tag.put("class", "panel box box-primary box-header with-border");
                        tag.put("style", "margin: 20px 5px 0px 5px; width: 90%");
                    }
                });
                for (DynRealmTO dynRealmTO : dynRealmTree.getObject()) {
                    final RealmTO realmTO = new RealmTO();
                    realmTO.setKey(dynRealmTO.getKey());
                    realmTO.setName(dynRealmTO.getKey());
                    realmTO.setFullPath(dynRealmTO.getKey());
                    RealmChoicePanel.this.links.add(new BootstrapAjaxLink<RealmTO>(ButtonList.getButtonMarkupId(), new Model<RealmTO>(), Buttons.Type.Link, new Model<>(realmTO.getKey())) {

                        private static final long serialVersionUID = -7978723352517770644L;

                        @Override
                        public void onClick(final AjaxRequestTarget target) {
                            model.setObject(realmTO);
                            label.setDefaultModelObject(realmTO.getKey());
                            realmLabel.setDefaultModel(new ResourceModel("dynRealmLabel", "Dynamic Realm"));
                            target.add(label);
                            send(pageRef.getPage(), Broadcast.EXACT, new ChosenRealm<>(realmTO, target));
                        }

                        @Override
                        public boolean isEnabled() {
                            return availableRealms.stream().anyMatch(availableRealm -> {
                                return SyncopeConstants.ROOT_REALM.equals(availableRealm) || realmTO.getKey().equals(availableRealm);
                            });
                        }
                    });
                }
            }
            return RealmChoicePanel.this.links;
        }
    };
    realms.setOutputMarkupId(true);
    realms.setAlignment(AlignmentBehavior.Alignment.RIGHT);
    realms.setType(Buttons.Type.Menu);
    MetaDataRoleAuthorizationStrategy.authorize(realms, ENABLE, StandardEntitlement.REALM_LIST);
    container.addOrReplace(realms);
}
Also used : StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) DynRealmTO(org.apache.syncope.common.lib.to.DynRealmTO) RealmTO(org.apache.syncope.common.lib.to.RealmTO) Buttons(de.agilecoders.wicket.core.markup.html.bootstrap.button.Buttons) HashMap(java.util.HashMap) SyncopeConsoleSession(org.apache.syncope.client.console.SyncopeConsoleSession) IconType(de.agilecoders.wicket.core.markup.html.bootstrap.image.IconType) StringUtils(org.apache.commons.lang3.StringUtils) GlyphIconType(de.agilecoders.wicket.core.markup.html.bootstrap.image.GlyphIconType) ArrayList(java.util.ArrayList) BootstrapAjaxLink(de.agilecoders.wicket.core.markup.html.bootstrap.button.BootstrapAjaxLink) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ComponentTag(org.apache.wicket.markup.ComponentTag) AbstractLink(org.apache.wicket.markup.html.link.AbstractLink) Label(org.apache.wicket.markup.html.basic.Label) AlignmentBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.behavior.AlignmentBehavior) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) MetaDataRoleAuthorizationStrategy(org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy) ButtonList(de.agilecoders.wicket.core.markup.html.bootstrap.button.ButtonList) Collection(java.util.Collection) Model(org.apache.wicket.model.Model) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) PageReference(org.apache.wicket.PageReference) Collectors(java.util.stream.Collectors) Panel(org.apache.wicket.markup.html.panel.Panel) List(java.util.List) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) DropDownButton(de.agilecoders.wicket.core.markup.html.bootstrap.button.dropdown.DropDownButton) Comparator(java.util.Comparator) RealmRestClient(org.apache.syncope.client.console.rest.RealmRestClient) ResourceModel(org.apache.wicket.model.ResourceModel) Collections(java.util.Collections) Broadcast(org.apache.wicket.event.Broadcast) DropDownButton(de.agilecoders.wicket.core.markup.html.bootstrap.button.dropdown.DropDownButton) Label(org.apache.wicket.markup.html.basic.Label) DynRealmTO(org.apache.syncope.common.lib.to.DynRealmTO) RealmTO(org.apache.syncope.common.lib.to.RealmTO) DynRealmTO(org.apache.syncope.common.lib.to.DynRealmTO) IconType(de.agilecoders.wicket.core.markup.html.bootstrap.image.IconType) GlyphIconType(de.agilecoders.wicket.core.markup.html.bootstrap.image.GlyphIconType) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ComponentTag(org.apache.wicket.markup.ComponentTag) Model(org.apache.wicket.model.Model) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) ResourceModel(org.apache.wicket.model.ResourceModel) ResourceModel(org.apache.wicket.model.ResourceModel) AbstractLink(org.apache.wicket.markup.html.link.AbstractLink)

Example 12 with RealmTO

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

the class Realm method buildTabList.

private List<ITab> buildTabList(final PageReference pageRef) {
    List<ITab> tabs = new ArrayList<>();
    tabs.add(new ITabComponent(new Model<>("DETAILS"), StandardEntitlement.REALM_CREATE, StandardEntitlement.REALM_UPDATE, StandardEntitlement.REALM_DELETE) {

        private static final long serialVersionUID = -5861786415855103549L;

        @Override
        public Panel getPanel(final String panelId) {
            final ActionsPanel<RealmTO> actionPanel = new ActionsPanel<>("actions", null);
            if (realmTO.getFullPath().startsWith(SyncopeConstants.ROOT_REALM)) {
                actionPanel.add(new ActionLink<RealmTO>(realmTO) {

                    private static final long serialVersionUID = 2802988981431379827L;

                    @Override
                    public void onClick(final AjaxRequestTarget target, final RealmTO ignore) {
                        onClickCreate(target);
                    }
                }, ActionLink.ActionType.CREATE, StandardEntitlement.REALM_CREATE).hideLabel();
                actionPanel.add(new ActionLink<RealmTO>(realmTO) {

                    private static final long serialVersionUID = 2802988981431379828L;

                    @Override
                    public void onClick(final AjaxRequestTarget target, final RealmTO ignore) {
                        onClickEdit(target, realmTO);
                    }
                }, ActionLink.ActionType.EDIT, StandardEntitlement.REALM_UPDATE).hideLabel();
                actionPanel.add(new ActionLink<RealmTO>(realmTO) {

                    private static final long serialVersionUID = 2802988981431379827L;

                    @Override
                    public void onClick(final AjaxRequestTarget target, final RealmTO ignore) {
                        onClickTemplate(target);
                    }
                }, ActionLink.ActionType.TEMPLATE, StandardEntitlement.REALM_UPDATE).hideLabel();
                actionPanel.add(new ActionLink<RealmTO>(realmTO) {

                    private static final long serialVersionUID = 2802988981431379829L;

                    @Override
                    public void onClick(final AjaxRequestTarget target, final RealmTO ignore) {
                        onClickDelete(target, realmTO);
                    }
                }, ActionLink.ActionType.DELETE, StandardEntitlement.REALM_DELETE, true).hideLabel();
            }
            RealmDetails panel = new RealmDetails(panelId, realmTO, actionPanel, false);
            panel.setContentEnabled(false);
            actionPanel.setEnabled(true);
            return panel;
        }

        @Override
        public boolean isVisible() {
            return SyncopeConsoleApplication.get().getSecuritySettings().getAuthorizationStrategy().isActionAuthorized(this, RENDER);
        }
    });
    final Triple<UserFormLayoutInfo, GroupFormLayoutInfo, Map<String, AnyObjectFormLayoutInfo>> formLayoutInfo = FormLayoutInfoUtils.fetch(anyTypes.stream().map(EntityTO::getKey).collect(Collectors.toList()));
    for (final AnyTypeTO anyType : anyTypes) {
        tabs.add(new ITabComponent(new Model<>(anyType.getKey()), String.format("%s_SEARCH", anyType.getKey())) {

            private static final long serialVersionUID = 1169585538404171118L;

            @Override
            public WebMarkupContainer getPanel(final String panelId) {
                return new AnyPanel(panelId, anyType, realmTO, formLayoutInfo, true, pageRef);
            }

            @Override
            public boolean isVisible() {
                return SyncopeConsoleApplication.get().getSecuritySettings().getAuthorizationStrategy().isActionAuthorized(this, RENDER);
            }
        });
    }
    return tabs;
}
Also used : ActionsPanel(org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel) ArrayList(java.util.ArrayList) RealmTO(org.apache.syncope.common.lib.to.RealmTO) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) ITab(org.apache.wicket.extensions.markup.html.tabs.ITab) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) EntityTO(org.apache.syncope.common.lib.to.EntityTO) ActionsPanel(org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel) ConnObjectPanel(org.apache.syncope.client.console.wizards.any.ConnObjectPanel) AjaxBootstrapTabbedPanel(de.agilecoders.wicket.core.markup.html.bootstrap.tabs.AjaxBootstrapTabbedPanel) Panel(org.apache.wicket.markup.html.panel.Panel) WizardMgtPanel(org.apache.syncope.client.console.wizards.WizardMgtPanel) Model(org.apache.wicket.model.Model) GroupFormLayoutInfo(org.apache.syncope.client.console.layout.GroupFormLayoutInfo) ITabComponent(org.apache.syncope.client.console.commons.ITabComponent) UserFormLayoutInfo(org.apache.syncope.client.console.layout.UserFormLayoutInfo) Map(java.util.Map)

Example 13 with RealmTO

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

the class DefaultRealmPullResultHandler method create.

private void create(final RealmTO realmTO, final SyncDelta delta, final String operation, final ProvisioningReport result) throws JobExecutionException {
    Object output;
    Result resultStatus;
    try {
        Realm realm = realmDAO.save(binder.create(profile.getTask().getDestinatioRealm(), realmTO));
        PropagationByResource propByRes = new PropagationByResource();
        for (String resource : realm.getResourceKeys()) {
            propByRes.add(ResourceOperation.CREATE, resource);
        }
        List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
        taskExecutor.execute(tasks, false);
        RealmTO actual = binder.getRealmTO(realm, true);
        result.setKey(actual.getKey());
        result.setName(profile.getTask().getDestinatioRealm().getFullPath() + "/" + actual.getName());
        output = actual;
        resultStatus = Result.SUCCESS;
        for (PullActions action : profile.getActions()) {
            action.after(profile, delta, actual, result);
        }
        LOG.debug("Realm {} successfully created", actual.getKey());
    } catch (PropagationException e) {
        // A propagation failure doesn't imply a pull failure.
        // The propagation exception status will be reported into the propagation task execution.
        LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
        output = e;
        resultStatus = Result.FAILURE;
    } catch (Exception e) {
        throwIgnoreProvisionException(delta, e);
        result.setStatus(ProvisioningReport.Status.FAILURE);
        result.setMessage(ExceptionUtils.getRootCauseMessage(e));
        LOG.error("Could not create Realm {} ", delta.getUid().getUidValue(), e);
        output = e;
        resultStatus = Result.FAILURE;
    }
    finalize(operation, resultStatus, null, output, delta);
}
Also used : PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) RealmTO(org.apache.syncope.common.lib.to.RealmTO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) Realm(org.apache.syncope.core.persistence.api.entity.Realm) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result)

Example 14 with RealmTO

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

the class DefaultRealmPullResultHandler method provision.

private List<ProvisioningReport> provision(final SyncDelta delta, final OrgUnit orgUnit) throws JobExecutionException {
    if (!profile.getTask().isPerformCreate()) {
        LOG.debug("PullTask not configured for create");
        finalize(UnmatchingRule.toEventName(UnmatchingRule.PROVISION), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    RealmTO realmTO = connObjectUtils.getRealmTO(delta.getObject(), profile.getTask(), orgUnit);
    if (realmTO.getFullPath() == null) {
        if (realmTO.getParent() == null) {
            realmTO.setParent(profile.getTask().getDestinatioRealm().getFullPath());
        }
        realmTO.setFullPath(realmTO.getParent() + "/" + realmTO.getName());
    }
    ProvisioningReport result = new ProvisioningReport();
    result.setOperation(ResourceOperation.CREATE);
    result.setAnyType(REALM_TYPE);
    result.setStatus(ProvisioningReport.Status.SUCCESS);
    result.setName(realmTO.getFullPath());
    if (profile.isDryRun()) {
        result.setKey(null);
        finalize(UnmatchingRule.toEventName(UnmatchingRule.PROVISION), Result.SUCCESS, null, null, delta);
    } else {
        for (PullActions action : profile.getActions()) {
            action.beforeProvision(profile, delta, realmTO);
        }
        create(realmTO, delta, UnmatchingRule.toEventName(UnmatchingRule.PROVISION), result);
    }
    return Collections.singletonList(result);
}
Also used : PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) RealmTO(org.apache.syncope.common.lib.to.RealmTO) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)

Example 15 with RealmTO

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

the class DefaultRealmPullResultHandler method deprovision.

private List<ProvisioningReport> deprovision(final SyncDelta delta, final List<String> keys, final boolean unlink) throws JobExecutionException {
    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNASSIGN) : MatchingRule.toEventName(MatchingRule.DEPROVISION), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    LOG.debug("About to deprovision {}", keys);
    final List<ProvisioningReport> results = new ArrayList<>();
    for (String key : keys) {
        LOG.debug("About to unassign resource {}", key);
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.DELETE);
        result.setAnyType(REALM_TYPE);
        result.setStatus(ProvisioningReport.Status.SUCCESS);
        result.setKey(key);
        Realm realm = realmDAO.find(key);
        RealmTO before = binder.getRealmTO(realm, true);
        if (before == null) {
            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(String.format("Realm '%s' not found", key));
        } else {
            result.setName(before.getFullPath());
        }
        if (!profile.isDryRun()) {
            Object output;
            Result resultStatus;
            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                try {
                    if (unlink) {
                        for (PullActions action : profile.getActions()) {
                            action.beforeUnassign(profile, delta, before);
                        }
                    } else {
                        for (PullActions action : profile.getActions()) {
                            action.beforeDeprovision(profile, delta, before);
                        }
                    }
                    PropagationByResource propByRes = new PropagationByResource();
                    propByRes.add(ResourceOperation.DELETE, profile.getTask().getResource().getKey());
                    taskExecutor.execute(propagationManager.createTasks(realm, propByRes, null), false);
                    if (unlink) {
                        realm.getResources().remove(profile.getTask().getResource());
                        output = binder.getRealmTO(realmDAO.save(realm), true);
                    } else {
                        output = binder.getRealmTO(realm, true);
                    }
                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, RealmTO.class.cast(output), result);
                    }
                    resultStatus = Result.SUCCESS;
                    LOG.debug("{} successfully updated", realm);
                } catch (PropagationException e) {
                    // A propagation failure doesn't imply a pull failure.
                    // The propagation exception status will be reported into the propagation task execution.
                    LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                } catch (Exception e) {
                    throwIgnoreProvisionException(delta, e);
                    result.setStatus(ProvisioningReport.Status.FAILURE);
                    result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                    LOG.error("Could not update Realm {}", delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                }
            }
            finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNASSIGN) : MatchingRule.toEventName(MatchingRule.DEPROVISION), resultStatus, before, output, delta);
        }
        results.add(result);
    }
    return results;
}
Also used : PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) RealmTO(org.apache.syncope.common.lib.to.RealmTO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) Realm(org.apache.syncope.core.persistence.api.entity.Realm) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result)

Aggregations

RealmTO (org.apache.syncope.common.lib.to.RealmTO)30 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)12 Realm (org.apache.syncope.core.persistence.api.entity.Realm)10 ArrayList (java.util.ArrayList)7 Response (javax.ws.rs.core.Response)7 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)7 PullActions (org.apache.syncope.core.provisioning.api.pushpull.PullActions)7 Test (org.junit.jupiter.api.Test)7 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)6 ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)6 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)4 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)4 Result (org.apache.syncope.common.lib.types.AuditElements.Result)4 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)4 IgnoreProvisionException (org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException)4 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)4 JobExecutionException (org.quartz.JobExecutionException)4 UserTO (org.apache.syncope.common.lib.to.UserTO)3 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)3 PropagationReporter (org.apache.syncope.core.provisioning.api.propagation.PropagationReporter)3