Search in sources :

Example 11 with StatementContext

use of org.jboss.hal.meta.StatementContext in project console by hal.

the class RoleColumn method editScopedRole.

private void editScopedRole(Role role, String type, AddressTemplate template, AddressTemplate typeaheadTemplate, String formId, String scopeAttribute) {
    Metadata metadata = metadataRegistry.lookup(template);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(formId, metadata).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;
    }).unboundFormItem(new SwitchItem(INCLUDE_ALL, new LabelBuilder().label(INCLUDE_ALL)), 2, resources.messages().includeAllHelpText()).build();
    form.getFormItem(scopeAttribute).setRequired(true);
    form.getFormItem(scopeAttribute).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, typeaheadTemplate));
    form.getFormItem(INCLUDE_ALL).setValue(role.isIncludeAll());
    form.attach();
    ModelNode modelNode = new ModelNode();
    modelNode.get(BASE_ROLE).set(role.getBaseRole().getName());
    role.getScope().forEach(scope -> modelNode.get(scopeAttribute).add(scope));
    new ModifyResourceDialog(resources.messages().modifyResourceTitle(type), form, (frm, changedValues) -> {
        boolean includeAll = frm.<Boolean>getFormItem(INCLUDE_ALL).getValue();
        boolean includeAllChanged = includeAll != role.isIncludeAll();
        List<Task<FlowContext>> tasks = new ArrayList<>();
        if (!changedValues.isEmpty()) {
            tasks.add(new ModifyScopedRole(dispatcher, role, changedValues, metadata));
        }
        if (includeAllChanged) {
            tasks.add(new ModifyIncludeAll(dispatcher, role, 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().modifyResourceSuccess(type, role.getName())));
                accessControl.reload(() -> {
                    refresh(role.getId());
                    eventBus.fireEvent(new RolesChangedEvent());
                });
            }
        });
    }).show(modelNode);
}
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) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Metadata(org.jboss.hal.meta.Metadata) ModifyScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyScopedRole) FlowContext(org.jboss.hal.flow.FlowContext) RolesChangedEvent(org.jboss.hal.config.RolesChangedEvent) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) ModifyIncludeAll(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyIncludeAll) ModelNode(org.jboss.hal.dmr.ModelNode) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) ModifyResourceDialog(org.jboss.hal.core.mbui.dialog.ModifyResourceDialog)

Example 12 with StatementContext

use of org.jboss.hal.meta.StatementContext in project console by hal.

the class AccessControlSsoPresenter method onReset.

@Override
protected void onReset() {
    List<Task<FlowContext>> tasks = new ArrayList<>();
    tasks.add(flowContext -> {
        ResourceAddress address = KEYCLOAK_SECURE_SERVER_TEMPLATE.resolve(statementContext);
        Operation op = new Operation.Builder(address, READ_RESOURCE_OPERATION).build();
        flowContext.set(ADDRESS, address.toString());
        return dispatcher.execute(op).doOnSuccess(response -> {
            flowContext.set(REALM, response.get(REALM).asString());
        }).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().failedReadKeycloak(address.toString(), ex.getMessage())))).toCompletable();
    });
    tasks.add(flowContext -> {
        ResourceAddress address = KEYCLOAK_REALM_TEMPLATE.resolve(statementContext, flowContext.<String>get(REALM));
        Operation op = new Operation.Builder(address, READ_RESOURCE_OPERATION).build();
        flowContext.set(ADDRESS, address.toString());
        return dispatcher.execute(op).doOnSuccess(response -> {
            flowContext.set(KEYCLOAK_SERVER_URL, response.get(AUTH_SERVER_URL).asString());
            flowContext.set(REALM_PUBLIC_KEY, response.get(REALM_PUBLIC_KEY).asString());
        }).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().failedReadKeycloak(address.toString(), ex.getMessage())))).toCompletable();
    });
    series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {

        @Override
        public void onSuccess(FlowContext flowContext) {
            ModelNode payload = new ModelNode();
            payload.get(REALM).set(flowContext.<String>get(REALM));
            payload.get(REALM_PUBLIC_KEY).set(flowContext.<String>get(REALM_PUBLIC_KEY));
            payload.get(KEYCLOAK_SERVER_URL).set(flowContext.<String>get(KEYCLOAK_SERVER_URL));
            getView().update(payload);
        }

        @Override
        public void onError(FlowContext context, Throwable throwable) {
            String address = context.get(ADDRESS);
            MessageEvent.fire(getEventBus(), Message.error(resources.messages().failedReadKeycloak(address, throwable.getMessage())));
        }
    });
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) TopLevelPresenter(org.jboss.hal.core.mvp.TopLevelPresenter) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) ProxyStandard(com.gwtplatform.mvp.client.annotations.ProxyStandard) Message(org.jboss.hal.spi.Message) HasPresenter(org.jboss.hal.core.mvp.HasPresenter) Operation(org.jboss.hal.dmr.Operation) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) EventBus(com.google.web.bindery.event.shared.EventBus) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) HalView(org.jboss.hal.core.mvp.HalView) Flow.series(org.jboss.hal.flow.Flow.series) Footer(org.jboss.hal.spi.Footer) Task(org.jboss.hal.flow.Task) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 13 with StatementContext

use of org.jboss.hal.meta.StatementContext in project console by hal.

the class StandaloneServerPresenter 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, there are differente attributes for
        // standalone and domain mode.
        Task<FlowContext> loadHttpInterface = flowContext -> {
            Operation readHttpInterface = new Operation.Builder(httpAddress, READ_RESOURCE_OPERATION).build();
            return dispatcher.execute(readHttpInterface).doOnSuccess(value -> {
                if (value.hasDefined(SOCKET_BINDING)) {
                    // standalone mode uses a socket-binding for port
                    // store the socket-binding name in the flow context and on a later call
                    // read the socket-binding-group=<s-b-g>/socket-binding=<http-binding> to
                    // retrieve the port number
                    flowContext.set(SOCKET_BINDING, value.get(SOCKET_BINDING).asString());
                }
            }).toCompletable();
        };
        tasks.add(loadHttpInterface);
        // if standalone mode, read the socket-binding-group=<s-b-g>/socket-binding=<http-binding>
        // to retrieve the port number
        Task<FlowContext> readHttpPortTask = flowContext -> {
            Operation op = new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, SOCKET_BINDING_GROUP).build();
            return dispatcher.execute(op).doOnSuccess(result -> {
                String sbg = result.asList().get(0).asString();
                String httpBinding = flowContext.get(SOCKET_BINDING);
                ResourceAddress address = SOCKET_BINDING_GROUP_TEMPLATE.resolve(statementContext, sbg, httpBinding);
                Operation readPort = new Operation.Builder(address, READ_ATTRIBUTE_OPERATION).param(NAME, PORT).param(RESOLVE_EXPRESSIONS, true).build();
                dispatcher.execute(readPort, portResult -> flowContext.set(PORT, portResult.asString()));
            }).toCompletable();
        };
        tasks.add(readHttpPortTask);
        // as part of the disable ssl task, undefine the secure-socket-binding
        // the attribute only exists in standalone mode
        Task<FlowContext> undefSslTask = flowContext -> {
            Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SECURE_SOCKET_BINDING).build();
            return dispatcher.execute(op).toCompletable();
        };
        tasks.add(undefSslTask);
        // 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;
                    reloadServer(null, location);
                } else {
                    reload();
                    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 : Dialog(org.jboss.hal.ballroom.dialog.Dialog) INCLUDE_RUNTIME(org.jboss.hal.dmr.ModelDescriptionConstants.INCLUDE_RUNTIME) 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) TopologyTasks.reloadBlocking(org.jboss.hal.core.runtime.TopologyTasks.reloadBlocking) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) SOCKET_BINDING(org.jboss.hal.dmr.ModelDescriptionConstants.SOCKET_BINDING) VALUE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE) HTMLElement(elemental2.dom.HTMLElement) Map(java.util.Map) Message(org.jboss.hal.spi.Message) KEY_MANAGER(org.jboss.hal.dmr.ModelDescriptionConstants.KEY_MANAGER) NAME(org.jboss.hal.dmr.ModelDescriptionConstants.NAME) UNDEFINE_ATTRIBUTE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION) READ_RESOURCE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_RESOURCE_OPERATION) SOCKET_BINDING_GROUP(org.jboss.hal.dmr.ModelDescriptionConstants.SOCKET_BINDING_GROUP) Server(org.jboss.hal.core.runtime.server.Server) 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) PORT(org.jboss.hal.dmr.ModelDescriptionConstants.PORT) SOCKET_BINDING_GROUP_TEMPLATE(org.jboss.hal.client.shared.sslwizard.AbstractConfiguration.SOCKET_BINDING_GROUP_TEMPLATE) CrudOperations(org.jboss.hal.core.CrudOperations) RESOLVE_EXPRESSIONS(org.jboss.hal.dmr.ModelDescriptionConstants.RESOLVE_EXPRESSIONS) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) INDEX(org.jboss.hal.dmr.ModelDescriptionConstants.INDEX) FinderPath(org.jboss.hal.core.finder.FinderPath) SECURE_SOCKET_BINDING(org.jboss.hal.dmr.ModelDescriptionConstants.SECURE_SOCKET_BINDING) FORM(org.jboss.hal.resources.Ids.FORM) Collectors(java.util.stream.Collectors) List(java.util.List) OperationFactory(org.jboss.hal.core.OperationFactory) PATH(org.jboss.hal.dmr.ModelDescriptionConstants.PATH) RESULT(org.jboss.hal.dmr.ModelDescriptionConstants.RESULT) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) Flow.series(org.jboss.hal.flow.Flow.series) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SupportsExpertMode(org.jboss.hal.core.mvp.SupportsExpertMode) ModelNode(org.jboss.hal.dmr.ModelNode) ATTRIBUTES_ONLY(org.jboss.hal.dmr.ModelDescriptionConstants.ATTRIBUTES_ONLY) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) CHILD_TYPE(org.jboss.hal.dmr.ModelDescriptionConstants.CHILD_TYPE) KEY_STORE(org.jboss.hal.dmr.ModelDescriptionConstants.KEY_STORE) HashMap(java.util.HashMap) CONSTANT_HEADERS(org.jboss.hal.dmr.ModelDescriptionConstants.CONSTANT_HEADERS) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) 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) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Constants(org.jboss.hal.resources.Constants) TRUST_MANAGER(org.jboss.hal.dmr.ModelDescriptionConstants.TRUST_MANAGER) Requires(org.jboss.hal.spi.Requires) CompositeResult(org.jboss.hal.dmr.CompositeResult) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) EnableSSLWizard(org.jboss.hal.client.shared.sslwizard.EnableSSLWizard) SSL_CONTEXT(org.jboss.hal.dmr.ModelDescriptionConstants.SSL_CONTEXT) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) EventBus(com.google.web.bindery.event.shared.EventBus) READ_ATTRIBUTE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION) WRITE_ATTRIBUTE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) DomGlobal.window(elemental2.dom.DomGlobal.window) Composite(org.jboss.hal.dmr.Composite) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) HEADERS(org.jboss.hal.dmr.ModelDescriptionConstants.HEADERS) NameTokens(org.jboss.hal.meta.token.NameTokens) 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) READ_CHILDREN_NAMES_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_CHILDREN_NAMES_OPERATION) SERVER_SSL_CONTEXT(org.jboss.hal.dmr.ModelDescriptionConstants.SERVER_SSL_CONTEXT) START_MODE(org.jboss.hal.dmr.ModelDescriptionConstants.START_MODE) Host(org.jboss.hal.core.runtime.host.Host) Form(org.jboss.hal.ballroom.form.Form) ConstantHeadersPresenter(org.jboss.hal.client.runtime.managementinterface.ConstantHeadersPresenter) Task(org.jboss.hal.flow.Task) HTMLElement(elemental2.dom.HTMLElement) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Constants(org.jboss.hal.resources.Constants) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) List(java.util.List) ArrayList(java.util.ArrayList) ModelNode(org.jboss.hal.dmr.ModelNode) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem)

Example 14 with StatementContext

use of org.jboss.hal.meta.StatementContext in project console by hal.

the class StoresPresenter method importCertificate.

void importCertificate(Metadata metadata, String name) {
    AddressTemplate template = metadata.getTemplate();
    String resource = Names.KEY_STORE + SPACE + name;
    metadata = metadata.forOperation(IMPORT_CERTIFICATE);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(template.lastName(), IMPORT_CERTIFICATE), metadata).build();
    form.setSaveCallback((form1, changedValues) -> {
        ModelNode payload = form.getModel();
        String path = payload.get(PATH).asString();
        if (!payload.hasDefined(VALIDATE)) {
            payload.get(VALIDATE).set(false);
        }
        ResourceAddress address = template.resolve(statementContext, name);
        String alias = payload.get(ALIAS).asString();
        List<Task<FlowContext>> tasks = new ArrayList<>();
        tasks.add(flowContext -> {
            Operation operation = new Operation.Builder(address, IMPORT_CERTIFICATE).payload(payload).build();
            return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().importCertificateError(alias, path, resource, ex.getMessage())))).toCompletable();
        });
        tasks.add(flowContext -> {
            Operation operation = new Operation.Builder(KEY_STORE_TEMPLATE.resolve(statementContext, name), STORE).build();
            return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().storeError(resource, ex.getMessage())))).toCompletable();
        });
        tasks.add(flowContext -> {
            Operation operation = new Operation.Builder(address, READ_ALIASES_OPERATION).build();
            return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().readAliasesError(resource, ex.getMessage())))).toCompletable();
        });
        series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {

            @Override
            public void onSuccess(FlowContext flowContext) {
                MessageEvent.fire(getEventBus(), Message.success(resources.messages().importCertificateSuccess(alias, path, resource)));
            }

            @Override
            public void onError(FlowContext context, Throwable ex) {
                MessageEvent.fire(getEventBus(), Message.error(resources.messages().removeAliasError(alias, resource, ex.getMessage())));
            }
        });
    });
    Dialog dialog = new Dialog.Builder(resources.constants().importCertificate()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().importt(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
    dialog.registerAttachable(form);
    dialog.show();
    form.edit(new ModelNode());
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) Dialog(org.jboss.hal.ballroom.dialog.Dialog) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) Date(java.util.Date) StatementContext(org.jboss.hal.meta.StatementContext) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Icons(org.jboss.hal.resources.Icons) Elements.p(org.jboss.gwt.elemento.core.Elements.p) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) HasPresenter(org.jboss.hal.core.mvp.HasPresenter) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) 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) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) AddressTemplates(org.jboss.hal.client.runtime.subsystem.elytron.AddressTemplates) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) HalView(org.jboss.hal.core.mvp.HalView) CalendarUtil(com.google.gwt.user.datepicker.client.CalendarUtil) Flow.series(org.jboss.hal.flow.Flow.series) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SupportsExpertMode(org.jboss.hal.core.mvp.SupportsExpertMode) ModelNode(org.jboss.hal.dmr.ModelNode) Elements.div(org.jboss.gwt.elemento.core.Elements.div) Alert(org.jboss.hal.ballroom.Alert) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) ApplicationFinderPresenter(org.jboss.hal.core.mvp.ApplicationFinderPresenter) Requires(org.jboss.hal.spi.Requires) CompositeResult(org.jboss.hal.dmr.CompositeResult) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) EventBus(com.google.web.bindery.event.shared.EventBus) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Consumer(java.util.function.Consumer) Composite(org.jboss.hal.dmr.Composite) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) Format(org.jboss.hal.ballroom.Format) SuggestCapabilitiesAutoComplete(org.jboss.hal.ballroom.autocomplete.SuggestCapabilitiesAutoComplete) NamedNode(org.jboss.hal.dmr.NamedNode) Collections(java.util.Collections) Form(org.jboss.hal.ballroom.form.Form) Task(org.jboss.hal.flow.Task) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) FlowContext(org.jboss.hal.flow.FlowContext) Dialog(org.jboss.hal.ballroom.dialog.Dialog) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 15 with StatementContext

use of org.jboss.hal.meta.StatementContext in project console by hal.

the class PasswordWizard method show.

public void show() {
    Constants constants = resources.constants();
    Wizard.Builder<PasswordContext, PasswordState> wb = new Wizard.Builder<>(constants.setIdentityPasswordTitle(), new PasswordContext());
    wb.addStep(PasswordState.CHOOSE_PASSWORD_TYPE, new ChoosePasswordTypeStep(resources)).addStep(PasswordState.CONFIGURATION, new ConfigurePasswordStep(resources, metadata)).addStep(PasswordState.REVIEW, new ReviewPasswordStep(resources, metadata)).onBack((context, currentState) -> {
        PasswordState previous = null;
        switch(currentState) {
            case CHOOSE_PASSWORD_TYPE:
                break;
            case CONFIGURATION:
                previous = PasswordState.CHOOSE_PASSWORD_TYPE;
                break;
            case REVIEW:
                previous = PasswordState.CONFIGURATION;
                break;
            default:
                break;
        }
        return previous;
    }).onNext((context, currentState) -> {
        PasswordState next = null;
        switch(currentState) {
            case CHOOSE_PASSWORD_TYPE:
                next = PasswordState.CONFIGURATION;
                break;
            case CONFIGURATION:
                next = PasswordState.REVIEW;
                break;
            case REVIEW:
                break;
            default:
                break;
        }
        return next;
    }).onFinish((wizard, context) -> {
        ResourceAddress address = metadata.getTemplate().resolve(statementContext, selectedRealm);
        Operation operation = new Operation.Builder(address, SET_PASSWORD).param(IDENTITY, selectedIdentity).param(context.type.name, context.model).build();
        LabelBuilder labelBuilder = new LabelBuilder();
        String type = labelBuilder.label(metadata.getTemplate().lastName());
        String resourceName = type + "" + selectedRealm;
        dispatcher.execute(operation, result -> MessageEvent.fire(eventBus, Message.success(resources.messages().setIdentityPasswordSuccess(selectedIdentity, resourceName))), (operation1, failure) -> MessageEvent.fire(eventBus, Message.error(resources.messages().setIdentityPasswordError(selectedIdentity, resourceName, failure))), (operation1, exception) -> MessageEvent.fire(eventBus, Message.error(resources.messages().setIdentityPasswordError(selectedIdentity, resourceName, exception.getMessage()))));
    });
    Wizard<PasswordContext, PasswordState> wizard = wb.build();
    wizard.show();
}
Also used : IDENTITY(org.jboss.hal.dmr.ModelDescriptionConstants.IDENTITY) Operation(org.jboss.hal.dmr.Operation) StatementContext(org.jboss.hal.meta.StatementContext) MessageEvent(org.jboss.hal.spi.MessageEvent) Wizard(org.jboss.hal.ballroom.wizard.Wizard) EventBus(com.google.web.bindery.event.shared.EventBus) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Resources(org.jboss.hal.resources.Resources) Constants(org.jboss.hal.resources.Constants) SET_PASSWORD(org.jboss.hal.dmr.ModelDescriptionConstants.SET_PASSWORD) Message(org.jboss.hal.spi.Message) Metadata(org.jboss.hal.meta.Metadata) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Constants(org.jboss.hal.resources.Constants) Operation(org.jboss.hal.dmr.Operation) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Wizard(org.jboss.hal.ballroom.wizard.Wizard)

Aggregations

StatementContext (org.jboss.hal.meta.StatementContext)51 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)47 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)46 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)46 ModelNode (org.jboss.hal.dmr.ModelNode)44 Resources (org.jboss.hal.resources.Resources)44 Ids (org.jboss.hal.resources.Ids)43 EventBus (com.google.web.bindery.event.shared.EventBus)42 List (java.util.List)42 Names (org.jboss.hal.resources.Names)41 Inject (javax.inject.Inject)40 Metadata (org.jboss.hal.meta.Metadata)40 Finder (org.jboss.hal.core.finder.Finder)37 Operation (org.jboss.hal.dmr.Operation)37 Requires (org.jboss.hal.spi.Requires)37 AddressTemplate (org.jboss.hal.meta.AddressTemplate)36 Form (org.jboss.hal.ballroom.form.Form)35 FinderPath (org.jboss.hal.core.finder.FinderPath)35 FinderPathFactory (org.jboss.hal.core.finder.FinderPathFactory)34 ModelNodeForm (org.jboss.hal.core.mbui.form.ModelNodeForm)34