use of org.jboss.hal.spi.Callback in project console by hal.
the class ComplexAttributeOperations method remove.
/**
* Undefines the complex attribute. After the attribute has been undefined a standard success message is fired and the
* specified callback is executed.
*
* @param complexAttribute the name of the complex attribute
* @param type the human readable name of the complex attribute
* @param address the fq address for the operation
* @param callback the callback executed after the complex attribute has been undefined
*/
@JsIgnore
public void remove(String complexAttribute, String type, ResourceAddress address, Callback callback) {
Operation operation = new Operation.Builder(address, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, complexAttribute).build();
SafeHtml question = resources.messages().removeSingletonConfirmationQuestion();
DialogFactory.showConfirmation(resources.messages().removeConfirmationTitle(type), question, () -> dispatcher.execute(operation, result -> {
MessageEvent.fire(eventBus, Message.success(resources.messages().removeSingletonResourceSuccess(type)));
callback.execute();
}));
}
use of org.jboss.hal.spi.Callback in project console by hal.
the class AccessControl method reload.
void reload(Callback callback) {
reset();
List<Operation> operations = new ArrayList<>();
operations.add(new Operation.Builder(AddressTemplates.root(), READ_RESOURCE_OPERATION).param(INCLUDE_RUNTIME, true).param(ATTRIBUTES_ONLY, true).build());
if (!environment.isStandalone()) {
operations.add(new Operation.Builder(AddressTemplates.root(), READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, HOST_SCOPED_ROLE).param(RECURSIVE, true).build());
operations.add(new Operation.Builder(AddressTemplates.root(), READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, SERVER_GROUP_SCOPED_ROLE).param(RECURSIVE, true).build());
}
operations.add(new Operation.Builder(AddressTemplates.root(), READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, ROLE_MAPPING).param(RECURSIVE, true).build());
dispatcher.execute(new Composite(operations), (CompositeResult result) -> {
int step = 0;
ModelNode attributes = result.step(step++).get(RESULT);
AccessControlProvider accessControlProvider = ModelNodeHelper.asEnumValue(attributes, PROVIDER, AccessControlProvider::valueOf, SIMPLE);
environment.setAccessControlProvider(accessControlProvider);
attributes.get(STANDARD_ROLE_NAMES).asList().stream().map(node -> new Role(node.asString())).forEach(roles::add);
if (!environment.isStandalone()) {
result.step(step++).get(RESULT).asPropertyList().stream().map(property -> scopedRole(property, Role.Type.HOST, HOSTS)).forEach(roles::add);
result.step(step++).get(RESULT).asPropertyList().stream().map(property -> scopedRole(property, Role.Type.SERVER_GROUP, SERVER_GROUPS)).forEach(roles::add);
}
// noinspection UnusedAssignment
result.step(step++).get(RESULT).asPropertyList().forEach(p1 -> {
Role role = roles.get(Ids.role(p1.getName()));
if (role != null) {
ModelNode assignmentNode = p1.getValue();
if (assignmentNode.hasDefined(INCLUDE_ALL)) {
role.setIncludeAll(assignmentNode.get(INCLUDE_ALL).asBoolean());
}
if (assignmentNode.hasDefined(INCLUDE)) {
assignmentNode.get(INCLUDE).asPropertyList().forEach(p2 -> addAssignment(p2, role, true));
}
if (assignmentNode.hasDefined(EXCLUDE)) {
assignmentNode.get(EXCLUDE).asPropertyList().forEach(p2 -> addAssignment(p2, role, false));
}
} else {
logger.error("Cannot add assignment for role {}: No matching role found!", p1.getName());
}
});
// sync with current user
String currentUserId = Ids.principal(Principal.Type.USER.name().toLowerCase(), currentUser.getName());
Principal currentPrincipal = principals.get(currentUserId);
if (currentPrincipal != null) {
Set<Role> currentRoles = assignments.byPrincipal(currentPrincipal).map(Assignment::getRole).collect(toSet());
currentUser.refreshRoles(currentRoles);
}
callback.execute();
});
}
use of org.jboss.hal.spi.Callback in project console by hal.
the class EndpointManager method authKeycloak.
private void authKeycloak(String kcAdapterUrl, String keycloakServerJsUrl, Callback callback) {
// load keycloak.js from keycloak server url
HTMLScriptElement script = (HTMLScriptElement) document.createElement("script");
script.src = keycloakServerJsUrl;
script.onload = onLoadEvent -> {
Keycloak kc = new Keycloak(kcAdapterUrl);
Keycloak.Api initOptions = new Keycloak.Api();
kc.init(initOptions).success(authenticated -> {
setInterval(o -> kc.updateToken(32), 30000);
kc.loadUserProfile().success(profile -> {
kc.userProfile = profile;
});
set(KEYCLOAK, kc);
callback.execute();
}).error(() -> logger.error("Error, could not initialize keycloak authentication."));
keycloakHolder.setKeycloak(kc);
return null;
};
document.head.appendChild(script);
}
use of org.jboss.hal.spi.Callback in project console by hal.
the class ServerActions method editUrl.
public void editUrl(Server server, Callback callback) {
Alert alert = new Alert(Icons.ERROR, resources.messages().serverUrlError());
HTMLElement info = p().element();
TextBoxItem urlItem = new TextBoxItem(URL, Names.URL);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.SERVER_URL_FORM, Metadata.empty()).unboundFormItem(urlItem).addOnly().onSave((f, changedValues) -> {
String url = urlItem.getValue();
if (Strings.isNullOrEmpty(url)) {
serverUrlStorage.remove(server.getHost(), server.getName());
} else {
serverUrlStorage.save(server.getHost(), server.getName(), url);
}
callback.execute();
}).build();
Dialog dialog = new Dialog.Builder(resources.constants().editURL()).add(alert.element()).add(info).add(form.element()).primary(form::save).cancel().closeIcon(true).closeOnEsc(true).build();
dialog.registerAttachable(form);
Elements.setVisible(alert.element(), false);
Elements.setVisible(info, false);
readUrl(server, new AsyncCallback<ServerUrl>() {
@Override
public void onFailure(Throwable caught) {
Elements.setVisible(alert.element(), true);
show(null);
}
@Override
public void onSuccess(ServerUrl serverUrl) {
if (serverUrl.isCustom()) {
info.innerHTML = resources.messages().serverUrlCustom().asString();
} else {
info.innerHTML = resources.messages().serverUrlManagementModel().asString();
}
Elements.setVisible(info, true);
show(serverUrl);
}
private void show(ServerUrl serverUrl) {
dialog.show();
form.edit(new ModelNode());
if (serverUrl != null) {
urlItem.setValue(serverUrl.getUrl());
}
}
});
}
use of org.jboss.hal.spi.Callback in project console by hal.
the class CrudOperations method readChildren.
/**
* Read multiple different child resources using a composite operation. The steps in the composite result map to the
* position of the resource in the {@code resources} collection.
*
* @param address the fq address for the {@code read-children-resource} operation
* @param resources the child resources (not human readable, but the actual child resource name!)
* @param depth the depth used for the {@code recursive-depth} parameter
* @param callback the callback which gets the composite result
*/
@JsIgnore
public void readChildren(ResourceAddress address, Iterable<String> resources, int depth, ReadCompositeCallback callback) {
List<Operation> operations = stream(resources.spliterator(), false).map(resource -> new Operation.Builder(address, READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, resource).param(RECURSIVE_DEPTH, depth).build()).collect(toList());
dispatcher.execute(new Composite(operations), callback::execute);
}
Aggregations