use of org.jboss.hal.resources.Resources in project console by hal.
the class CredentialReference method addCredentialReference.
private void addCredentialReference(String baseId, Metadata crMetadata, String credentialReferenceName, String alternativeName, Supplier<ResourceAddress> address, Callback callback) {
ResourceAddress fqAddress = address.get();
if (fqAddress != null) {
String id = Ids.build(baseId, credentialReferenceName, Ids.ADD);
Form<ModelNode> form = new ModelNodeForm.Builder<>(id, crMetadata).addOnly().include(STORE, ALIAS, CLEAR_TEXT, TYPE).unsorted().build();
form.addFormValidation(new CrFormValuesValidation(resources));
new AddResourceDialog(resources.messages().addResourceTitle(Names.CREDENTIAL_REFERENCE), form, (name, model) -> {
if (alternativeName != null) {
Operation undefine = new Operation.Builder(fqAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, alternativeName).build();
Operation write = new Operation.Builder(fqAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, credentialReferenceName).param(VALUE, model).build();
dispatcher.execute(new Composite(undefine, write), (CompositeResult result) -> {
MessageEvent.fire(eventBus, Message.success(resources.messages().addSingleResourceSuccess(Names.CREDENTIAL_REFERENCE)));
callback.execute();
});
} else {
ca.add(credentialReferenceName, Names.CREDENTIAL_REFERENCE, fqAddress, model, callback);
}
}).show();
} else {
MessageEvent.fire(eventBus, Message.error(resources.messages().credentialReferenceAddressError()));
}
}
use of org.jboss.hal.resources.Resources 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.resources.Resources 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.resources.Resources 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.resources.Resources 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();
}
Aggregations