Search in sources :

Example 1 with SOCKET_BINDING_GROUP

use of org.jboss.hal.dmr.ModelDescriptionConstants.SOCKET_BINDING_GROUP 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)

Aggregations

SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 EventBus (com.google.web.bindery.event.shared.EventBus)1 NameToken (com.gwtplatform.mvp.client.annotations.NameToken)1 ProxyCodeSplit (com.gwtplatform.mvp.client.annotations.ProxyCodeSplit)1 ProxyPlace (com.gwtplatform.mvp.client.proxy.ProxyPlace)1 DomGlobal.window (elemental2.dom.DomGlobal.window)1 HTMLElement (elemental2.dom.HTMLElement)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Provider (javax.inject.Provider)1 Dialog (org.jboss.hal.ballroom.dialog.Dialog)1 DialogFactory (org.jboss.hal.ballroom.dialog.DialogFactory)1 Form (org.jboss.hal.ballroom.form.Form)1 SwitchItem (org.jboss.hal.ballroom.form.SwitchItem)1 ConstantHeadersPresenter (org.jboss.hal.client.runtime.managementinterface.ConstantHeadersPresenter)1 HttpManagementInterfacePresenter (org.jboss.hal.client.runtime.managementinterface.HttpManagementInterfacePresenter)1