Search in sources :

Example 1 with Task

use of org.jboss.hal.flow.Task in project console by hal.

the class MetadataProcessor method processInternal.

private void processInternal(Set<AddressTemplate> templates, boolean recursive, Progress progress, AsyncCallback<Void> callback) {
    // we can skip the tasks if the metadata is already in the registries
    LookupRegistryTask lookupRegistries = new LookupRegistryTask(resourceDescriptionRegistry, securityContextRegistry);
    if (lookupRegistries.allPresent(templates, recursive)) {
        logger.debug("All metadata have been already processed -> callback.onSuccess(null)");
        callback.onSuccess(null);
    } else {
        boolean ie = Browser.isIE();
        List<Task<LookupContext>> tasks = new ArrayList<>();
        tasks.add(lookupRegistries);
        if (!ie) {
            tasks.add(new LookupDatabaseTask(resourceDescriptionDatabase, securityContextDatabase));
        }
        tasks.add(new RrdTask(environment, dispatcher, statementContext, settings, BATCH_SIZE, RRD_DEPTH));
        tasks.add(new UpdateRegistryTask(resourceDescriptionRegistry, securityContextRegistry));
        if (!ie) {
            tasks.add(new UpdateDatabaseTask(workerChannel));
        }
        LookupContext context = new LookupContext(progress, templates, recursive);
        Stopwatch stopwatch = Stopwatch.createStarted();
        series(context, tasks).subscribe(new Outcome<LookupContext>() {

            @Override
            public void onError(LookupContext context, Throwable error) {
                stopwatch.stop();
                logger.debug("Failed to process metadata: {}", error.getMessage());
                callback.onFailure(error);
            }

            @Override
            public void onSuccess(LookupContext context) {
                stopwatch.stop();
                logger.info("Successfully processed metadata in {} ms", stopwatch.elapsed(MILLISECONDS));
                callback.onSuccess(null);
            }
        });
    }
}
Also used : Task(org.jboss.hal.flow.Task) ArrayList(java.util.ArrayList) Stopwatch(com.google.common.base.Stopwatch)

Example 2 with Task

use of org.jboss.hal.flow.Task in project console by hal.

the class JmsQueuePresenter method reload.

@Override
protected void reload() {
    if (showAll()) {
        readAll();
    } else {
        ResourceAddress address = queueAddress();
        Task<FlowContext> count = context -> {
            Operation operation = new Operation.Builder(address, COUNT_MESSAGES).build();
            return dispatcher.execute(operation).doOnSuccess(result -> context.set(MESSAGES_COUNT, result.asLong())).toCompletable();
        };
        Task<FlowContext> list = context -> {
            long messages = context.get(MESSAGES_COUNT);
            if (messages > MESSAGES_THRESHOLD) {
                context.set(MESSAGES, emptyList());
                return Completable.complete();
            } else {
                Operation operation = new Operation.Builder(address, LIST_MESSAGES).build();
                return dispatcher.execute(operation).doOnSuccess(result -> context.set(MESSAGES, result.asList().stream().map(JmsMessage::new).collect(toList()))).toCompletable();
            }
        };
        series(new FlowContext(progress.get()), count, list).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {

            @Override
            public void onSuccess(FlowContext context) {
                long count = context.get(MESSAGES_COUNT);
                List<JmsMessage> messages = context.get(MESSAGES);
                if (count > MESSAGES_THRESHOLD) {
                    logger.debug("More than {} messages in queue {}. Skip :list-messages operation.", MESSAGES_THRESHOLD, queueAddress());
                    getView().showMany(count);
                } else {
                    getView().showAll(messages);
                }
            }
        });
    }
}
Also used : Dialog(org.jboss.hal.ballroom.dialog.Dialog) Provider(javax.inject.Provider) StatementContext(org.jboss.hal.meta.StatementContext) LoggerFactory(org.slf4j.LoggerFactory) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Map(java.util.Map) 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) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) Collections.emptyList(java.util.Collections.emptyList) FinderPath(org.jboss.hal.core.finder.FinderPath) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) HalView(org.jboss.hal.core.mvp.HalView) 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) ModelNode(org.jboss.hal.dmr.ModelNode) Completable(rx.Completable) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) HashMap(java.util.HashMap) FlowContext(org.jboss.hal.flow.FlowContext) Inject(javax.inject.Inject) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplates(org.jboss.hal.client.runtime.subsystem.messaging.AddressTemplates) ApplicationFinderPresenter(org.jboss.hal.core.mvp.ApplicationFinderPresenter) Requires(org.jboss.hal.spi.Requires) Logger(org.slf4j.Logger) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) ModelNodeHelper.failSafeBoolean(org.jboss.hal.dmr.ModelNodeHelper.failSafeBoolean) 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) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) FormItem(org.jboss.hal.ballroom.form.FormItem) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) Type(org.jboss.hal.client.runtime.subsystem.messaging.Destination.Type) Elements(org.jboss.gwt.elemento.core.Elements) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Form(org.jboss.hal.ballroom.form.Form) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext)

Example 3 with Task

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

use of org.jboss.hal.flow.Task 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 5 with Task

use of org.jboss.hal.flow.Task 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)

Aggregations

Task (org.jboss.hal.flow.Task)28 FlowContext (org.jboss.hal.flow.FlowContext)27 ArrayList (java.util.ArrayList)23 List (java.util.List)23 Provider (javax.inject.Provider)22 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)22 Flow.series (org.jboss.hal.flow.Flow.series)22 Progress (org.jboss.hal.flow.Progress)22 EventBus (com.google.web.bindery.event.shared.EventBus)21 ModelNode (org.jboss.hal.dmr.ModelNode)21 Operation (org.jboss.hal.dmr.Operation)21 StatementContext (org.jboss.hal.meta.StatementContext)21 Resources (org.jboss.hal.resources.Resources)21 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)20 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)19 Ids (org.jboss.hal.resources.Ids)19 Message (org.jboss.hal.spi.Message)19 MessageEvent (org.jboss.hal.spi.MessageEvent)19 AddressTemplate (org.jboss.hal.meta.AddressTemplate)18 Footer (org.jboss.hal.spi.Footer)18