Search in sources :

Example 6 with SwitchItem

use of org.jboss.hal.ballroom.form.SwitchItem 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 7 with SwitchItem

use of org.jboss.hal.ballroom.form.SwitchItem in project console by hal.

the class HostPresenter method disableSslForManagementInterface.

@Override
@SuppressWarnings("DuplicatedCode")
public void disableSslForManagementInterface() {
    Constants constants = resources.constants();
    String serverName = environment.isStandalone() ? Names.STANDALONE_SERVER : Names.DOMAIN_CONTROLLER;
    String label = constants.reload() + " " + serverName;
    SwitchItem reload = new SwitchItem(RELOAD, label);
    reload.setExpressionAllowed(false);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(RELOAD, FORM), Metadata.empty()).unboundFormItem(reload).build();
    form.attach();
    HTMLElement formElement = form.element();
    ModelNode model = new ModelNode();
    model.setEmptyObject();
    form.edit(model);
    ResourceAddress httpAddress = HTTP_INTERFACE_TEMPLATE.resolve(statementContext);
    DialogFactory.buildConfirmation(constants.disableSSL(), resources.messages().disableSSLManagementQuestion(serverName), formElement, Dialog.Size.MEDIUM, () -> {
        List<Task<FlowContext>> tasks = new ArrayList<>();
        // load the http-interface resource to get the port
        Task<FlowContext> loadHttpInterface = flowContext -> {
            Operation readHttpInterface = new Operation.Builder(httpAddress, READ_RESOURCE_OPERATION).build();
            return dispatcher.execute(readHttpInterface).doOnSuccess(value -> {
                if (value.hasDefined(PORT)) {
                    // only domain mode contains "port" attribute
                    String port = value.get(PORT).asString();
                    if (port.contains("$")) {
                        // if it contains an expression value, resolve it at host level
                        ResourceAddress address = AddressTemplate.of("/host=" + environment.getDomainController()).resolve(statementContext);
                        Operation readPort = new Operation.Builder(address, RESOLVE_EXPRESSION).param(EXPRESSION, port).build();
                        dispatcher.execute(readPort, portResult -> flowContext.set(PORT, portResult.asString()));
                    } else {
                        flowContext.set(PORT, port);
                    }
                }
            }).toCompletable();
        };
        tasks.add(loadHttpInterface);
        // in domain-mode read the /host=<dc> domain controller
        // it is important for later use if user wants to reload dc if in admin-mode
        Task<FlowContext> loadDc = flowContext -> {
            ResourceAddress dcAddress = AddressTemplate.of("/host=" + environment.getDomainController()).resolve(statementContext);
            Operation readDcOp = new Operation.Builder(dcAddress, READ_RESOURCE_OPERATION).param(ATTRIBUTES_ONLY, true).build();
            return dispatcher.execute(readDcOp).doOnSuccess(value -> flowContext.set(HOST, new Host(value))).toCompletable();
        };
        tasks.add(loadDc);
        // as part of the disable ssl task, undefine the secure-port, it only exists in domain mode
        Task<FlowContext> undefineSecurePortTask = flowContext -> {
            Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SECURE_PORT).build();
            return dispatcher.execute(op).toCompletable();
        };
        tasks.add(undefineSecurePortTask);
        // as part of the disable ssl task, undefine the ssl-context
        Task<FlowContext> undefineSslContextTask = flowContext -> {
            Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).build();
            return dispatcher.execute(op).toCompletable();
        };
        tasks.add(undefineSslContextTask);
        series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {

            @Override
            public void onSuccess(FlowContext flowContext) {
                if (reload.getValue() != null && reload.getValue()) {
                    String port = flowContext.get(PORT).toString();
                    // extracts the url search path, so the reload shows the same view the use is on
                    String urlSuffix = window.location.getHref();
                    urlSuffix = urlSuffix.substring(urlSuffix.indexOf("//") + 2);
                    urlSuffix = urlSuffix.substring(urlSuffix.indexOf("/"));
                    // the location to redirect the browser to the unsecure URL
                    // TODO Replace hardcoded scheme
                    String location = "http://" + window.location.getHostname() + ":" + port + urlSuffix;
                    Host host = flowContext.get(HOST);
                    reloadServer(host, location);
                } else {
                    reloadView();
                    MessageEvent.fire(getEventBus(), Message.success(resources.messages().disableSSLManagementSuccess()));
                }
            }

            @Override
            public void onError(FlowContext context, Throwable throwable) {
                MessageEvent.fire(getEventBus(), Message.error(resources.messages().disableSSLManagementError(throwable.getMessage())));
            }
        });
    }).show();
}
Also used : INCLUDE_RUNTIME(org.jboss.hal.dmr.ModelDescriptionConstants.INCLUDE_RUNTIME) TopologyTasks.reloadBlocking(org.jboss.hal.core.runtime.TopologyTasks.reloadBlocking) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) HTTP_INTERFACE_TEMPLATE(org.jboss.hal.client.runtime.host.AddressTemplates.HTTP_INTERFACE_TEMPLATE) VALUE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE) Map(java.util.Map) UNDEFINE_ATTRIBUTE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION) LIST_ADD_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.LIST_ADD_OPERATION) HttpManagementInterfacePresenter(org.jboss.hal.client.runtime.managementinterface.HttpManagementInterfacePresenter) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) MANAGEMENT_INTERFACE(org.jboss.hal.dmr.ModelDescriptionConstants.MANAGEMENT_INTERFACE) CrudOperations(org.jboss.hal.core.CrudOperations) INDEX(org.jboss.hal.dmr.ModelDescriptionConstants.INDEX) PATH(org.jboss.hal.dmr.ModelDescriptionConstants.PATH) RESULT(org.jboss.hal.dmr.ModelDescriptionConstants.RESULT) CORE_SERVICE(org.jboss.hal.dmr.ModelDescriptionConstants.CORE_SERVICE) Flow.series(org.jboss.hal.flow.Flow.series) SYSTEM_PROPERTY(org.jboss.hal.dmr.ModelDescriptionConstants.SYSTEM_PROPERTY) Footer(org.jboss.hal.spi.Footer) EXPRESSION(org.jboss.hal.dmr.ModelDescriptionConstants.EXPRESSION) ATTRIBUTES_ONLY(org.jboss.hal.dmr.ModelDescriptionConstants.ATTRIBUTES_ONLY) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) KEY_STORE(org.jboss.hal.dmr.ModelDescriptionConstants.KEY_STORE) JVM(org.jboss.hal.dmr.ModelDescriptionConstants.JVM) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Task(org.jboss.hal.flow.Task) RELOAD(org.jboss.hal.dmr.ModelDescriptionConstants.RELOAD) Progress(org.jboss.hal.flow.Progress) TRUST_MANAGER(org.jboss.hal.dmr.ModelDescriptionConstants.TRUST_MANAGER) CompositeResult(org.jboss.hal.dmr.CompositeResult) EnableSSLWizard(org.jboss.hal.client.shared.sslwizard.EnableSSLWizard) SSL_CONTEXT(org.jboss.hal.dmr.ModelDescriptionConstants.SSL_CONTEXT) Operation(org.jboss.hal.dmr.Operation) EventBus(com.google.web.bindery.event.shared.EventBus) WRITE_ATTRIBUTE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) DomGlobal.window(elemental2.dom.DomGlobal.window) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) NameTokens(org.jboss.hal.meta.token.NameTokens) READ_CHILDREN_NAMES_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_CHILDREN_NAMES_OPERATION) NamedNode(org.jboss.hal.dmr.NamedNode) ADMIN_ONLY(org.jboss.hal.dmr.ModelDescriptionConstants.ADMIN_ONLY) Form(org.jboss.hal.ballroom.form.Form) ConstantHeadersPresenter(org.jboss.hal.client.runtime.managementinterface.ConstantHeadersPresenter) Dialog(org.jboss.hal.ballroom.dialog.Dialog) LIST_REMOVE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.LIST_REMOVE_OPERATION) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) ELYTRON_TEMPLATE(org.jboss.hal.client.runtime.host.AddressTemplates.ELYTRON_TEMPLATE) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) KEY_MANAGER(org.jboss.hal.dmr.ModelDescriptionConstants.KEY_MANAGER) NAME(org.jboss.hal.dmr.ModelDescriptionConstants.NAME) SECURE_PORT(org.jboss.hal.dmr.ModelDescriptionConstants.SECURE_PORT) READ_RESOURCE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_RESOURCE_OPERATION) SOCKET_BINDING_GROUP(org.jboss.hal.dmr.ModelDescriptionConstants.SOCKET_BINDING_GROUP) PORT(org.jboss.hal.dmr.ModelDescriptionConstants.PORT) RESTART_SERVERS(org.jboss.hal.dmr.ModelDescriptionConstants.RESTART_SERVERS) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) FinderPath(org.jboss.hal.core.finder.FinderPath) FORM(org.jboss.hal.resources.Ids.FORM) Collectors(java.util.stream.Collectors) List(java.util.List) OperationFactory(org.jboss.hal.core.OperationFactory) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) Finder(org.jboss.hal.core.finder.Finder) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) HOST(org.jboss.hal.dmr.ModelDescriptionConstants.HOST) SupportsExpertMode(org.jboss.hal.core.mvp.SupportsExpertMode) ModelNode(org.jboss.hal.dmr.ModelNode) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) CHILD_TYPE(org.jboss.hal.dmr.ModelDescriptionConstants.CHILD_TYPE) HashMap(java.util.HashMap) CONSTANT_HEADERS(org.jboss.hal.dmr.ModelDescriptionConstants.CONSTANT_HEADERS) READ_CHILDREN_RESOURCES_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_CHILDREN_RESOURCES_OPERATION) Inject(javax.inject.Inject) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Constants(org.jboss.hal.resources.Constants) RESOLVE_EXPRESSION(org.jboss.hal.dmr.ModelDescriptionConstants.RESOLVE_EXPRESSION) INTERFACE(org.jboss.hal.dmr.ModelDescriptionConstants.INTERFACE) Requires(org.jboss.hal.spi.Requires) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) Ids(org.jboss.hal.resources.Ids) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) Composite(org.jboss.hal.dmr.Composite) HEADERS(org.jboss.hal.dmr.ModelDescriptionConstants.HEADERS) MANAGEMENT(org.jboss.hal.dmr.ModelDescriptionConstants.MANAGEMENT) MbuiPresenter(org.jboss.hal.core.mbui.MbuiPresenter) Resources(org.jboss.hal.resources.Resources) MbuiView(org.jboss.hal.core.mbui.MbuiView) EnableSSLPresenter(org.jboss.hal.client.shared.sslwizard.EnableSSLPresenter) SERVER_SSL_CONTEXT(org.jboss.hal.dmr.ModelDescriptionConstants.SERVER_SSL_CONTEXT) Host(org.jboss.hal.core.runtime.host.Host) Task(org.jboss.hal.flow.Task) HTMLElement(elemental2.dom.HTMLElement) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Constants(org.jboss.hal.resources.Constants) Host(org.jboss.hal.core.runtime.host.Host) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) List(java.util.List) ModelNode(org.jboss.hal.dmr.ModelNode) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem)

Aggregations

SwitchItem (org.jboss.hal.ballroom.form.SwitchItem)7 ModelNode (org.jboss.hal.dmr.ModelNode)7 Form (org.jboss.hal.ballroom.form.Form)6 List (java.util.List)5 ModelNodeForm (org.jboss.hal.core.mbui.form.ModelNodeForm)5 Metadata (org.jboss.hal.meta.Metadata)5 Ids (org.jboss.hal.resources.Ids)5 Resources (org.jboss.hal.resources.Resources)5 EventBus (com.google.web.bindery.event.shared.EventBus)4 HTMLElement (elemental2.dom.HTMLElement)4 ArrayList (java.util.ArrayList)4 Inject (javax.inject.Inject)4 Provider (javax.inject.Provider)4 LabelBuilder (org.jboss.hal.ballroom.LabelBuilder)4 DialogFactory (org.jboss.hal.ballroom.dialog.DialogFactory)4 Environment (org.jboss.hal.config.Environment)4 SuccessfulOutcome (org.jboss.hal.core.SuccessfulOutcome)4 Finder (org.jboss.hal.core.finder.Finder)4 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)4 Flow.series (org.jboss.hal.flow.Flow.series)4