Search in sources :

Example 46 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class DynRealmITCase method misc.

@Test
public void misc() {
    DynRealmTO dynRealm = null;
    try {
        dynRealm = new DynRealmTO();
        dynRealm.setKey("/name" + getUUIDString());
        dynRealm.getDynMembershipConds().put(AnyTypeKind.USER.name(), "cool==true");
        // invalid key (starts with /)
        try {
            dynRealmService.create(dynRealm);
            fail("This should not happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.InvalidDynRealm, e.getType());
        }
        dynRealm.setKey("name" + getUUIDString());
        Response response = dynRealmService.create(dynRealm);
        dynRealm = getObject(response.getLocation(), DynRealmService.class, DynRealmTO.class);
        assertNotNull(dynRealm);
        PagedResult<UserTO> matching = userService.search(new AnyQuery.Builder().fiql("cool==true").build());
        assertNotNull(matching);
        assertNotEquals(0, matching.getSize());
        UserTO user = matching.getResult().get(0);
        assertTrue(user.getDynRealms().contains(dynRealm.getKey()));
    } finally {
        if (dynRealm != null) {
            dynRealmService.delete(dynRealm.getKey());
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) DynRealmService(org.apache.syncope.common.rest.api.service.DynRealmService) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DynRealmTO(org.apache.syncope.common.lib.to.DynRealmTO) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) Test(org.junit.jupiter.api.Test)

Example 47 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class TemplateEditor method doSave.

public void doSave(final IProgressMonitor monitor) {
    final ITextEditor ite = (ITextEditor) getActiveEditor();
    final String content = ite.getDocumentProvider().getDocument(ite.getEditorInput()).get();
    Job saveJob = new Job(SAVE_TEMPLATE_LABEL) {

        @Override
        protected IStatus run(final IProgressMonitor arg0) {
            try {
                if (ite.getTitle().equals(SyncopeView.TEMPLATE_FORMAT_HTML)) {
                    SyncopeView.setMailTemplateContent(ite.getTitleToolTip(), MailTemplateFormat.HTML, content);
                } else if (ite.getTitle().equals(SyncopeView.TEMPLATE_FORMAT_TEXT)) {
                    SyncopeView.setMailTemplateContent(ite.getTitleToolTip(), MailTemplateFormat.TEXT, content);
                } else if (ite.getTitle().equals(SyncopeView.TEMPLATE_FORMAT_CSV)) {
                    SyncopeView.setReportTemplateContent(ite.getTitleToolTip(), ReportTemplateFormat.CSV, content);
                } else if (ite.getTitle().equals(SyncopeView.TEMPLATE_FORMAT_XSL_FO)) {
                    SyncopeView.setReportTemplateContent(ite.getTitleToolTip(), ReportTemplateFormat.FO, content);
                } else if (ite.getTitle().equals(SyncopeView.TEMPLATE_FORMAT_XSL_HTML)) {
                    SyncopeView.setReportTemplateContent(ite.getTitleToolTip(), ReportTemplateFormat.HTML, content);
                } else {
                    throw new Exception("Not a valid editor title");
                }
            } catch (final SyncopeClientException e) {
                e.printStackTrace();
                if (ClientExceptionType.NotFound.equals(e.getType())) {
                    /*
                         * If a deleted template is being edited
                         * close editor and display error
                         */
                    Display.getDefault().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            TemplateEditor.this.getSite().getPage().closeEditor(TemplateEditor.this, false);
                        }
                    });
                    return new org.eclipse.core.runtime.Status(org.eclipse.core.runtime.Status.ERROR, Activator.PLUGIN_ID, "Template No longer exists");
                }
            } catch (final Exception e) {
                e.printStackTrace();
            } finally {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        ite.doSave(monitor);
                    }
                });
            }
            if (monitor.isCanceled()) {
                return org.eclipse.core.runtime.Status.CANCEL_STATUS;
            }
            return org.eclipse.core.runtime.Status.OK_STATUS;
        }
    };
    saveJob.setUser(true);
    saveJob.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Job(org.eclipse.core.runtime.jobs.Job) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PartInitException(org.eclipse.ui.PartInitException)

Example 48 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class AnyObjectDirectoryPanel method getActions.

@Override
public ActionsPanel<AnyObjectTO> getActions(final IModel<AnyObjectTO> model) {
    final ActionsPanel<AnyObjectTO> panel = super.getActions(model);
    panel.add(new ActionLink<AnyObjectTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
            send(AnyObjectDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(new AnyWrapper<>(new AnyObjectRestClient().read(model.getObject().getKey())), target));
        }
    }, ActionType.EDIT, StringUtils.join(new String[] { AnyEntitlement.READ.getFor(type), AnyEntitlement.UPDATE.getFor(type) }, ",")).setRealm(realm);
    panel.add(new ActionLink<AnyObjectTO>() {

        private static final long serialVersionUID = -7978723352517770645L;

        @Override
        public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
            final AnyObjectTO clone = SerializationUtils.clone(model.getObject());
            clone.setKey(null);
            send(AnyObjectDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<>(new AnyWrapper<>(clone), target));
        }

        @Override
        protected boolean statusCondition(final AnyObjectTO modelObject) {
            return addAjaxLink.isVisibleInHierarchy() && realm.startsWith(SyncopeConstants.ROOT_REALM);
        }
    }, ActionType.CLONE, AnyEntitlement.CREATE.getFor(type)).setRealm(realm);
    if (wizardInModal) {
        panel.add(new ActionLink<AnyObjectTO>() {

            private static final long serialVersionUID = -7978723352517770645L;

            @Override
            public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
                final IModel<AnyWrapper<AnyObjectTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
                altDefaultModal.setFormModel(formModel);
                target.add(altDefaultModal.setContent(new AnyStatusModal<>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), "resource", false)));
                altDefaultModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
                altDefaultModal.show(true);
            }
        }, ActionType.MANAGE_RESOURCES, AnyEntitlement.UPDATE.getFor(type)).setRealm(realm);
        panel.add(new ActionLink<AnyObjectTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
                target.add(utilityModal.setContent(new AnyPropagationTasks(utilityModal, AnyTypeKind.ANY_OBJECT, model.getObject().getKey(), pageRef)));
                utilityModal.header(new StringResourceModel("any.propagation.tasks", model));
                utilityModal.show(true);
            }
        }, ActionType.PROPAGATION_TASKS, StandardEntitlement.TASK_LIST);
        panel.add(new ActionLink<AnyObjectTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
                target.add(utilityModal.setContent(new NotificationTasks(AnyTypeKind.ANY_OBJECT, model.getObject().getKey(), pageRef)));
                utilityModal.header(new StringResourceModel("any.notification.tasks", model));
                utilityModal.show(true);
                target.add(utilityModal);
            }
        }, ActionType.NOTIFICATION_TASKS, StandardEntitlement.TASK_LIST);
    }
    panel.add(new ActionLink<AnyObjectTO>() {

        private static final long serialVersionUID = -7978723352517770646L;

        @Override
        public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
            try {
                restClient.delete(model.getObject().getETagValue(), model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (SyncopeClientException e) {
                LOG.error("While deleting object {}", model.getObject().getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }

        @Override
        protected boolean statusCondition(final AnyObjectTO modelObject) {
            return realm.startsWith(SyncopeConstants.ROOT_REALM);
        }
    }, ActionType.DELETE, AnyEntitlement.DELETE.getFor(type), true).setRealm(realm);
    return panel;
}
Also used : CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) AjaxWizard(org.apache.syncope.client.console.wizards.AjaxWizard) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyWrapper(org.apache.syncope.client.console.wizards.any.AnyWrapper) NotificationTasks(org.apache.syncope.client.console.notifications.NotificationTasks) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AnyStatusModal(org.apache.syncope.client.console.status.AnyStatusModal) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyPropagationTasks(org.apache.syncope.client.console.tasks.AnyPropagationTasks) AnyObjectRestClient(org.apache.syncope.client.console.rest.AnyObjectRestClient) StringResourceModel(org.apache.wicket.model.StringResourceModel) ActionLink(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)

Example 49 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class NotificationWizardBuilder method getSchemas.

private List<String> getSchemas() {
    AnyTypeTO type = null;
    try {
        type = anyTypeRestClient.read(AnyTypeKind.USER.name());
    } catch (SyncopeClientException e) {
        LOG.error("While reading all any types", e);
    }
    String[] anyTypeClasses = type == null ? new String[0] : type.getClasses().toArray(new String[] {});
    List<String> result = new ArrayList<>();
    result.add("username");
    result.addAll(schemaRestClient.<PlainSchemaTO>getSchemas(SchemaType.PLAIN, null, anyTypeClasses).stream().map(EntityTO::getKey).collect(Collectors.toList()));
    result.addAll(schemaRestClient.<DerSchemaTO>getSchemas(SchemaType.DERIVED, null, anyTypeClasses).stream().map(EntityTO::getKey).collect(Collectors.toList()));
    result.addAll(schemaRestClient.<VirSchemaTO>getSchemas(SchemaType.VIRTUAL, null, anyTypeClasses).stream().map(EntityTO::getKey).collect(Collectors.toList()));
    Collections.sort(result);
    return result;
}
Also used : EntityTO(org.apache.syncope.common.lib.to.EntityTO) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ArrayList(java.util.ArrayList) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO)

Example 50 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class ApprovalDirectoryPanel method getActions.

@Override
public ActionsPanel<WorkflowFormTO> getActions(final IModel<WorkflowFormTO> model) {
    final ActionsPanel<WorkflowFormTO> panel = super.getActions(model);
    panel.add(new ActionLink<WorkflowFormTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final WorkflowFormTO ignore) {
            claimForm(model.getObject().getTaskId());
            SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
            target.add(container);
        }
    }, ActionLink.ActionType.CLAIM, StandardEntitlement.WORKFLOW_FORM_CLAIM);
    panel.add(new ActionLink<WorkflowFormTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final WorkflowFormTO ignore) {
            manageApprovalModal.setFormModel(new CompoundPropertyModel<>(model.getObject()));
            target.add(manageApprovalModal.setContent(new ApprovalModal(manageApprovalModal, pageRef, model.getObject()) {

                private static final long serialVersionUID = 5546519445061007248L;

                @Override
                public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
                    try {
                        super.onSubmit(target, form);
                        ApprovalDirectoryPanel.this.getTogglePanel().close(target);
                    } catch (SyncopeClientException e) {
                        SyncopeConsoleSession.get().error(getString(Constants.ERROR) + ": " + e.getMessage());
                    }
                    ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
                }
            }));
            manageApprovalModal.header(new Model<>(getString("approval.manage", new Model<>(model.getObject()))));
            manageApprovalModal.show(true);
        }

        @Override
        protected boolean statusCondition(final WorkflowFormTO modelObject) {
            return SyncopeConsoleSession.get().getSelfTO().getUsername().equals(model.getObject().getOwner());
        }
    }, ActionLink.ActionType.MANAGE_APPROVAL, StandardEntitlement.WORKFLOW_FORM_READ);
    // SYNCOPE-1200 edit user while in approval state
    panel.add(new ActionLink<WorkflowFormTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final WorkflowFormTO ignore) {
            modal.setFormModel(new CompoundPropertyModel<>(model.getObject()));
            WorkflowFormTO formTO = model.getObject();
            UserTO newUserTO;
            UserTO previousUserTO;
            if (formTO.getUserPatch() == null) {
                newUserTO = formTO.getUserTO();
                previousUserTO = null;
            } else if (formTO.getUserTO() == null) {
                // make it stronger by handling possible NPE
                previousUserTO = new UserTO();
                previousUserTO.setKey(formTO.getUserPatch().getKey());
                newUserTO = AnyOperations.patch(previousUserTO, formTO.getUserPatch());
            } else {
                previousUserTO = formTO.getUserTO();
                formTO.getUserTO().setKey(formTO.getUserPatch().getKey());
                formTO.getUserTO().setPassword(null);
                newUserTO = AnyOperations.patch(formTO.getUserTO(), formTO.getUserPatch());
            }
            AjaxWizard.EditItemActionEvent<UserTO> editItemActionEvent = new AjaxWizard.EditItemActionEvent<>(newUserTO, target);
            editItemActionEvent.forceModalPanel(new ApprovalUserWizardBuilder(model.getObject(), previousUserTO, newUserTO, new AnyTypeRestClient().read(AnyTypeKind.USER.name()).getClasses(), FormLayoutInfoUtils.fetch(Collections.singletonList(AnyTypeKind.USER.name())).getLeft(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
            send(ApprovalDirectoryPanel.this, Broadcast.EXACT, editItemActionEvent);
        }

        @Override
        protected boolean statusCondition(final WorkflowFormTO modelObject) {
            return SyncopeConsoleSession.get().getSelfTO().getUsername().equals(model.getObject().getOwner());
        }
    }, ActionLink.ActionType.EDIT_APPROVAL, StandardEntitlement.WORKFLOW_FORM_SUBMIT);
    return panel;
}
Also used : CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) AjaxWizard(org.apache.syncope.client.console.wizards.AjaxWizard) AnyTypeRestClient(org.apache.syncope.client.console.rest.AnyTypeRestClient) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) UserTO(org.apache.syncope.common.lib.to.UserTO) IModel(org.apache.wicket.model.IModel) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Model(org.apache.wicket.model.Model) ResourceModel(org.apache.wicket.model.ResourceModel) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) BasePage(org.apache.syncope.client.console.pages.BasePage)

Aggregations

SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)240 Test (org.junit.jupiter.api.Test)105 UserTO (org.apache.syncope.common.lib.to.UserTO)50 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)40 Response (javax.ws.rs.core.Response)34 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)20 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)19 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)18 Realm (org.apache.syncope.core.persistence.api.entity.Realm)18 GroupTO (org.apache.syncope.common.lib.to.GroupTO)17 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)16 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 Map (java.util.Map)14 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)14 ArrayList (java.util.ArrayList)12 List (java.util.List)12 ItemTO (org.apache.syncope.common.lib.to.ItemTO)12 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)12 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)11