use of org.jboss.hal.flow.FlowContext in project console by hal.
the class SecurityDomainPresenter method addModule.
void addModule(Module module) {
// first check for (and add if necessary) the intermediate singleton
// then add the final resource
AddressTemplate singletonTemplate = SELECTED_SECURITY_DOMAIN_TEMPLATE.append(module.singleton);
series(new FlowContext(progress.get()), new ResourceCheck(dispatcher, singletonTemplate.resolve(statementContext)), context -> {
int status = context.pop();
if (status == 200) {
return Completable.complete();
} else {
Operation operation = new Operation.Builder(singletonTemplate.resolve(statementContext), ADD).build();
return dispatcher.execute(operation).toCompletable();
}
}).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext context) {
AddressTemplate metadataTemplate = SECURITY_DOMAIN_TEMPLATE.append(module.singleton).append(module.resource + EQ_WILDCARD);
AddressTemplate selectionTemplate = SELECTED_SECURITY_DOMAIN_TEMPLATE.append(module.singleton).append(module.resource + EQ_WILDCARD);
Metadata metadata = metadataRegistry.lookup(metadataTemplate);
AddResourceDialog dialog = new AddResourceDialog(module.id, resources.messages().addResourceTitle(module.type), metadata, (name, modelNode) -> {
ResourceAddress address = selectionTemplate.resolve(statementContext, name);
crud.add(module.type, name, address, modelNode, (n, a) -> reload());
});
dialog.show();
}
});
}
use of org.jboss.hal.flow.FlowContext in project console by hal.
the class RoleColumn method editStandardRole.
// ------------------------------------------------------ modify roles
private void editStandardRole(Role role) {
Metadata metadata = metadataRegistry.lookup(ROLE_MAPPING_TEMPLATE);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.ROLE_MAPPING_FORM, metadata).unboundFormItem(new NameItem(), 0).include(INCLUDE_ALL).build();
form.getFormItem(NAME).setEnabled(false);
form.getFormItem(NAME).setRequired(false);
ModelNode modelNode = new ModelNode();
modelNode.get(INCLUDE_ALL).set(role.isIncludeAll());
new ModifyResourceDialog(resources.messages().modifyResourceTitle(resources.constants().role()), form, (frm, changedValues) -> series(new FlowContext(progress.get()), new CheckRoleMapping(dispatcher, role), new AddRoleMapping(dispatcher, role, status -> status == 404), new ModifyIncludeAll(dispatcher, role, frm.getModel().get(INCLUDE_ALL).asBoolean())).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
MessageEvent.fire(eventBus, Message.success(resources.messages().modifyResourceSuccess(resources.constants().role(), role.getName())));
accessControl.reload(() -> {
refresh(role.getId());
eventBus.fireEvent(new RolesChangedEvent());
});
}
})).show(modelNode);
form.getFormItem(NAME).setValue(role.getName());
}
use of org.jboss.hal.flow.FlowContext in project console by hal.
the class RoleColumn method removeScopedRole.
// ------------------------------------------------------ remove roles
private void removeScopedRole(Role role, String type) {
List<Task<FlowContext>> tasks = new ArrayList<>();
List<Assignment> assignments = accessControl.assignments().byRole(role).collect(toList());
if (!assignments.isEmpty()) {
tasks.add(new RemoveAssignments(dispatcher, assignments));
}
tasks.add(new CheckRoleMapping(dispatcher, role));
tasks.add(new RemoveRoleMapping(dispatcher, role, status -> status == 200));
tasks.add(new RemoveScopedRole(dispatcher, role));
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().removeResourceSuccess(type, role.getName())));
accessControl.reload(() -> {
refresh(RefreshMode.CLEAR_SELECTION);
eventBus.fireEvent(new RolesChangedEvent());
});
}
});
}
use of org.jboss.hal.flow.FlowContext in project console by hal.
the class RoleColumn method addScopedRole.
// ------------------------------------------------------ add roles
@SuppressWarnings("ConstantConditions")
private void addScopedRole(Role.Type type, String typeName, AddressTemplate template, AddressTemplate typeaheadTemplate, String formId, String scopeAttribute) {
Metadata metadata = metadataRegistry.lookup(template);
Form<ModelNode> form = new ModelNodeForm.Builder<>(formId, metadata).addOnly().unboundFormItem(new NameItem(), 0).unboundFormItem(new SwitchItem(INCLUDE_ALL, new LabelBuilder().label(INCLUDE_ALL)), 3, resources.messages().includeAllHelpText()).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;
}).build();
form.getFormItem(scopeAttribute).setRequired(true);
form.getFormItem(scopeAttribute).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, typeaheadTemplate));
form.attach();
AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(typeName), form, (name, model) -> {
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(new AddScopedRole(dispatcher, type, name, model));
Boolean includeAll = form.<Boolean>getFormItem(INCLUDE_ALL).getValue();
Role transientRole = new Role(name, null, type, null);
// We only need the role name in the functions,
// so it's ok to setup a transient role w/o the other attributes.
tasks.add(new CheckRoleMapping(dispatcher, transientRole));
tasks.add(new AddRoleMapping(dispatcher, transientRole, status -> status == 404));
if (includeAll != null && includeAll) {
tasks.add(new ModifyIncludeAll(dispatcher, transientRole, 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().addResourceSuccess(typeName, name)));
accessControl.reload(() -> {
refresh(Ids.role(name));
eventBus.fireEvent(new RolesChangedEvent());
});
}
});
});
dialog.getForm().<String>getFormItem(NAME).addValidationHandler(createUniqueValidation());
dialog.show();
}
use of org.jboss.hal.flow.FlowContext in project console by hal.
the class PrincipalColumn method collectTasks.
private void collectTasks(List<Task<FlowContext>> tasks, Principal.Type type, String name, boolean include, ModelNode modelNode, String attribute) {
String realm = modelNode.hasDefined(REALM) ? modelNode.get(REALM).asString() : null;
String resourceName = Principal.buildResourceName(type, name, realm);
Principal principal = new Principal(type, resourceName, name, realm);
if (modelNode.hasDefined(attribute)) {
modelNode.get(attribute).asList().stream().map(nameNode -> accessControl.roles().get(Ids.role(nameNode.asString()))).forEach(role -> {
if (role != null) {
tasks.add(new CheckRoleMapping(dispatcher, role));
tasks.add(new AddRoleMapping(dispatcher, role, status -> status == 404));
tasks.add(new AddAssignment(dispatcher, role, principal, include));
}
});
}
}
Aggregations