Search in sources :

Example 1 with Constants

use of org.jboss.hal.resources.Constants in project console by hal.

the class LoggingProfileView method init.

@PostConstruct
@SuppressWarnings("Duplicates")
void init() {
    Constants constants = mbuiContext.resources().constants();
    noRootLogger = new EmptyState.Builder(Ids.LOGGING_PROFILE + "-root-logger-empty", constants.noRootLogger()).description(constants.noRootLoggerDescription()).icon(fontAwesome("sitemap")).primaryAction(constants.add(), this::addRootLogger).build();
    noRootLogger.element().classList.add(marginTopLarge);
    // hack which relies on the element hierarchy given in the template. will break if you change that hierarchy.
    rootLoggerForm.element().parentNode.appendChild(noRootLogger.element());
    rootLoggerVisibility(false);
    // --------------------------- json formatter
    AddressTemplate jsonTemplate = LOGGING_PROFILE_TEMPLATE.append(JSON_FORMATTER_TEMPLATE.lastName() + EQ_WILDCARD);
    LabelBuilder labelBuilder = new LabelBuilder();
    Metadata jsonMetadata = mbuiContext.metadataRegistry().lookup(jsonTemplate);
    Metadata jsonKeyOverridesMetadata = jsonMetadata.forComplexAttribute(KEY_OVERRIDES);
    String jsonLabel = labelBuilder.label(jsonTemplate.lastName());
    jsonFormatterTable = new ModelNodeTable.Builder<NamedNode>(Ids.build(LOGGING_PROFILE, JSON, FORMATTER, TABLE), jsonMetadata).button(constants.add(), table -> crud().add(Ids.build(LOGGING_PROFILE, JSON, FORMATTER, ADD), Names.JSON_FORMATTER, jsonTemplate.replaceWildcards(presenter.getLoggingProfile()), (name, address) -> presenter.reload()), Constraint.executable(jsonTemplate, ADD)).button(constants.remove(), table -> crud().remove(Names.JSON_FORMATTER, table.selectedRow().getName(), jsonTemplate.replaceWildcards(presenter.getLoggingProfile()), () -> presenter.reload()), Constraint.executable(jsonTemplate, REMOVE)).column(NAME, (cell, type, row, meta) -> row.getName()).build();
    jsonFormatterForm = new ModelNodeForm.Builder<NamedNode>(Ids.build(LOGGING_PROFILE, JSON, FORMATTER, FORM), jsonMetadata).onSave((form, changedValues) -> mbuiContext.crud().save(jsonLabel, form.getModel().getName(), jsonTemplate.replaceWildcards(presenter.getLoggingProfile()), changedValues, () -> presenter.reload())).prepareReset(form -> mbuiContext.crud().reset(jsonLabel, jsonFormatterTable.selectedRow().getName(), jsonTemplate.replaceWildcards(presenter.getLoggingProfile()), form, jsonMetadata, () -> presenter.reload())).build();
    jsonKeyOverridesForm = new ModelNodeForm.Builder<>(Ids.build(LOGGING_PROFILE, FORMATTER, JSON, KEY_OVERRIDES, FORM), jsonKeyOverridesMetadata).singleton(() -> {
        StatementContext jsonStatementContext = new SelectionAwareStatementContext(mbuiContext.statementContext(), () -> jsonFormatterTable.hasSelection() ? jsonFormatterTable.selectedRow().getName() : null);
        ResourceAddress address = jsonTemplate.resolve(jsonStatementContext, presenter.getLoggingProfile());
        return new Operation.Builder(address, READ_ATTRIBUTE_OPERATION).param(NAME, KEY_OVERRIDES).build();
    }, () -> presenter.addComplexObject(jsonLabel, jsonFormatterTable.selectedRow().getName(), KEY_OVERRIDES, jsonTemplate.replaceWildcards(presenter.getLoggingProfile()))).onSave((form, changedValues) -> presenter.saveComplexObject(jsonLabel, jsonFormatterTable.selectedRow().getName(), KEY_OVERRIDES, jsonTemplate.replaceWildcards(presenter.getLoggingProfile()), changedValues)).prepareReset(form -> presenter.resetComplexObject(jsonLabel, jsonFormatterTable.selectedRow().getName(), KEY_OVERRIDES, jsonTemplate.replaceWildcards(presenter.getLoggingProfile()), jsonKeyOverridesMetadata, form)).prepareRemove(form -> presenter.removeComplexObject(jsonLabel, jsonFormatterTable.selectedRow().getName(), KEY_OVERRIDES, jsonTemplate.replaceWildcards(presenter.getLoggingProfile()))).build();
    Tabs jsonTabs = new Tabs(Ids.build(LOGGING_PROFILE, FORMATTER, JSON, TAB_CONTAINER));
    jsonTabs.add(Ids.build(LOGGING_PROFILE, FORMATTER, JSON, ATTRIBUTES, TAB), constants.attributes(), jsonFormatterForm.element());
    jsonTabs.add(Ids.build(LOGGING_PROFILE, FORMATTER, JSON, KEY_OVERRIDES, TAB), Names.KEY_OVERRIDES, jsonKeyOverridesForm.element());
    HTMLElement jsonSection = section().add(h(1).textContent(Names.JSON_FORMATTER)).add(p().textContent(jsonMetadata.getDescription().getDescription())).add(jsonFormatterTable).add(jsonTabs).element();
    registerAttachable(jsonFormatterTable, jsonFormatterForm, jsonKeyOverridesForm);
    navigation.insertSecondary("logging-profile-formatter-item", Ids.build(LOGGING_PROFILE, FORMATTER, JSON, Ids.ITEM), null, Names.JSON_FORMATTER, jsonSection);
    // --------------------------- xml formatter
    AddressTemplate xmlTemplate = LOGGING_PROFILE_TEMPLATE.append(XML_FORMATTER_TEMPLATE.lastName() + EQ_WILDCARD);
    Metadata xmlMetadata = mbuiContext.metadataRegistry().lookup(xmlTemplate);
    Metadata xmlKeyOverridesMetadata = xmlMetadata.forComplexAttribute(KEY_OVERRIDES);
    String xmlLabel = labelBuilder.label(xmlTemplate.lastName());
    xmlFormatterTable = new ModelNodeTable.Builder<NamedNode>(Ids.build(LOGGING_PROFILE, XML, FORMATTER, TABLE), xmlMetadata).button(constants.add(), table -> crud().add(Ids.build(LOGGING_PROFILE, XML, FORMATTER, ADD), Names.XML_FORMATTER, xmlTemplate.replaceWildcards(presenter.getLoggingProfile()), (name, address) -> presenter.reload()), Constraint.executable(xmlTemplate, ADD)).button(constants.remove(), table -> crud().remove(Names.XML_FORMATTER, table.selectedRow().getName(), xmlTemplate.replaceWildcards(presenter.getLoggingProfile()), () -> presenter.reload()), Constraint.executable(xmlTemplate, REMOVE)).column(NAME, (cell, type, row, meta) -> row.getName()).build();
    xmlFormatterForm = new ModelNodeForm.Builder<NamedNode>(Ids.build(LOGGING_PROFILE, XML, FORMATTER, FORM), xmlMetadata).onSave((form, changedValues) -> mbuiContext.crud().save(xmlLabel, form.getModel().getName(), xmlTemplate.replaceWildcards(presenter.getLoggingProfile()), changedValues, () -> presenter.reload())).prepareReset(form -> mbuiContext.crud().reset(xmlLabel, xmlFormatterTable.selectedRow().getName(), xmlTemplate.replaceWildcards(presenter.getLoggingProfile()), form, xmlMetadata, () -> presenter.reload())).build();
    xmlKeyOverridesForm = new ModelNodeForm.Builder<>(Ids.build(LOGGING_PROFILE, FORMATTER, XML, KEY_OVERRIDES, FORM), xmlKeyOverridesMetadata).singleton(() -> {
        StatementContext xmlStatementContext = new SelectionAwareStatementContext(mbuiContext.statementContext(), () -> xmlFormatterTable.hasSelection() ? xmlFormatterTable.selectedRow().getName() : null);
        ResourceAddress address = xmlTemplate.resolve(xmlStatementContext, presenter.getLoggingProfile());
        return new Operation.Builder(address, READ_ATTRIBUTE_OPERATION).param(NAME, KEY_OVERRIDES).build();
    }, () -> presenter.addComplexObject(xmlLabel, xmlFormatterTable.selectedRow().getName(), KEY_OVERRIDES, xmlTemplate.replaceWildcards(presenter.getLoggingProfile()))).onSave((form, changedValues) -> presenter.saveComplexObject(xmlLabel, xmlFormatterTable.selectedRow().getName(), KEY_OVERRIDES, xmlTemplate.replaceWildcards(presenter.getLoggingProfile()), changedValues)).prepareReset(form -> presenter.resetComplexObject(xmlLabel, xmlFormatterTable.selectedRow().getName(), KEY_OVERRIDES, xmlTemplate.replaceWildcards(presenter.getLoggingProfile()), xmlKeyOverridesMetadata, form)).prepareRemove(form -> presenter.removeComplexObject(xmlLabel, xmlFormatterTable.selectedRow().getName(), KEY_OVERRIDES, xmlTemplate.replaceWildcards(presenter.getLoggingProfile()))).build();
    Tabs xmlTabs = new Tabs(Ids.build(LOGGING_PROFILE, FORMATTER, XML, TAB_CONTAINER));
    xmlTabs.add(Ids.build(LOGGING_PROFILE, FORMATTER, XML, ATTRIBUTES, TAB), constants.attributes(), xmlFormatterForm.element());
    xmlTabs.add(Ids.build(LOGGING_PROFILE, FORMATTER, XML, KEY_OVERRIDES, TAB), Names.KEY_OVERRIDES, xmlKeyOverridesForm.element());
    HTMLElement xmlSection = section().add(h(1).textContent(Names.XML_FORMATTER)).add(p().textContent(xmlMetadata.getDescription().getDescription())).add(xmlFormatterTable).add(xmlTabs).element();
    registerAttachable(xmlFormatterTable, xmlFormatterForm, xmlKeyOverridesForm);
    navigation.insertSecondary("logging-profile-formatter-item", Ids.build(LOGGING_PROFILE, FORMATTER, XML, Ids.ITEM), null, Names.XML_FORMATTER, xmlSection);
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) Constraint(org.jboss.hal.meta.security.Constraint) StatementContext(org.jboss.hal.meta.StatementContext) LOGGING_PROFILE_TEMPLATE(org.jboss.hal.client.configuration.subsystem.logging.AddressTemplates.LOGGING_PROFILE_TEMPLATE) TAB_CONTAINER(org.jboss.hal.resources.Ids.TAB_CONTAINER) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Elements.p(org.jboss.gwt.elemento.core.Elements.p) HTMLElement(elemental2.dom.HTMLElement) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) Elements.h(org.jboss.gwt.elemento.core.Elements.h) CrudOperations(org.jboss.hal.core.CrudOperations) Table(org.jboss.hal.ballroom.table.Table) Collections.emptyList(java.util.Collections.emptyList) SuggestHandler(org.jboss.hal.ballroom.form.SuggestHandler) FORM(org.jboss.hal.resources.Ids.FORM) VerticalNavigation(org.jboss.hal.ballroom.VerticalNavigation) ModelNodeHelper.failSafeGet(org.jboss.hal.dmr.ModelNodeHelper.failSafeGet) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) SelectionAwareStatementContext(org.jboss.hal.meta.SelectionAwareStatementContext) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) PostConstruct(javax.annotation.PostConstruct) JSON_FORMATTER_TEMPLATE(org.jboss.hal.client.configuration.subsystem.logging.AddressTemplates.JSON_FORMATTER_TEMPLATE) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) ModelNode(org.jboss.hal.dmr.ModelNode) FileFormItem(org.jboss.hal.core.ui.FileFormItem) ModelNodeTable(org.jboss.hal.core.mbui.table.ModelNodeTable) MbuiViewImpl(org.jboss.hal.core.mbui.MbuiViewImpl) Tabs(org.jboss.hal.ballroom.Tabs) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) XML_FORMATTER_TEMPLATE(org.jboss.hal.client.configuration.subsystem.logging.AddressTemplates.XML_FORMATTER_TEMPLATE) TAB(org.jboss.hal.resources.Ids.TAB) Elements.section(org.jboss.gwt.elemento.core.Elements.section) AddressTemplate(org.jboss.hal.meta.AddressTemplate) MbuiElement(org.jboss.hal.spi.MbuiElement) Constants(org.jboss.hal.resources.Constants) EmptyState(org.jboss.hal.ballroom.EmptyState) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) DomGlobal.document(elemental2.dom.DomGlobal.document) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) CATEGORY(org.jboss.hal.resources.Names.CATEGORY) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) CSS.marginTopLarge(org.jboss.hal.resources.CSS.marginTopLarge) FormItem(org.jboss.hal.ballroom.form.FormItem) MbuiContext(org.jboss.hal.core.mbui.MbuiContext) MbuiView(org.jboss.hal.spi.MbuiView) SELECTED_LOGGING_PROFILE_TEMPLATE(org.jboss.hal.client.configuration.subsystem.logging.AddressTemplates.SELECTED_LOGGING_PROFILE_TEMPLATE) NamedNode(org.jboss.hal.dmr.NamedNode) Elements(org.jboss.gwt.elemento.core.Elements) Form(org.jboss.hal.ballroom.form.Form) EmptyState(org.jboss.hal.ballroom.EmptyState) HTMLElement(elemental2.dom.HTMLElement) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Metadata(org.jboss.hal.meta.Metadata) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Constants(org.jboss.hal.resources.Constants) NamedNode(org.jboss.hal.dmr.NamedNode) Operation(org.jboss.hal.dmr.Operation) SelectionAwareStatementContext(org.jboss.hal.meta.SelectionAwareStatementContext) StatementContext(org.jboss.hal.meta.StatementContext) SelectionAwareStatementContext(org.jboss.hal.meta.SelectionAwareStatementContext) ModelNodeTable(org.jboss.hal.core.mbui.table.ModelNodeTable) Tabs(org.jboss.hal.ballroom.Tabs) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) PostConstruct(javax.annotation.PostConstruct)

Example 2 with Constants

use of org.jboss.hal.resources.Constants in project console by hal.

the class EnableSSLWizard method show.

public void show() {
    Constants constants = resources.constants();
    AddressTemplate template = undertowHttps ? UNDERTOW_HTTPS_LISTENER_TEMPLATE : HTTP_INTERFACE_TEMPLATE;
    Wizard.Builder<EnableSSLContext, EnableSSLState> wb = new Wizard.Builder<>(constants.enableSSLManagementTitle(), new EnableSSLContext());
    wb.addStep(EnableSSLState.DEFINE_STRATEGY, new DefineStrategyStep(resources, environment.isStandalone(), undertowHttps)).addStep(EnableSSLState.CONFIGURATION, new ConfigurationStep(existingResources, resources, environment, undertowHttps, template)).addStep(EnableSSLState.REVIEW, new ReviewStep(dispatcher, statementContext, resources, environment, undertowHttps, template)).onBack((context, currentState) -> {
        EnableSSLState previous = null;
        switch(currentState) {
            case DEFINE_STRATEGY:
                break;
            case CONFIGURATION:
                previous = EnableSSLState.DEFINE_STRATEGY;
                break;
            case REVIEW:
                previous = EnableSSLState.CONFIGURATION;
                break;
            default:
                break;
        }
        return previous;
    }).onNext((context, currentState) -> {
        EnableSSLState next = null;
        switch(currentState) {
            case DEFINE_STRATEGY:
                next = EnableSSLState.CONFIGURATION;
                break;
            case CONFIGURATION:
                next = EnableSSLState.REVIEW;
                break;
            case REVIEW:
                break;
            default:
                break;
        }
        return next;
    }).stayOpenAfterFinish().onFinish((wizard, context) -> {
        ModelNode model = context.model;
        ModelNode credRef = new ModelNode();
        credRef.get(CLEAR_TEXT).set(asString(model, AbstractConfiguration.KEY_STORE_PASSWORD));
        // use Flow tasks to run DMR operations as there are resources that must exists before next
        // operations are called, as in the example of a generate-key-pair and import-certificate
        // the key-store must exists. For this case, the Composite doesn't work.
        List<Task<FlowContext>> tasks = new ArrayList<>();
        // key-store is only created when user chooses to create all resources or create a key-store based on
        // an existing JKS file
        boolean createKeyStore = !context.strategy.equals(EnableSSLContext.Strategy.KEYSTORE_RESOURCE_EXISTS);
        String keyStoreName = createKeyStore ? asString(model, AbstractConfiguration.KEY_STORE_NAME) : asString(model, KEY_STORE);
        if (createKeyStore) {
            if (context.strategy.equals(EnableSSLContext.Strategy.KEYSTORE_CREATE)) {
                ResourceAddress ksAddress = keyStoreTemplate().resolve(statementContext, keyStoreName);
                tasks.add(flowContext -> {
                    Operation.Builder builder = new Operation.Builder(ksAddress, ADD).param(PATH, asString(model, KEY_STORE_PATH)).param(CREDENTIAL_REFERENCE, credRef).param(TYPE, asString(model, AbstractConfiguration.KEY_STORE_TYPE));
                    if (model.hasDefined(AbstractConfiguration.KEY_STORE_RELATIVE_TO)) {
                        builder.param(RELATIVE_TO, asString(model, AbstractConfiguration.KEY_STORE_RELATIVE_TO));
                    }
                    Operation keyStoreOp = builder.build();
                    return dispatcher.execute(keyStoreOp).doOnError(exception -> wizard.showError(constants.failed(), resources.messages().addKeyStoreError(keyStoreName), exception.getMessage(), false)).toCompletable();
                });
                tasks.add(flowContext -> {
                    Composite composite = new Composite();
                    // the generate-key=pair can only be called on an existing key-store
                    String dn = "CN=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_CN) + ", OU=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_OU) + ", O=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_O) + ", L=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_L) + ", ST=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_ST) + ", C=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_C);
                    Operation genKeyOp = new Operation.Builder(ksAddress, GENERATE_KEY_PAIR).param(ALIAS, asString(model, AbstractConfiguration.PRIVATE_KEY_ALIAS)).param(DISTINGUISHED_NAME, dn).param(VALIDITY, asString(model, AbstractConfiguration.PRIVATE_KEY_VALIDITY)).param(ModelDescriptionConstants.ALGORITHM, asString(model, AbstractConfiguration.PRIVATE_KEY_ALGORITHM)).build();
                    composite.add(genKeyOp);
                    Operation storeOp = new Operation.Builder(ksAddress, STORE).build();
                    composite.add(storeOp);
                    return dispatcher.execute(composite).toCompletable();
                });
            } else if (context.strategy.equals(EnableSSLContext.Strategy.KEYSTORE_FILE_EXISTS)) {
                tasks.add(flowContext -> {
                    ResourceAddress ksAddress = keyStoreTemplate().resolve(statementContext, keyStoreName);
                    Operation.Builder builder = new Operation.Builder(ksAddress, ADD).param(PATH, asString(model, KEY_STORE_PATH)).param(CREDENTIAL_REFERENCE, credRef).param(TYPE, asString(model, AbstractConfiguration.KEY_STORE_TYPE)).param(REQUIRED, true);
                    if (model.hasDefined(AbstractConfiguration.KEY_STORE_RELATIVE_TO)) {
                        builder.param(RELATIVE_TO, asString(model, AbstractConfiguration.KEY_STORE_RELATIVE_TO));
                    }
                    Operation keyStoreOp = builder.build();
                    return dispatcher.execute(keyStoreOp).doOnError(exception -> wizard.showError(constants.failed(), resources.messages().addKeyStoreError(keyStoreName), exception.getMessage(), false)).toCompletable();
                });
            } else if (context.strategy.equals(EnableSSLContext.Strategy.KEYSTORE_OBTAIN_LETSENCRYPT)) {
                ResourceAddress ksAddress = keyStoreTemplate().resolve(statementContext, keyStoreName);
                tasks.add(flowContext -> {
                    Operation.Builder builder = new Operation.Builder(ksAddress, ADD).param(PATH, asString(model, KEY_STORE_PATH)).param(CREDENTIAL_REFERENCE, credRef).param(TYPE, asString(model, AbstractConfiguration.KEY_STORE_TYPE));
                    if (model.hasDefined(AbstractConfiguration.KEY_STORE_RELATIVE_TO)) {
                        builder.param(RELATIVE_TO, asString(model, AbstractConfiguration.KEY_STORE_RELATIVE_TO));
                    }
                    Operation keyStoreOp = builder.build();
                    return dispatcher.execute(keyStoreOp).doOnError(exception -> wizard.showError(constants.failed(), resources.messages().addKeyStoreError(keyStoreName), exception.getMessage(), false)).toCompletable();
                });
                String caaName = asString(model, CAA_NAME);
                ResourceAddress caaAddress = certificateAuthorityAccountTemplate().resolve(statementContext, caaName);
                tasks.add(flowContext -> {
                    Operation caaOp = new Operation.Builder(caaAddress, ADD).param(KEY_STORE, keyStoreName).param(ALIAS, asString(model, CAA_ALIAS)).build();
                    return dispatcher.execute(caaOp).doOnError(exception -> wizard.showError(constants.failed(), resources.messages().addResourceError(caaName, exception.getMessage()), false)).toCompletable();
                });
                tasks.add(flowContext -> {
                    Composite composite = new Composite();
                    String obtainAlias = asString(model, PRIVATE_KEY_ALIAS);
                    Operation obtainOp = new Operation.Builder(ksAddress, OBTAIN_CERTIFICATE).param(ALIAS, obtainAlias).param(CERTIFICATE_AUTHORITY_ACCOUNT, caaName).param("domain-names", model.get(CAA_DOMAIN_NAMES)).param("agree-to-terms-of-service", true).param("staging", asString(model, CAA_STAGING)).build();
                    composite.add(obtainOp);
                    Operation storeOp = new Operation.Builder(ksAddress, STORE).build();
                    composite.add(storeOp);
                    return dispatcher.execute(composite).doOnError(ex -> wizard.showError(constants.failed(), resources.messages().obtainCertificateError(obtainAlias, keyStoreName, ex.getMessage()), false)).toCompletable();
                });
            }
        }
        String trustManagerName = model.hasDefined(TRUST_MANAGER) ? asString(model, TRUST_MANAGER) : null;
        if (context.mutualAuthentication) {
            ModelNode tsCredRef = new ModelNode();
            tsCredRef.get(CLEAR_TEXT).set(asString(model, AbstractConfiguration.TRUST_STORE_PASSWORD));
            String trustStoreName = asString(model, AbstractConfiguration.TRUST_STORE_NAME);
            ResourceAddress tsAddress = keyStoreTemplate().resolve(statementContext, trustStoreName);
            tasks.add(flowContext -> {
                Operation.Builder builder = new Operation.Builder(tsAddress, ADD).param(PATH, asString(model, AbstractConfiguration.TRUST_STORE_PATH)).param(CREDENTIAL_REFERENCE, tsCredRef).param(TYPE, asString(model, AbstractConfiguration.TRUST_STORE_TYPE));
                if (model.hasDefined(AbstractConfiguration.TRUST_STORE_RELATIVE_TO)) {
                    builder.param(RELATIVE_TO, asString(model, AbstractConfiguration.TRUST_STORE_RELATIVE_TO));
                }
                Operation trustStoreOp = builder.build();
                return dispatcher.execute(trustStoreOp).toCompletable();
            });
            tasks.add(flowContext -> {
                Composite composite = new Composite();
                Operation importCertOp = new Operation.Builder(tsAddress, IMPORT_CERTIFICATE).param(ALIAS, asString(model, AbstractConfiguration.CLIENT_CERTIFICATE_ALIAS)).param(PATH, asString(model, AbstractConfiguration.CLIENT_CERTIFICATE_PATH)).param(CREDENTIAL_REFERENCE, tsCredRef).param(VALIDATE, model.get(AbstractConfiguration.CLIENT_CERTIFICATE_VALIDATE).asBoolean(false)).param(TRUST_CACERTS, model.get(AbstractConfiguration.CLIENT_CERTIFICATE_TRUST).asBoolean(false)).build();
                composite.add(importCertOp);
                Operation storeOp = new Operation.Builder(tsAddress, STORE).build();
                composite.add(storeOp);
                ResourceAddress etmAddress = trustManagerTemplate().resolve(statementContext, trustManagerName);
                Operation trustManagerOp = new Operation.Builder(etmAddress, ADD).param(KEY_STORE, trustStoreName).param(ModelDescriptionConstants.ALGORITHM, KEY_MANAGER_ALGORITHM).build();
                composite.add(trustManagerOp);
                return dispatcher.execute(composite).toCompletable();
            });
        }
        Composite composite = new Composite();
        String keyManager = asString(model, KEY_MANAGER);
        ResourceAddress ekmAddress = keyManagerTemplate().resolve(statementContext, keyManager);
        Operation keyManagerOp = new Operation.Builder(ekmAddress, ADD).param(KEY_STORE, keyStoreName).param(ModelDescriptionConstants.ALGORITHM, KEY_MANAGER_ALGORITHM).param(CREDENTIAL_REFERENCE, credRef).build();
        composite.add(keyManagerOp);
        ModelNode protocols = new ModelNode();
        protocols.add(KEY_MANAGER_TLSV1_2);
        String serverSslContext = asString(model, SERVER_SSL_CONTEXT);
        ResourceAddress sslCtxAddress = sslContextTemplate().resolve(statementContext, serverSslContext);
        Operation.Builder sslCtxBuilder = new Operation.Builder(sslCtxAddress, ADD).param(KEY_MANAGER, keyManager).param(PROTOCOLS, protocols);
        if (context.mutualAuthentication) {
            sslCtxBuilder.param(TRUST_MANAGER, trustManagerName);
            sslCtxBuilder.param(WANT_CLIENT_AUTH, true);
        }
        Operation sslCtxOp = sslCtxBuilder.build();
        composite.add(sslCtxOp);
        if (undertowHttps) {
            ResourceAddress httpsAddress = UNDERTOW_HTTPS_LISTENER_TEMPLATE.resolve(statementContext, undertowServer, httpsListener);
            Operation writeSslCtxOp = new Operation.Builder(httpsAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).param(VALUE, serverSslContext).build();
            composite.add(writeSslCtxOp);
            // undefine the "alternatives" attributes
            composite.add(undefineAttribute(httpsAddress, SECURITY_REALM));
            composite.add(undefineAttribute(httpsAddress, "verify-client"));
            composite.add(undefineAttribute(httpsAddress, "enabled-cipher-suites"));
            composite.add(undefineAttribute(httpsAddress, "enabled-protocols"));
            composite.add(undefineAttribute(httpsAddress, "ssl-session-cache-size"));
            composite.add(undefineAttribute(httpsAddress, "ssl-session-timeout"));
        } else {
            ResourceAddress httpInterfaceAddress = HTTP_INTERFACE_TEMPLATE.resolve(statementContext);
            Operation writeSslCtxOp = new Operation.Builder(httpInterfaceAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).param(VALUE, serverSslContext).build();
            composite.add(writeSslCtxOp);
            if (environment.isStandalone()) {
                Operation writeSecureSocketBinding = new Operation.Builder(httpInterfaceAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SECURE_SOCKET_BINDING).param(VALUE, asString(model, SECURE_SOCKET_BINDING)).build();
                composite.add(writeSecureSocketBinding);
            } else {
                Operation writeSecurePortOp = new Operation.Builder(httpInterfaceAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SECURE_PORT).param(VALUE, asString(model, SECURE_PORT)).build();
                composite.add(writeSecurePortOp);
            }
        }
        tasks.add(flowContext -> dispatcher.execute(composite).toCompletable());
        series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {

            @Override
            public void onSuccess(FlowContext flowContext) {
                if (undertowHttps) {
                    wizard.showSuccess(resources.constants().success(), resources.messages().enableSSLResultsSuccessUndertow(httpsListener, serverSslContext), context1 -> presenter.reloadView(), true);
                } else {
                    // constructs the http management console url
                    String serverName = environment.isStandalone() ? Names.STANDALONE_SERVER : Names.DOMAIN_CONTROLLER;
                    String label = resources.constants().reload() + " " + serverName;
                    SafeHtml description;
                    StringBuilder location = new StringBuilder("https://" + window.location.getHostname() + ":");
                    if (environment.isStandalone()) {
                        location.append(context.securePort);
                        description = resources.messages().enableSSLResultsSuccessStandalone(location.toString());
                    } else {
                        location.append(asString(model, SECURE_PORT));
                        description = resources.messages().enableSSLResultsSuccessDomain(location.toString());
                    }
                    // extracts the url search path, so the url shows the view the user is located
                    String urlSuffix = window.location.getHref();
                    urlSuffix = urlSuffix.substring(urlSuffix.indexOf("//") + 2);
                    urlSuffix = urlSuffix.substring(urlSuffix.indexOf("/"));
                    location.append(urlSuffix);
                    wizard.showSuccess(resources.constants().success(), description, label, // reloads the server/host if user clicks on the success action
                    context1 -> presenter.reloadServer(host, location.toString()), // reload only the view and displays a success message
                    context2 -> {
                        presenter.reloadView();
                        MessageEvent.fire(eventBus, Message.success(resources.messages().enableSSLSuccess()));
                    }, true);
                }
            }

            @Override
            public void onError(FlowContext context, Throwable exception) {
                wizard.showError(resources.constants().failed(), resources.messages().enableSSLResultsError(), exception.getMessage(), false);
            }
        });
    });
    Wizard<EnableSSLContext, EnableSSLState> wizard = wb.build();
    wizard.show();
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) 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) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) AbstractConfiguration(org.jboss.hal.client.shared.sslwizard.AbstractConfiguration) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Constants(org.jboss.hal.resources.Constants) Map(java.util.Map) Message(org.jboss.hal.spi.Message) Names(org.jboss.hal.resources.Names) Operation(org.jboss.hal.dmr.Operation) Wizard(org.jboss.hal.ballroom.wizard.Wizard) EventBus(com.google.web.bindery.event.shared.EventBus) DomGlobal.window(elemental2.dom.DomGlobal.window) Composite(org.jboss.hal.dmr.Composite) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Resources(org.jboss.hal.resources.Resources) Flow.series(org.jboss.hal.flow.Flow.series) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Host(org.jboss.hal.core.runtime.host.Host) Task(org.jboss.hal.flow.Task) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Constants(org.jboss.hal.resources.Constants) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) ModelNode(org.jboss.hal.dmr.ModelNode) Wizard(org.jboss.hal.ballroom.wizard.Wizard)

Example 3 with Constants

use of org.jboss.hal.resources.Constants 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 4 with Constants

use of org.jboss.hal.resources.Constants 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)

Example 5 with Constants

use of org.jboss.hal.resources.Constants 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

EventBus (com.google.web.bindery.event.shared.EventBus)4 List (java.util.List)4 Map (java.util.Map)4 Operation (org.jboss.hal.dmr.Operation)4 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)4 StatementContext (org.jboss.hal.meta.StatementContext)4 Constants (org.jboss.hal.resources.Constants)4 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)3 DomGlobal.window (elemental2.dom.DomGlobal.window)3 HTMLElement (elemental2.dom.HTMLElement)3 ArrayList (java.util.ArrayList)3 Provider (javax.inject.Provider)3 Form (org.jboss.hal.ballroom.form.Form)3 Environment (org.jboss.hal.config.Environment)3 CrudOperations (org.jboss.hal.core.CrudOperations)3 SuccessfulOutcome (org.jboss.hal.core.SuccessfulOutcome)3 ModelNodeForm (org.jboss.hal.core.mbui.form.ModelNodeForm)3 Host (org.jboss.hal.core.runtime.host.Host)3 Composite (org.jboss.hal.dmr.Composite)3 ModelNode (org.jboss.hal.dmr.ModelNode)3