use of org.jboss.hal.meta.StatementContext in project console by hal.
the class RoleColumn method editScopedRole.
private void editScopedRole(Role role, String type, AddressTemplate template, AddressTemplate typeaheadTemplate, String formId, String scopeAttribute) {
Metadata metadata = metadataRegistry.lookup(template);
Form<ModelNode> form = new ModelNodeForm.Builder<>(formId, metadata).include(BASE_ROLE, scopeAttribute).customFormItem(BASE_ROLE, attributeDescription -> {
SingleSelectBoxItem item = new SingleSelectBoxItem(BASE_ROLE, new LabelBuilder().label(BASE_ROLE), standardRoleNames, false);
item.setRequired(true);
return item;
}).unboundFormItem(new SwitchItem(INCLUDE_ALL, new LabelBuilder().label(INCLUDE_ALL)), 2, resources.messages().includeAllHelpText()).build();
form.getFormItem(scopeAttribute).setRequired(true);
form.getFormItem(scopeAttribute).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, typeaheadTemplate));
form.getFormItem(INCLUDE_ALL).setValue(role.isIncludeAll());
form.attach();
ModelNode modelNode = new ModelNode();
modelNode.get(BASE_ROLE).set(role.getBaseRole().getName());
role.getScope().forEach(scope -> modelNode.get(scopeAttribute).add(scope));
new ModifyResourceDialog(resources.messages().modifyResourceTitle(type), form, (frm, changedValues) -> {
boolean includeAll = frm.<Boolean>getFormItem(INCLUDE_ALL).getValue();
boolean includeAllChanged = includeAll != role.isIncludeAll();
List<Task<FlowContext>> tasks = new ArrayList<>();
if (!changedValues.isEmpty()) {
tasks.add(new ModifyScopedRole(dispatcher, role, changedValues, metadata));
}
if (includeAllChanged) {
tasks.add(new ModifyIncludeAll(dispatcher, role, includeAll));
}
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
MessageEvent.fire(eventBus, Message.success(resources.messages().modifyResourceSuccess(type, role.getName())));
accessControl.reload(() -> {
refresh(role.getId());
eventBus.fireEvent(new RolesChangedEvent());
});
}
});
}).show(modelNode);
}
use of org.jboss.hal.meta.StatementContext in project console by hal.
the class AccessControlSsoPresenter method onReset.
@Override
protected void onReset() {
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(flowContext -> {
ResourceAddress address = KEYCLOAK_SECURE_SERVER_TEMPLATE.resolve(statementContext);
Operation op = new Operation.Builder(address, READ_RESOURCE_OPERATION).build();
flowContext.set(ADDRESS, address.toString());
return dispatcher.execute(op).doOnSuccess(response -> {
flowContext.set(REALM, response.get(REALM).asString());
}).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().failedReadKeycloak(address.toString(), ex.getMessage())))).toCompletable();
});
tasks.add(flowContext -> {
ResourceAddress address = KEYCLOAK_REALM_TEMPLATE.resolve(statementContext, flowContext.<String>get(REALM));
Operation op = new Operation.Builder(address, READ_RESOURCE_OPERATION).build();
flowContext.set(ADDRESS, address.toString());
return dispatcher.execute(op).doOnSuccess(response -> {
flowContext.set(KEYCLOAK_SERVER_URL, response.get(AUTH_SERVER_URL).asString());
flowContext.set(REALM_PUBLIC_KEY, response.get(REALM_PUBLIC_KEY).asString());
}).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().failedReadKeycloak(address.toString(), ex.getMessage())))).toCompletable();
});
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
ModelNode payload = new ModelNode();
payload.get(REALM).set(flowContext.<String>get(REALM));
payload.get(REALM_PUBLIC_KEY).set(flowContext.<String>get(REALM_PUBLIC_KEY));
payload.get(KEYCLOAK_SERVER_URL).set(flowContext.<String>get(KEYCLOAK_SERVER_URL));
getView().update(payload);
}
@Override
public void onError(FlowContext context, Throwable throwable) {
String address = context.get(ADDRESS);
MessageEvent.fire(getEventBus(), Message.error(resources.messages().failedReadKeycloak(address, throwable.getMessage())));
}
});
}
use of org.jboss.hal.meta.StatementContext in project console by hal.
the class StandaloneServerPresenter method disableSslForManagementInterface.
@Override
@SuppressWarnings("DuplicatedCode")
public void disableSslForManagementInterface() {
Constants constants = resources.constants();
String serverName = environment.isStandalone() ? Names.STANDALONE_SERVER : Names.DOMAIN_CONTROLLER;
String label = constants.reload() + " " + serverName;
SwitchItem reload = new SwitchItem(RELOAD, label);
reload.setExpressionAllowed(false);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(RELOAD, FORM), Metadata.empty()).unboundFormItem(reload).build();
form.attach();
HTMLElement formElement = form.element();
ModelNode model = new ModelNode();
model.setEmptyObject();
form.edit(model);
ResourceAddress httpAddress = HTTP_INTERFACE_TEMPLATE.resolve(statementContext);
DialogFactory.buildConfirmation(constants.disableSSL(), resources.messages().disableSSLManagementQuestion(serverName), formElement, Dialog.Size.MEDIUM, () -> {
List<Task<FlowContext>> tasks = new ArrayList<>();
// load the http-interface resource to get the port, there are differente attributes for
// standalone and domain mode.
Task<FlowContext> loadHttpInterface = flowContext -> {
Operation readHttpInterface = new Operation.Builder(httpAddress, READ_RESOURCE_OPERATION).build();
return dispatcher.execute(readHttpInterface).doOnSuccess(value -> {
if (value.hasDefined(SOCKET_BINDING)) {
// standalone mode uses a socket-binding for port
// store the socket-binding name in the flow context and on a later call
// read the socket-binding-group=<s-b-g>/socket-binding=<http-binding> to
// retrieve the port number
flowContext.set(SOCKET_BINDING, value.get(SOCKET_BINDING).asString());
}
}).toCompletable();
};
tasks.add(loadHttpInterface);
// if standalone mode, read the socket-binding-group=<s-b-g>/socket-binding=<http-binding>
// to retrieve the port number
Task<FlowContext> readHttpPortTask = flowContext -> {
Operation op = new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, SOCKET_BINDING_GROUP).build();
return dispatcher.execute(op).doOnSuccess(result -> {
String sbg = result.asList().get(0).asString();
String httpBinding = flowContext.get(SOCKET_BINDING);
ResourceAddress address = SOCKET_BINDING_GROUP_TEMPLATE.resolve(statementContext, sbg, httpBinding);
Operation readPort = new Operation.Builder(address, READ_ATTRIBUTE_OPERATION).param(NAME, PORT).param(RESOLVE_EXPRESSIONS, true).build();
dispatcher.execute(readPort, portResult -> flowContext.set(PORT, portResult.asString()));
}).toCompletable();
};
tasks.add(readHttpPortTask);
// as part of the disable ssl task, undefine the secure-socket-binding
// the attribute only exists in standalone mode
Task<FlowContext> undefSslTask = flowContext -> {
Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SECURE_SOCKET_BINDING).build();
return dispatcher.execute(op).toCompletable();
};
tasks.add(undefSslTask);
// as part of the disable ssl task, undefine the ssl-context
Task<FlowContext> undefineSslContextTask = flowContext -> {
Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).build();
return dispatcher.execute(op).toCompletable();
};
tasks.add(undefineSslContextTask);
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
if (reload.getValue() != null && reload.getValue()) {
String port = flowContext.get(PORT).toString();
// extracts the url search path, so the reload shows the same view the use is on
String urlSuffix = window.location.getHref();
urlSuffix = urlSuffix.substring(urlSuffix.indexOf("//") + 2);
urlSuffix = urlSuffix.substring(urlSuffix.indexOf("/"));
// the location to redirect the browser to the unsecure URL
// TODO Replace hardcoded scheme
String location = "http://" + window.location.getHostname() + ":" + port + urlSuffix;
reloadServer(null, location);
} else {
reload();
MessageEvent.fire(getEventBus(), Message.success(resources.messages().disableSSLManagementSuccess()));
}
}
@Override
public void onError(FlowContext context, Throwable throwable) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().disableSSLManagementError(throwable.getMessage())));
}
});
}).show();
}
use of org.jboss.hal.meta.StatementContext in project console by hal.
the class StoresPresenter method importCertificate.
void importCertificate(Metadata metadata, String name) {
AddressTemplate template = metadata.getTemplate();
String resource = Names.KEY_STORE + SPACE + name;
metadata = metadata.forOperation(IMPORT_CERTIFICATE);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(template.lastName(), IMPORT_CERTIFICATE), metadata).build();
form.setSaveCallback((form1, changedValues) -> {
ModelNode payload = form.getModel();
String path = payload.get(PATH).asString();
if (!payload.hasDefined(VALIDATE)) {
payload.get(VALIDATE).set(false);
}
ResourceAddress address = template.resolve(statementContext, name);
String alias = payload.get(ALIAS).asString();
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(address, IMPORT_CERTIFICATE).payload(payload).build();
return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().importCertificateError(alias, path, resource, ex.getMessage())))).toCompletable();
});
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(KEY_STORE_TEMPLATE.resolve(statementContext, name), STORE).build();
return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().storeError(resource, ex.getMessage())))).toCompletable();
});
tasks.add(flowContext -> {
Operation operation = new Operation.Builder(address, READ_ALIASES_OPERATION).build();
return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().readAliasesError(resource, ex.getMessage())))).toCompletable();
});
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
MessageEvent.fire(getEventBus(), Message.success(resources.messages().importCertificateSuccess(alias, path, resource)));
}
@Override
public void onError(FlowContext context, Throwable ex) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().removeAliasError(alias, resource, ex.getMessage())));
}
});
});
Dialog dialog = new Dialog.Builder(resources.constants().importCertificate()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().importt(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
dialog.registerAttachable(form);
dialog.show();
form.edit(new ModelNode());
}
use of org.jboss.hal.meta.StatementContext in project console by hal.
the class PasswordWizard method show.
public void show() {
Constants constants = resources.constants();
Wizard.Builder<PasswordContext, PasswordState> wb = new Wizard.Builder<>(constants.setIdentityPasswordTitle(), new PasswordContext());
wb.addStep(PasswordState.CHOOSE_PASSWORD_TYPE, new ChoosePasswordTypeStep(resources)).addStep(PasswordState.CONFIGURATION, new ConfigurePasswordStep(resources, metadata)).addStep(PasswordState.REVIEW, new ReviewPasswordStep(resources, metadata)).onBack((context, currentState) -> {
PasswordState previous = null;
switch(currentState) {
case CHOOSE_PASSWORD_TYPE:
break;
case CONFIGURATION:
previous = PasswordState.CHOOSE_PASSWORD_TYPE;
break;
case REVIEW:
previous = PasswordState.CONFIGURATION;
break;
default:
break;
}
return previous;
}).onNext((context, currentState) -> {
PasswordState next = null;
switch(currentState) {
case CHOOSE_PASSWORD_TYPE:
next = PasswordState.CONFIGURATION;
break;
case CONFIGURATION:
next = PasswordState.REVIEW;
break;
case REVIEW:
break;
default:
break;
}
return next;
}).onFinish((wizard, context) -> {
ResourceAddress address = metadata.getTemplate().resolve(statementContext, selectedRealm);
Operation operation = new Operation.Builder(address, SET_PASSWORD).param(IDENTITY, selectedIdentity).param(context.type.name, context.model).build();
LabelBuilder labelBuilder = new LabelBuilder();
String type = labelBuilder.label(metadata.getTemplate().lastName());
String resourceName = type + "" + selectedRealm;
dispatcher.execute(operation, result -> MessageEvent.fire(eventBus, Message.success(resources.messages().setIdentityPasswordSuccess(selectedIdentity, resourceName))), (operation1, failure) -> MessageEvent.fire(eventBus, Message.error(resources.messages().setIdentityPasswordError(selectedIdentity, resourceName, failure))), (operation1, exception) -> MessageEvent.fire(eventBus, Message.error(resources.messages().setIdentityPasswordError(selectedIdentity, resourceName, exception.getMessage()))));
});
Wizard<PasswordContext, PasswordState> wizard = wb.build();
wizard.show();
}
Aggregations