use of org.jboss.hal.flow.FlowContext in project console by hal.
the class AssignmentColumn method columnActionHandler.
private ColumnActionHandler<Assignment> columnActionHandler(Role role, boolean include) {
return column -> {
Principal principal = findPrincipal(getFinder().getContext().getPath());
if (principal != null) {
series(new FlowContext(progress.get()), new CheckRoleMapping(dispatcher, role), new AddRoleMapping(dispatcher, role, status -> status == 404), new AddAssignment(dispatcher, role, principal, include)).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
String type = resources.constants().role();
SafeHtml message = include ? resources.messages().assignmentIncludeSuccess(type, role.getName()) : resources.messages().assignmentExcludeSuccess(type, role.getName());
MessageEvent.fire(eventBus, Message.success(message));
accessControl.reload(() -> {
refresh(RefreshMode.RESTORE_SELECTION);
if (isCurrentUser(principal)) {
eventBus.fireEvent(new UserChangedEvent());
}
});
}
});
}
};
}
use of org.jboss.hal.flow.FlowContext 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();
}
use of org.jboss.hal.flow.FlowContext in project console by hal.
the class StoresPresenter method importCertificate.
void importCertificate(Metadata metadata, String name) {
AddressTemplate template = metadata.getTemplate();
String resource = Names.KEY_STORE + SPACE + name;
metadata = metadata.forOperation(IMPORT_CERTIFICATE);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(template.lastName(), IMPORT_CERTIFICATE), metadata).build();
form.setSaveCallback((form1, changedValues) -> {
ModelNode payload = form.getModel();
String path = payload.get(PATH).asString();
if (!payload.hasDefined(VALIDATE)) {
payload.get(VALIDATE).set(false);
}
ResourceAddress address = template.resolve(statementContext, name);
String alias = payload.get(ALIAS).asString();
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(address, IMPORT_CERTIFICATE).payload(payload).build();
return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().importCertificateError(alias, path, resource, ex.getMessage())))).toCompletable();
});
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(KEY_STORE_TEMPLATE.resolve(statementContext, name), STORE).build();
return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().storeError(resource, ex.getMessage())))).toCompletable();
});
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(address, READ_ALIASES_OPERATION).build();
return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().readAliasesError(resource, ex.getMessage())))).toCompletable();
});
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
MessageEvent.fire(getEventBus(), Message.success(resources.messages().importCertificateSuccess(alias, path, resource)));
}
@Override
public void onError(FlowContext context, Throwable ex) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().removeAliasError(alias, resource, ex.getMessage())));
}
});
});
Dialog dialog = new Dialog.Builder(resources.constants().importCertificate()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().importt(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
dialog.registerAttachable(form);
dialog.show();
form.edit(new ModelNode());
}
use of org.jboss.hal.flow.FlowContext in project console by hal.
the class StoresPresenter method generateKeyPair.
void generateKeyPair(Metadata metadata, String name) {
AddressTemplate template = metadata.getTemplate();
String resource = Names.KEY_STORE + SPACE + name;
metadata = metadata.forOperation(GENERATE_KEY_PAIR);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(template.lastName(), GENERATE_KEY_PAIR), metadata).build();
form.setSaveCallback((form1, changedValues) -> {
ResourceAddress address = template.resolve(statementContext, name);
String alias = form.getModel().get(ALIAS).asString();
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(address, GENERATE_KEY_PAIR).payload(form.getModel()).build();
return dispatcher.execute(operation).toCompletable();
});
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(KEY_STORE_TEMPLATE.resolve(statementContext, name), STORE).build();
return dispatcher.execute(operation).toCompletable();
});
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(address, READ_ALIASES_OPERATION).build();
return dispatcher.execute(operation).toCompletable();
});
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
MessageEvent.fire(getEventBus(), Message.success(resources.messages().generateKeyPairSuccess(alias, resource)));
}
@Override
public void onError(FlowContext context, Throwable ex) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().generateKeyPairError(alias, resource, ex.getMessage())));
}
});
});
Dialog dialog = new Dialog.Builder(resources.constants().generateKeyPair()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().generate(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
dialog.registerAttachable(form);
dialog.show();
form.edit(new ModelNode());
}
use of org.jboss.hal.flow.FlowContext in project console by hal.
the class StoresPresenter method changeAlias.
void changeAlias(Metadata metadata, String name, String alias, Consumer<List<ModelNode>> callback) {
AddressTemplate template = metadata.getTemplate();
String resource = Names.KEY_STORE + SPACE + name;
metadata = metadata.forOperation(CHANGE_ALIAS);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(template.lastName(), CHANGE_ALIAS), metadata).build();
form.setSaveCallback((form1, changedValues) -> {
String newAlias = form.getModel().get("new-alias").asString();
ResourceAddress address = template.resolve(statementContext, name);
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(address, CHANGE_ALIAS).payload(form.getModel()).build();
return dispatcher.execute(operation).toCompletable();
});
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(KEY_STORE_TEMPLATE.resolve(statementContext, name), STORE).build();
return dispatcher.execute(operation).toCompletable();
});
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(address, READ_ALIASES_OPERATION).build();
return dispatcher.execute(operation).doOnSuccess(flowContext::push).toCompletable();
});
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
MessageEvent.fire(getEventBus(), Message.success(resources.messages().changeAliasSuccess(alias, newAlias, resource)));
ModelNode aliases = flowContext.pop();
if (aliases.isDefined()) {
callback.accept(aliases.asList());
} else {
callback.accept(Collections.emptyList());
}
}
@Override
public void onError(FlowContext context, Throwable ex) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().changeAliasError(alias, newAlias, resource, ex.getMessage())));
}
});
});
ModelNode model = new ModelNode();
model.get(ALIAS).set(alias);
form.getFormItem(ALIAS).setEnabled(false);
Dialog dialog = new Dialog.Builder(resources.constants().changeAlias()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().change(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
dialog.registerAttachable(form);
dialog.show();
form.edit(model);
}
Aggregations