use of org.jboss.hal.config.AccessControlProvider.SIMPLE 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.config.AccessControlProvider.SIMPLE in project console by hal.
the class ReadAuthentication method call.
@Override
public Completable call(FlowContext context) {
logger.debug("Read authentication");
ResourceAddress address = CORE_SERVICE_TEMPLATE.resolve(statementContext);
Operation opAuthorization = new Operation.Builder(address, READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, ACCESS).param(INCLUDE_RUNTIME, true).param(RECURSIVE_DEPTH, 1).build();
Operation opWhoami = new Operation.Builder(ResourceAddress.root(), WHOAMI).param(VERBOSE, true).build();
return dispatcher.execute(new Composite(opAuthorization, opWhoami)).doOnSuccess((CompositeResult compositeResult) -> {
ModelNode result = compositeResult.step(0).get(RESULT);
if (result.hasDefined(AUTHORIZATION)) {
result = result.get(AUTHORIZATION);
// provider
AccessControlProvider accessControlProvider = asEnumValue(result, PROVIDER, AccessControlProvider::valueOf, SIMPLE);
environment.setAccessControlProvider(accessControlProvider);
// standard roles
if (result.hasDefined(STANDARD_ROLE_NAMES)) {
result.get(STANDARD_ROLE_NAMES).asList().stream().map(node -> new Role(node.asString())).forEach(role -> environment.getRoles().add(role));
}
// scoped roles
if (!environment.isStandalone()) {
if (result.hasDefined(HOST_SCOPED_ROLE)) {
result.get(HOST_SCOPED_ROLE).asPropertyList().stream().map(property -> scopedRole(property, Role.Type.HOST, HOSTS)).forEach(role -> environment.getRoles().add(role));
}
if (result.hasDefined(SERVER_GROUP_SCOPED_ROLE)) {
result.get(SERVER_GROUP_SCOPED_ROLE).asPropertyList().stream().map(property -> scopedRole(property, Role.Type.SERVER_GROUP, SERVER_GROUPS)).forEach(role -> environment.getRoles().add(role));
}
}
} else {
logger.warn("Unable to read {} (insufficient rights?). Use :whoami values as fallback.", CORE_SERVICE_TEMPLATE.append("access=authorization"));
ModelNode resultWhoami = compositeResult.step(1).get(RESULT);
environment.setAccessControlProvider(RBAC);
environment.getRoles().clear();
if (resultWhoami.hasDefined(ROLES)) {
resultWhoami.get(ROLES).asList().stream().map(node -> new Role(node.asString())).forEach(role -> environment.getRoles().add(role));
} else if (resultWhoami.hasDefined(MAPPED_ROLES)) {
resultWhoami.get(MAPPED_ROLES).asList().stream().map(node -> new Role(node.asString())).forEach(role -> environment.getRoles().add(role));
}
}
}).onErrorResumeNext(throwable -> {
if (throwable instanceof DispatchFailure) {
logger.error("Unable to read {}. Use :whoami values as fallback.", CORE_SERVICE_TEMPLATE);
return Single.just(new CompositeResult(new ModelNode()));
} else {
return Single.error(throwable);
}
}).toCompletable();
}
Aggregations