Search in sources :

Example 1 with UserRestClient

use of org.apache.syncope.client.console.rest.UserRestClient in project syncope by apache.

the class UserDirectoryPanel method getActions.

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

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            send(UserDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(new UserWrapper(new UserRestClient().read(model.getObject().getKey())), target));
        }
    }, ActionType.EDIT, StringUtils.join(new String[] { StandardEntitlement.USER_READ, StandardEntitlement.USER_UPDATE }, ",")).setRealm(realm);
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            UserTO clone = SerializationUtils.clone(model.getObject());
            clone.setKey(null);
            clone.setUsername(model.getObject().getUsername() + "_clone");
            send(UserDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<>(new UserWrapper(clone), target));
        }

        @Override
        protected boolean statusCondition(final UserTO modelObject) {
            return addAjaxLink.isVisibleInHierarchy() && realm.startsWith(SyncopeConstants.ROOT_REALM);
        }
    }, ActionType.CLONE, StandardEntitlement.USER_CREATE).setRealm(realm);
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            try {
                UserRestClient.class.cast(restClient).mustChangePassword(model.getObject().getETagValue(), !model.getObject().isMustChangePassword(), model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (Exception e) {
                LOG.error("While actioning object {}", model.getObject().getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionType.MUSTCHANGEPASSWORD, StandardEntitlement.USER_UPDATE).setRealm(realm);
    if (wizardInModal) {
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -4875218360625971340L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                IModel<AnyWrapper<UserTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
                displayAttributeModal.setFormModel(formModel);
                target.add(displayAttributeModal.setContent(new ChangePasswordModal(displayAttributeModal, pageRef, new UserWrapper(model.getObject()))));
                displayAttributeModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
                displayAttributeModal.show(true);
            }
        }, ActionType.PASSWORD_MANAGEMENT, StandardEntitlement.USER_UPDATE).setRealm(realm);
        if (SyncopeConsoleSession.get().getPlatformInfo().isPwdResetAllowed() && !SyncopeConsoleSession.get().getPlatformInfo().isPwdResetRequiringSecurityQuestions()) {
            panel.add(new ActionLink<UserTO>() {

                private static final long serialVersionUID = -7978723352517770644L;

                @Override
                public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                    try {
                        SyncopeConsoleSession.get().getAnonymousClient().getService(UserSelfService.class).requestPasswordReset(model.getObject().getUsername(), null);
                        SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                        target.add(container);
                    } catch (Exception e) {
                        LOG.error("While actioning object {}", model.getObject().getKey(), e);
                        SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                    }
                    ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
                }
            }, ActionType.REQUEST_PASSWORD_RESET, StandardEntitlement.USER_UPDATE).setRealm(realm);
        }
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

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

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                IModel<AnyWrapper<UserTO>> 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, StandardEntitlement.USER_UPDATE).setRealm(realm);
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                target.add(utilityModal.setContent(new AnyPropagationTasks(utilityModal, AnyTypeKind.USER, 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<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                target.add(utilityModal.setContent(new NotificationTasks(AnyTypeKind.USER, 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<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            try {
                restClient.delete(model.getObject().getETagValue(), model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (Exception 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 UserTO modelObject) {
            return realm.startsWith(SyncopeConstants.ROOT_REALM);
        }
    }, ActionType.DELETE, StandardEntitlement.USER_DELETE, true).setRealm(realm);
    return panel;
}
Also used : CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) AjaxWizard(org.apache.syncope.client.console.wizards.AjaxWizard) UserSelfService(org.apache.syncope.common.rest.api.service.UserSelfService) AnyWrapper(org.apache.syncope.client.console.wizards.any.AnyWrapper) NotificationTasks(org.apache.syncope.client.console.notifications.NotificationTasks) UserWrapper(org.apache.syncope.client.console.wizards.any.UserWrapper) UserRestClient(org.apache.syncope.client.console.rest.UserRestClient) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AnyStatusModal(org.apache.syncope.client.console.status.AnyStatusModal) AnyPropagationTasks(org.apache.syncope.client.console.tasks.AnyPropagationTasks) UserTO(org.apache.syncope.common.lib.to.UserTO) ChangePasswordModal(org.apache.syncope.client.console.status.ChangePasswordModal) StringResourceModel(org.apache.wicket.model.StringResourceModel) ActionLink(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)

Example 2 with UserRestClient

use of org.apache.syncope.client.console.rest.UserRestClient in project syncope by apache.

the class RemediationDirectoryPanel method getActions.

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

        private static final long serialVersionUID = 6193210574968203299L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RemediationTO ignore) {
            modal.header(new ResourceModel("error"));
            modal.setContent(new ExecMessageModal(model.getObject().getError()));
            modal.show(true);
            target.add(modal);
        }
    }, ActionLink.ActionType.VIEW_DETAILS, StandardEntitlement.REMEDIATION_READ);
    if (model.getObject().getOperation() == ResourceOperation.DELETE) {
        String entitlements = StringUtils.join(new String[] { StandardEntitlement.REMEDIATION_REMEDY, AnyTypeKind.USER.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.USER_DELETE : AnyTypeKind.GROUP.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.GROUP_DELETE : AnyEntitlement.DELETE.getFor(model.getObject().getAnyType()) }, ",");
        panel.add(new ActionLink<RemediationTO>() {

            private static final long serialVersionUID = 6193210574968203299L;

            @Override
            public void onClick(final AjaxRequestTarget target, final RemediationTO ignore) {
                try {
                    restClient.remedy(model.getObject().getKey(), model.getObject().getKeyPayload());
                    SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                    target.add(container);
                } catch (SyncopeClientException e) {
                    LOG.error("While performing remediation {}", model.getObject().getKey(), e);
                    SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                }
                ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
            }
        }, ActionLink.ActionType.CLOSE, entitlements, true);
    } else {
        String entitlements = model.getObject().getOperation() == ResourceOperation.CREATE ? StringUtils.join(new String[] { StandardEntitlement.REMEDIATION_REMEDY, AnyTypeKind.USER.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.USER_CREATE : AnyTypeKind.GROUP.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.GROUP_CREATE : AnyEntitlement.CREATE.getFor(model.getObject().getAnyType()) }, ",") : StringUtils.join(new String[] { StandardEntitlement.REMEDIATION_REMEDY, AnyTypeKind.USER.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.USER_UPDATE : AnyTypeKind.GROUP.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.GROUP_UPDATE : AnyEntitlement.UPDATE.getFor(model.getObject().getAnyType()) }, ",");
        panel.add(new ActionLink<RemediationTO>() {

            private static final long serialVersionUID = 6193210574968203299L;

            @Override
            public void onClick(final AjaxRequestTarget target, final RemediationTO ignore) {
                modal.setFormModel(new CompoundPropertyModel<>(model.getObject()));
                RemediationTO remediationTO = model.getObject();
                switch(remediationTO.getAnyType()) {
                    case "USER":
                        UserTO newUserTO;
                        UserTO previousUserTO;
                        if (remediationTO.getAnyPatchPayload() == null) {
                            newUserTO = (UserTO) remediationTO.getAnyTOPayload();
                            previousUserTO = null;
                        } else {
                            previousUserTO = new UserRestClient().read(remediationTO.getAnyPatchPayload().getKey());
                            newUserTO = AnyOperations.patch(previousUserTO, (UserPatch) remediationTO.getAnyPatchPayload());
                        }
                        AjaxWizard.EditItemActionEvent<UserTO> userEvent = new AjaxWizard.EditItemActionEvent<>(newUserTO, target);
                        userEvent.forceModalPanel(new RemediationUserWizardBuilder(model.getObject(), previousUserTO, newUserTO, new AnyTypeRestClient().read(remediationTO.getAnyType()).getClasses(), FormLayoutInfoUtils.fetch(Arrays.asList(remediationTO.getAnyType())).getLeft(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
                        send(RemediationDirectoryPanel.this, Broadcast.EXACT, userEvent);
                        break;
                    case "GROUP":
                        GroupTO newGroupTO;
                        GroupTO previousGroupTO;
                        if (remediationTO.getAnyPatchPayload() == null) {
                            newGroupTO = (GroupTO) remediationTO.getAnyTOPayload();
                            previousGroupTO = null;
                        } else {
                            previousGroupTO = new GroupRestClient().read(remediationTO.getAnyPatchPayload().getKey());
                            newGroupTO = AnyOperations.patch(previousGroupTO, (GroupPatch) remediationTO.getAnyPatchPayload());
                        }
                        AjaxWizard.EditItemActionEvent<GroupTO> groupEvent = new AjaxWizard.EditItemActionEvent<>(newGroupTO, target);
                        groupEvent.forceModalPanel(new RemediationGroupWizardBuilder(model.getObject(), previousGroupTO, newGroupTO, new AnyTypeRestClient().read(remediationTO.getAnyType()).getClasses(), FormLayoutInfoUtils.fetch(Arrays.asList(remediationTO.getAnyType())).getMiddle(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
                        send(RemediationDirectoryPanel.this, Broadcast.EXACT, groupEvent);
                        break;
                    default:
                        AnyObjectTO newAnyObjectTO;
                        AnyObjectTO previousAnyObjectTO;
                        if (remediationTO.getAnyPatchPayload() == null) {
                            newAnyObjectTO = (AnyObjectTO) remediationTO.getAnyTOPayload();
                            previousAnyObjectTO = null;
                        } else {
                            previousAnyObjectTO = new AnyObjectRestClient().read(remediationTO.getAnyPatchPayload().getKey());
                            newAnyObjectTO = AnyOperations.patch(previousAnyObjectTO, (AnyObjectPatch) remediationTO.getAnyPatchPayload());
                        }
                        AjaxWizard.EditItemActionEvent<AnyObjectTO> anyObjectEvent = new AjaxWizard.EditItemActionEvent<>(newAnyObjectTO, target);
                        anyObjectEvent.forceModalPanel(new RemediationAnyObjectWizardBuilder(model.getObject(), previousAnyObjectTO, newAnyObjectTO, new AnyTypeRestClient().read(remediationTO.getAnyType()).getClasses(), FormLayoutInfoUtils.fetch(Arrays.asList(remediationTO.getAnyType())).getRight().values().iterator().next(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
                        send(RemediationDirectoryPanel.this, Broadcast.EXACT, anyObjectEvent);
                }
            }
        }, ActionLink.ActionType.EDIT, entitlements);
    }
    panel.add(new ActionLink<RemediationTO>() {

        private static final long serialVersionUID = 6193210574968203299L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RemediationTO ignore) {
            try {
                restClient.delete(model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (SyncopeClientException e) {
                LOG.error("While deleting {}", model.getObject().getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionLink.ActionType.DELETE, StandardEntitlement.REMEDIATION_DELETE, true);
    return panel;
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ResourceModel(org.apache.wicket.model.ResourceModel) StringResourceModel(org.apache.wicket.model.StringResourceModel) GroupRestClient(org.apache.syncope.client.console.rest.GroupRestClient) AnyObjectRestClient(org.apache.syncope.client.console.rest.AnyObjectRestClient) BasePage(org.apache.syncope.client.console.pages.BasePage) 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) RemediationTO(org.apache.syncope.common.lib.to.RemediationTO) UserRestClient(org.apache.syncope.client.console.rest.UserRestClient) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) UserTO(org.apache.syncope.common.lib.to.UserTO)

Example 3 with UserRestClient

use of org.apache.syncope.client.console.rest.UserRestClient in project syncope by apache.

the class ResourceStatusDirectoryPanel method updateResultTable.

public void updateResultTable(final String type, final AjaxRequestTarget target) {
    this.type = type;
    if (StringUtils.isNoneEmpty(type)) {
        switch(type) {
            case "USER":
                this.restClient = new UserRestClient();
                break;
            case "GROUP":
                this.restClient = new GroupRestClient();
                break;
            default:
                this.restClient = new AnyObjectRestClient();
        }
    }
    super.updateResultTable(target);
}
Also used : GroupRestClient(org.apache.syncope.client.console.rest.GroupRestClient) AnyObjectRestClient(org.apache.syncope.client.console.rest.AnyObjectRestClient) UserRestClient(org.apache.syncope.client.console.rest.UserRestClient)

Aggregations

UserRestClient (org.apache.syncope.client.console.rest.UserRestClient)3 AnyObjectRestClient (org.apache.syncope.client.console.rest.AnyObjectRestClient)2 GroupRestClient (org.apache.syncope.client.console.rest.GroupRestClient)2 AjaxWizard (org.apache.syncope.client.console.wizards.AjaxWizard)2 UserTO (org.apache.syncope.common.lib.to.UserTO)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 CompoundPropertyModel (org.apache.wicket.model.CompoundPropertyModel)2 StringResourceModel (org.apache.wicket.model.StringResourceModel)2 NotificationTasks (org.apache.syncope.client.console.notifications.NotificationTasks)1 BasePage (org.apache.syncope.client.console.pages.BasePage)1 AnyTypeRestClient (org.apache.syncope.client.console.rest.AnyTypeRestClient)1 AnyStatusModal (org.apache.syncope.client.console.status.AnyStatusModal)1 ChangePasswordModal (org.apache.syncope.client.console.status.ChangePasswordModal)1 AnyPropagationTasks (org.apache.syncope.client.console.tasks.AnyPropagationTasks)1 ActionLink (org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)1 AnyWrapper (org.apache.syncope.client.console.wizards.any.AnyWrapper)1 UserWrapper (org.apache.syncope.client.console.wizards.any.UserWrapper)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)1 GroupTO (org.apache.syncope.common.lib.to.GroupTO)1