Search in sources :

Example 26 with RealmTO

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

the class Realms method updateRealmContent.

private WebMarkupContainer updateRealmContent(final RealmTO realmTO, final int selectedIndex) {
    if (realmTO == null) {
        return content;
    }
    content.addOrReplace(new Realm("body", realmTO, Realms.this.getPageReference(), selectedIndex) {

        private static final long serialVersionUID = 8221398624379357183L;

        @Override
        protected void onClickTemplate(final AjaxRequestTarget target) {
            templates.setTargetObject(realmTO);
            templates.toggle(target, true);
        }

        @Override
        protected void setWindowClosedReloadCallback(final BaseModal<?> modal) {
            modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

                private static final long serialVersionUID = 8804221891699487139L;

                @Override
                public void onClose(final AjaxRequestTarget target) {
                    if (modal.getContent() instanceof ResultPage) {
                        Serializable result = ResultPage.class.cast(modal.getContent()).getResult();
                        RealmTO newRealmTO = RealmTO.class.cast(ProvisioningResult.class.cast(result).getEntity());
                        // reload realmChoicePanel label too - SYNCOPE-1151
                        target.add(realmChoicePanel.reloadRealmTree(target, Model.of(newRealmTO)));
                        realmChoicePanel.setCurrentRealm(newRealmTO);
                        send(Realms.this, Broadcast.DEPTH, new ChosenRealm<>(newRealmTO, target));
                    } else {
                        target.add(realmChoicePanel.reloadRealmTree(target));
                    }
                    target.add(content);
                    modal.show(false);
                }
            });
        }

        @Override
        protected void onClickCreate(final AjaxRequestTarget target) {
            this.wizardBuilder.setParentPath(realmChoicePanel.getCurrentRealm().getFullPath());
            send(this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<RealmTO>(new RealmTO(), target) {

                @Override
                public String getEventDescription() {
                    return "realm.new";
                }
            });
        }

        @Override
        protected void onClickEdit(final AjaxRequestTarget target, final RealmTO realmTO) {
            this.wizardBuilder.setParentPath(realmTO.getFullPath());
            send(this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<RealmTO>(realmTO, target) {

                @Override
                public String getEventDescription() {
                    return "realm.edit";
                }
            });
        }

        @Override
        protected void onClickDelete(final AjaxRequestTarget target, final RealmTO realmTO) {
            try {
                if (realmTO.getKey() == null) {
                    throw new Exception("Root realm cannot be deleted");
                }
                realmRestClient.delete(realmTO.getFullPath());
                RealmTO parent = realmChoicePanel.moveToParentRealm(realmTO.getKey());
                target.add(realmChoicePanel.reloadRealmTree(target));
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                updateRealmContent(parent, selectedIndex);
                target.add(content);
            } catch (Exception e) {
                LOG.error("While deleting realm", e);
                // Escape line breaks
                SyncopeConsoleSession.get().error(e.getMessage().replace("\n", " "));
            }
            ((BasePage) Realms.this.getPage()).getNotificationPanel().refresh(target);
        }
    });
    return content;
}
Also used : Serializable(java.io.Serializable) RealmTO(org.apache.syncope.common.lib.to.RealmTO) WindowClosedCallback(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.WindowClosedCallback) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ResultPage(org.apache.syncope.client.console.wizards.any.ResultPage) Realm(org.apache.syncope.client.console.panels.Realm) ChosenRealm(org.apache.syncope.client.console.panels.RealmChoicePanel.ChosenRealm)

Example 27 with RealmTO

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

the class RealmResource method newResourceResponse.

@Override
protected ResourceResponse newResourceResponse(final Attributes attributes) {
    LOG.debug("Search all available realms");
    ResourceResponse response = new ResourceResponse();
    response.setContentType(MediaType.APPLICATION_JSON);
    try {
        HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
        if (!xsrfCheck(request)) {
            LOG.error("XSRF TOKEN does not match");
            response.setError(Response.Status.BAD_REQUEST.getStatusCode(), "XSRF TOKEN does not match");
            return response;
        }
        final List<RealmTO> realmTOs = SyncopeEnduserSession.get().getService(RealmService.class).list();
        response.setTextEncoding(StandardCharsets.UTF_8.name());
        response.setWriteCallback(new AbstractResource.WriteCallback() {

            @Override
            public void writeData(final Attributes attributes) throws IOException {
                attributes.getResponse().write(MAPPER.writeValueAsString(realmTOs));
            }
        });
        response.setStatusCode(Response.Status.OK.getStatusCode());
    } catch (Exception e) {
        LOG.error("Error retrieving available realms", e);
        response.setError(Response.Status.BAD_REQUEST.getStatusCode(), new StringBuilder().append("ErrorMessage{{ ").append(e.getMessage()).append(" }}").toString());
    }
    return response;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RealmService(org.apache.syncope.common.rest.api.service.RealmService) RealmTO(org.apache.syncope.common.lib.to.RealmTO) AbstractResource(org.apache.wicket.request.resource.AbstractResource) IOException(java.io.IOException) IOException(java.io.IOException)

Example 28 with RealmTO

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

the class RealmLogic method update.

@PreAuthorize("hasRole('" + StandardEntitlement.REALM_UPDATE + "')")
public ProvisioningResult<RealmTO> update(final RealmTO realmTO) {
    Realm realm = realmDAO.findByFullPath(realmTO.getFullPath());
    if (realm == null) {
        LOG.error("Could not find realm '" + realmTO.getFullPath() + "'");
        throw new NotFoundException(realmTO.getFullPath());
    }
    PropagationByResource propByRes = binder.update(realm, realmTO);
    realm = realmDAO.save(realm);
    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
    ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
    result.setEntity(binder.getRealmTO(realm, true));
    result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
    return result;
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) RealmTO(org.apache.syncope.common.lib.to.RealmTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) Realm(org.apache.syncope.core.persistence.api.entity.Realm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 29 with RealmTO

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

the class RealmLogic method create.

@PreAuthorize("hasRole('" + StandardEntitlement.REALM_CREATE + "')")
public ProvisioningResult<RealmTO> create(final String parentPath, final RealmTO realmTO) {
    Realm parent;
    if (StringUtils.isBlank(realmTO.getParent())) {
        parent = realmDAO.findByFullPath(parentPath);
        if (parent == null) {
            LOG.error("Could not find parent realm " + parentPath);
            throw new NotFoundException(parentPath);
        }
        realmTO.setParent(parent.getFullPath());
    } else {
        parent = realmDAO.find(realmTO.getParent());
        if (parent == null) {
            LOG.error("Could not find parent realm " + realmTO.getParent());
            throw new NotFoundException(realmTO.getParent());
        }
        if (!parent.getFullPath().equals(parentPath)) {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPath);
            sce.getElements().add("Mismatching parent realm: " + parentPath + " Vs " + parent.getFullPath());
            throw sce;
        }
    }
    String fullPath = StringUtils.appendIfMissing(parent.getFullPath(), "/") + realmTO.getName();
    if (realmDAO.findByFullPath(fullPath) != null) {
        throw new DuplicateException(fullPath);
    }
    Realm realm = realmDAO.save(binder.create(parent, realmTO));
    PropagationByResource propByRes = new PropagationByResource();
    realm.getResourceKeys().forEach(resource -> {
        propByRes.add(ResourceOperation.CREATE, resource);
    });
    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
    ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
    result.setEntity(binder.getRealmTO(realm, true));
    result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
    return result;
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RealmTO(org.apache.syncope.common.lib.to.RealmTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) Realm(org.apache.syncope.core.persistence.api.entity.Realm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 30 with RealmTO

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

the class RealmLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.REALM_DELETE + "')")
public ProvisioningResult<RealmTO> delete(final String fullPath) {
    Realm realm = realmDAO.findByFullPath(fullPath);
    if (realm == null) {
        LOG.error("Could not find realm '" + fullPath + "'");
        throw new NotFoundException(fullPath);
    }
    if (!realmDAO.findChildren(realm).isEmpty()) {
        throw SyncopeClientException.build(ClientExceptionType.HasChildren);
    }
    Set<String> adminRealms = Collections.singleton(realm.getFullPath());
    AnyCond keyCond = new AnyCond(AttributeCond.Type.ISNOTNULL);
    keyCond.setSchema("key");
    SearchCond allMatchingCond = SearchCond.getLeafCond(keyCond);
    int users = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.USER);
    int groups = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.GROUP);
    int anyObjects = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.ANY_OBJECT);
    if (users + groups + anyObjects > 0) {
        SyncopeClientException containedAnys = SyncopeClientException.build(ClientExceptionType.AssociatedAnys);
        containedAnys.getElements().add(users + " user(s)");
        containedAnys.getElements().add(groups + " group(s)");
        containedAnys.getElements().add(anyObjects + " anyObject(s)");
        throw containedAnys;
    }
    PropagationByResource propByRes = new PropagationByResource();
    realm.getResourceKeys().forEach(resource -> {
        propByRes.add(ResourceOperation.DELETE, resource);
    });
    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
    ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
    result.setEntity(binder.getRealmTO(realm, true));
    result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
    realmDAO.delete(realm);
    return result;
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RealmTO(org.apache.syncope.common.lib.to.RealmTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Realm(org.apache.syncope.core.persistence.api.entity.Realm) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

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