Search in sources :

Example 1 with AddRoleMapping

use of org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping in project console by hal.

the class AssignmentColumn method columnActionHandler.

private ColumnActionHandler<Assignment> columnActionHandler(Role role, boolean include) {
    return column -> {
        Principal principal = findPrincipal(getFinder().getContext().getPath());
        if (principal != null) {
            series(new FlowContext(progress.get()), new CheckRoleMapping(dispatcher, role), new AddRoleMapping(dispatcher, role, status -> status == 404), new AddAssignment(dispatcher, role, principal, include)).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {

                @Override
                public void onSuccess(FlowContext context) {
                    String type = resources.constants().role();
                    SafeHtml message = include ? resources.messages().assignmentIncludeSuccess(type, role.getName()) : resources.messages().assignmentExcludeSuccess(type, role.getName());
                    MessageEvent.fire(eventBus, Message.success(message));
                    accessControl.reload(() -> {
                        refresh(RefreshMode.RESTORE_SELECTION);
                        if (isCurrentUser(principal)) {
                            eventBus.fireEvent(new UserChangedEvent());
                        }
                    });
                }
            });
        }
    };
}
Also used : ColumnActionHandler(org.jboss.hal.core.finder.ColumnActionHandler) Provider(javax.inject.Provider) AsyncColumn(org.jboss.hal.spi.AsyncColumn) ItemActionFactory(org.jboss.hal.core.finder.ItemActionFactory) MessageEvent(org.jboss.hal.spi.MessageEvent) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ColumnAction(org.jboss.hal.core.finder.ColumnAction) ItemAction(org.jboss.hal.core.finder.ItemAction) ItemDisplay(org.jboss.hal.core.finder.ItemDisplay) FinderSegment(org.jboss.hal.core.finder.FinderSegment) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) UserChangedEvent(org.jboss.hal.config.UserChangedEvent) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Inject(javax.inject.Inject) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) Progress(org.jboss.hal.flow.Progress) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) FinderColumn(org.jboss.hal.core.finder.FinderColumn) User(org.jboss.hal.config.User) Collectors.toSet(java.util.stream.Collectors.toSet) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) INCLUDE_TEMPLATE(org.jboss.hal.client.accesscontrol.AddressTemplates.INCLUDE_TEMPLATE) EXCLUDE_TEMPLATE(org.jboss.hal.client.accesscontrol.AddressTemplates.EXCLUDE_TEMPLATE) REMOVE(org.jboss.hal.dmr.ModelDescriptionConstants.REMOVE) Set(java.util.Set) EventBus(com.google.web.bindery.event.shared.EventBus) AddAssignment(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddAssignment) FinderPath(org.jboss.hal.core.finder.FinderPath) Sets(com.google.common.collect.Sets) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) Resources(org.jboss.hal.resources.Resources) Flow.series(org.jboss.hal.flow.Flow.series) Role(org.jboss.hal.config.Role) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Elements.span(org.jboss.gwt.elemento.core.Elements.span) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) UserChangedEvent(org.jboss.hal.config.UserChangedEvent) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) AddAssignment(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddAssignment) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) FlowContext(org.jboss.hal.flow.FlowContext) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping)

Example 2 with AddRoleMapping

use of org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping in project console by hal.

the class RoleColumn method editStandardRole.

// ------------------------------------------------------ modify roles
private void editStandardRole(Role role) {
    Metadata metadata = metadataRegistry.lookup(ROLE_MAPPING_TEMPLATE);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.ROLE_MAPPING_FORM, metadata).unboundFormItem(new NameItem(), 0).include(INCLUDE_ALL).build();
    form.getFormItem(NAME).setEnabled(false);
    form.getFormItem(NAME).setRequired(false);
    ModelNode modelNode = new ModelNode();
    modelNode.get(INCLUDE_ALL).set(role.isIncludeAll());
    new ModifyResourceDialog(resources.messages().modifyResourceTitle(resources.constants().role()), form, (frm, changedValues) -> series(new FlowContext(progress.get()), new CheckRoleMapping(dispatcher, role), new AddRoleMapping(dispatcher, role, status -> status == 404), new ModifyIncludeAll(dispatcher, role, frm.getModel().get(INCLUDE_ALL).asBoolean())).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {

        @Override
        public void onSuccess(FlowContext context) {
            MessageEvent.fire(eventBus, Message.success(resources.messages().modifyResourceSuccess(resources.constants().role(), role.getName())));
            accessControl.reload(() -> {
                refresh(role.getId());
                eventBus.fireEvent(new RolesChangedEvent());
            });
        }
    })).show(modelNode);
    form.getFormItem(NAME).setValue(role.getName());
}
Also used : Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) AddScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddScopedRole) ItemDisplay(org.jboss.hal.core.finder.ItemDisplay) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Metadata(org.jboss.hal.meta.Metadata) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping) Settings(org.jboss.hal.config.Settings) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) ModifyResourceDialog(org.jboss.hal.core.mbui.dialog.ModifyResourceDialog) RemoveAssignments(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveAssignments) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Flow.series(org.jboss.hal.flow.Flow.series) Role(org.jboss.hal.config.Role) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) Elements.small(org.jboss.gwt.elemento.core.Elements.small) CSS.subtitle(org.jboss.hal.resources.CSS.subtitle) ModelNode(org.jboss.hal.dmr.ModelNode) RemoveScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveScopedRole) AsyncColumn(org.jboss.hal.spi.AsyncColumn) MessageEvent(org.jboss.hal.spi.MessageEvent) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ColumnAction(org.jboss.hal.core.finder.ColumnAction) ItemAction(org.jboss.hal.core.finder.ItemAction) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) Task(org.jboss.hal.flow.Task) ModifyIncludeAll(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyIncludeAll) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) RemoveRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveRoleMapping) FinderColumn(org.jboss.hal.core.finder.FinderColumn) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) Comparator.comparing(java.util.Comparator.comparing) ModifyScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyScopedRole) RolesChangedEvent(org.jboss.hal.config.RolesChangedEvent) AddressTemplates(org.jboss.hal.client.accesscontrol.AddressTemplates) ColumnActionFactory(org.jboss.hal.core.finder.ColumnActionFactory) Requires(org.jboss.hal.spi.Requires) CSS.itemText(org.jboss.hal.resources.CSS.itemText) Ids(org.jboss.hal.resources.Ids) EventBus(com.google.web.bindery.event.shared.EventBus) CSS.pfIcon(org.jboss.hal.resources.CSS.pfIcon) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) Resources(org.jboss.hal.resources.Resources) RUN_AS(org.jboss.hal.config.Settings.Key.RUN_AS) Elements.span(org.jboss.gwt.elemento.core.Elements.span) Form(org.jboss.hal.ballroom.form.Form) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) Metadata(org.jboss.hal.meta.Metadata) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) FlowContext(org.jboss.hal.flow.FlowContext) RolesChangedEvent(org.jboss.hal.config.RolesChangedEvent) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) ModifyIncludeAll(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyIncludeAll) ModelNode(org.jboss.hal.dmr.ModelNode) ModifyResourceDialog(org.jboss.hal.core.mbui.dialog.ModifyResourceDialog) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping)

Example 3 with AddRoleMapping

use of org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping in project console by hal.

the class RoleColumn method addScopedRole.

// ------------------------------------------------------ add roles
@SuppressWarnings("ConstantConditions")
private void addScopedRole(Role.Type type, String typeName, AddressTemplate template, AddressTemplate typeaheadTemplate, String formId, String scopeAttribute) {
    Metadata metadata = metadataRegistry.lookup(template);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(formId, metadata).addOnly().unboundFormItem(new NameItem(), 0).unboundFormItem(new SwitchItem(INCLUDE_ALL, new LabelBuilder().label(INCLUDE_ALL)), 3, resources.messages().includeAllHelpText()).include(BASE_ROLE, scopeAttribute).customFormItem(BASE_ROLE, attributeDescription -> {
        SingleSelectBoxItem item = new SingleSelectBoxItem(BASE_ROLE, new LabelBuilder().label(BASE_ROLE), standardRoleNames, false);
        item.setRequired(true);
        return item;
    }).build();
    form.getFormItem(scopeAttribute).setRequired(true);
    form.getFormItem(scopeAttribute).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, typeaheadTemplate));
    form.attach();
    AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(typeName), form, (name, model) -> {
        List<Task<FlowContext>> tasks = new ArrayList<>();
        tasks.add(new AddScopedRole(dispatcher, type, name, model));
        Boolean includeAll = form.<Boolean>getFormItem(INCLUDE_ALL).getValue();
        Role transientRole = new Role(name, null, type, null);
        // We only need the role name in the functions,
        // so it's ok to setup a transient role w/o the other attributes.
        tasks.add(new CheckRoleMapping(dispatcher, transientRole));
        tasks.add(new AddRoleMapping(dispatcher, transientRole, status -> status == 404));
        if (includeAll != null && includeAll) {
            tasks.add(new ModifyIncludeAll(dispatcher, transientRole, includeAll));
        }
        series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {

            @Override
            public void onSuccess(FlowContext context) {
                MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(typeName, name)));
                accessControl.reload(() -> {
                    refresh(Ids.role(name));
                    eventBus.fireEvent(new RolesChangedEvent());
                });
            }
        });
    });
    dialog.getForm().<String>getFormItem(NAME).addValidationHandler(createUniqueValidation());
    dialog.show();
}
Also used : Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) AddScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddScopedRole) ItemDisplay(org.jboss.hal.core.finder.ItemDisplay) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Metadata(org.jboss.hal.meta.Metadata) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping) Settings(org.jboss.hal.config.Settings) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) ModifyResourceDialog(org.jboss.hal.core.mbui.dialog.ModifyResourceDialog) RemoveAssignments(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveAssignments) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Flow.series(org.jboss.hal.flow.Flow.series) Role(org.jboss.hal.config.Role) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) Elements.small(org.jboss.gwt.elemento.core.Elements.small) CSS.subtitle(org.jboss.hal.resources.CSS.subtitle) ModelNode(org.jboss.hal.dmr.ModelNode) RemoveScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveScopedRole) AsyncColumn(org.jboss.hal.spi.AsyncColumn) MessageEvent(org.jboss.hal.spi.MessageEvent) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ColumnAction(org.jboss.hal.core.finder.ColumnAction) ItemAction(org.jboss.hal.core.finder.ItemAction) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) Task(org.jboss.hal.flow.Task) ModifyIncludeAll(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyIncludeAll) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) RemoveRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveRoleMapping) FinderColumn(org.jboss.hal.core.finder.FinderColumn) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) Comparator.comparing(java.util.Comparator.comparing) ModifyScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyScopedRole) RolesChangedEvent(org.jboss.hal.config.RolesChangedEvent) AddressTemplates(org.jboss.hal.client.accesscontrol.AddressTemplates) ColumnActionFactory(org.jboss.hal.core.finder.ColumnActionFactory) Requires(org.jboss.hal.spi.Requires) CSS.itemText(org.jboss.hal.resources.CSS.itemText) Ids(org.jboss.hal.resources.Ids) EventBus(com.google.web.bindery.event.shared.EventBus) CSS.pfIcon(org.jboss.hal.resources.CSS.pfIcon) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) Resources(org.jboss.hal.resources.Resources) RUN_AS(org.jboss.hal.config.Settings.Key.RUN_AS) Elements.span(org.jboss.gwt.elemento.core.Elements.span) Form(org.jboss.hal.ballroom.form.Form) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) Task(org.jboss.hal.flow.Task) AddScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddScopedRole) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Metadata(org.jboss.hal.meta.Metadata) ArrayList(java.util.ArrayList) FlowContext(org.jboss.hal.flow.FlowContext) RolesChangedEvent(org.jboss.hal.config.RolesChangedEvent) AddScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddScopedRole) Role(org.jboss.hal.config.Role) RemoveScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveScopedRole) ModifyScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyScopedRole) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ModifyIncludeAll(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyIncludeAll) ModelNode(org.jboss.hal.dmr.ModelNode) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping)

Example 4 with AddRoleMapping

use of org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping in project console by hal.

the class PrincipalColumn method collectTasks.

private void collectTasks(List<Task<FlowContext>> tasks, Principal.Type type, String name, boolean include, ModelNode modelNode, String attribute) {
    String realm = modelNode.hasDefined(REALM) ? modelNode.get(REALM).asString() : null;
    String resourceName = Principal.buildResourceName(type, name, realm);
    Principal principal = new Principal(type, resourceName, name, realm);
    if (modelNode.hasDefined(attribute)) {
        modelNode.get(attribute).asList().stream().map(nameNode -> accessControl.roles().get(Ids.role(nameNode.asString()))).forEach(role -> {
            if (role != null) {
                tasks.add(new CheckRoleMapping(dispatcher, role));
                tasks.add(new AddRoleMapping(dispatcher, role, status -> status == 404));
                tasks.add(new AddAssignment(dispatcher, role, principal, include));
            }
        });
    }
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Provider(javax.inject.Provider) MessageEvent(org.jboss.hal.spi.MessageEvent) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ItemAction(org.jboss.hal.core.finder.ItemAction) ItemDisplay(org.jboss.hal.core.finder.ItemDisplay) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) UniqueNameValidation(org.jboss.hal.ballroom.form.UniqueNameValidation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) Task(org.jboss.hal.flow.Task) StaticAutoComplete(org.jboss.hal.ballroom.autocomplete.StaticAutoComplete) Progress(org.jboss.hal.flow.Progress) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) RESTORE_SELECTION(org.jboss.hal.core.finder.FinderColumn.RefreshMode.RESTORE_SELECTION) FinderColumn(org.jboss.hal.core.finder.FinderColumn) User(org.jboss.hal.config.User) Comparator.comparing(java.util.Comparator.comparing) Metadata(org.jboss.hal.meta.Metadata) ColumnActionFactory(org.jboss.hal.core.finder.ColumnActionFactory) CompositeResult(org.jboss.hal.dmr.CompositeResult) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) INCLUDE_TEMPLATE(org.jboss.hal.client.accesscontrol.AddressTemplates.INCLUDE_TEMPLATE) Set(java.util.Set) EventBus(com.google.web.bindery.event.shared.EventBus) AddAssignment(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddAssignment) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Composite(org.jboss.hal.dmr.Composite) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) FormItem(org.jboss.hal.ballroom.form.FormItem) Resources(org.jboss.hal.resources.Resources) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) CLEAR_SELECTION(org.jboss.hal.core.finder.FinderColumn.RefreshMode.CLEAR_SELECTION) Flow.series(org.jboss.hal.flow.Flow.series) Role(org.jboss.hal.config.Role) Finder(org.jboss.hal.core.finder.Finder) ValidationResult(org.jboss.hal.ballroom.form.ValidationResult) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Form(org.jboss.hal.ballroom.form.Form) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) AddAssignment(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddAssignment) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping)

Example 5 with AddRoleMapping

use of org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping in project console by hal.

the class MembershipColumn method columnActionHandler.

private ColumnActionHandler<Assignment> columnActionHandler(Principal principal, boolean include) {
    return column -> {
        Role role = findRole(getFinder().getContext().getPath());
        if (role != null) {
            series(new FlowContext(progress.get()), new CheckRoleMapping(dispatcher, role), new AddRoleMapping(dispatcher, role, status -> status == 404), new AddAssignment(dispatcher, role, principal, include)).subscribe(new org.jboss.hal.core.SuccessfulOutcome<FlowContext>(eventBus, resources) {

                @Override
                public void onSuccess(FlowContext context) {
                    String type = principal.getType() == Principal.Type.USER ? resources.constants().user() : resources.constants().group();
                    SafeHtml message = include ? resources.messages().assignmentIncludeSuccess(type, principal.getName()) : resources.messages().assignmentExcludeSuccess(type, principal.getName());
                    MessageEvent.fire(eventBus, Message.success(message));
                    accessControl.reload(() -> {
                        refresh(RefreshMode.RESTORE_SELECTION);
                        if (isCurrentUser(principal)) {
                            eventBus.fireEvent(new UserChangedEvent());
                        }
                    });
                }
            });
        }
    };
}
Also used : ColumnActionHandler(org.jboss.hal.core.finder.ColumnActionHandler) Provider(javax.inject.Provider) AsyncColumn(org.jboss.hal.spi.AsyncColumn) ItemActionFactory(org.jboss.hal.core.finder.ItemActionFactory) MessageEvent(org.jboss.hal.spi.MessageEvent) ColumnAction(org.jboss.hal.core.finder.ColumnAction) ItemAction(org.jboss.hal.core.finder.ItemAction) ItemDisplay(org.jboss.hal.core.finder.ItemDisplay) FinderSegment(org.jboss.hal.core.finder.FinderSegment) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) UserChangedEvent(org.jboss.hal.config.UserChangedEvent) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Inject(javax.inject.Inject) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) Progress(org.jboss.hal.flow.Progress) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) FinderColumn(org.jboss.hal.core.finder.FinderColumn) User(org.jboss.hal.config.User) Comparator.comparing(java.util.Comparator.comparing) Collectors.toSet(java.util.stream.Collectors.toSet) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) INCLUDE_TEMPLATE(org.jboss.hal.client.accesscontrol.AddressTemplates.INCLUDE_TEMPLATE) EXCLUDE_TEMPLATE(org.jboss.hal.client.accesscontrol.AddressTemplates.EXCLUDE_TEMPLATE) REMOVE(org.jboss.hal.dmr.ModelDescriptionConstants.REMOVE) Set(java.util.Set) EventBus(com.google.web.bindery.event.shared.EventBus) AddAssignment(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddAssignment) FinderPath(org.jboss.hal.core.finder.FinderPath) Sets(com.google.common.collect.Sets) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) Resources(org.jboss.hal.resources.Resources) Flow.series(org.jboss.hal.flow.Flow.series) Role(org.jboss.hal.config.Role) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Elements.span(org.jboss.gwt.elemento.core.Elements.span) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) Role(org.jboss.hal.config.Role) UserChangedEvent(org.jboss.hal.config.UserChangedEvent) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) AddAssignment(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddAssignment) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) FlowContext(org.jboss.hal.flow.FlowContext) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping)

Aggregations

EventBus (com.google.web.bindery.event.shared.EventBus)5 HTMLElement (elemental2.dom.HTMLElement)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Collectors.toList (java.util.stream.Collectors.toList)5 Provider (javax.inject.Provider)5 AddRoleMapping (org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping)5 CheckRoleMapping (org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping)5 Role (org.jboss.hal.config.Role)5 Finder (org.jboss.hal.core.finder.Finder)5 FinderColumn (org.jboss.hal.core.finder.FinderColumn)5 ItemAction (org.jboss.hal.core.finder.ItemAction)5 ItemDisplay (org.jboss.hal.core.finder.ItemDisplay)5 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)5 Flow.series (org.jboss.hal.flow.Flow.series)5 FlowContext (org.jboss.hal.flow.FlowContext)5 Progress (org.jboss.hal.flow.Progress)5 Ids (org.jboss.hal.resources.Ids)5 Comparator.comparing (java.util.Comparator.comparing)4 Inject (javax.inject.Inject)4