use of com.yahoo.vespa.hosted.controller.api.integration.organization.User in project vespa by vespa-engine.
the class ApplicationApiHandler method authenticatedUser.
private HttpResponse authenticatedUser(HttpRequest request) {
String userIdString = request.getProperty("userOverride");
if (userIdString == null)
userIdString = getUserId(request).map(UserId::id).orElseThrow(() -> new ForbiddenException("You must be authenticated or specify userOverride"));
UserId userId = new UserId(userIdString);
List<Tenant> tenants = controller.tenants().asList(userId);
Slime slime = new Slime();
Cursor response = slime.setObject();
response.setString("user", userId.id());
Cursor tenantsArray = response.setArray("tenants");
for (Tenant tenant : tenants) tenantInTenantsListToSlime(tenant, request.getUri(), tenantsArray.addObject());
response.setBool("tenantExists", tenants.stream().map(Tenant::getId).anyMatch(id -> id.isTenantFor(userId)));
return new SlimeJsonResponse(slime);
}
use of com.yahoo.vespa.hosted.controller.api.integration.organization.User in project vespa by vespa-engine.
the class ApplicationApiHandler method toSlime.
private void toSlime(Cursor object, Tenant tenant, HttpRequest request, boolean listApplications) {
object.setString("tenant", tenant.getId().id());
object.setString("type", tenant.tenantType().name());
tenant.getAthensDomain().ifPresent(a -> object.setString("athensDomain", a.getName()));
tenant.getProperty().ifPresent(p -> object.setString("property", p.id()));
tenant.getPropertyId().ifPresent(p -> object.setString("propertyId", p.toString()));
Cursor applicationArray = object.setArray("applications");
if (listApplications) {
// This cludge is needed because we call this after deleting the tenant. As this call makes another tenant lookup it will fail. TODO is to support lookup on tenant
for (Application application : controller.applications().asList(TenantName.from(tenant.getId().id()))) {
if (application.id().instance().isDefault()) {
// TODO: Skip non-default applications until supported properly
if (recurseOverApplications(request))
toSlime(applicationArray.addObject(), application, request);
else
toSlime(application, applicationArray.addObject(), request);
}
}
}
tenant.getPropertyId().ifPresent(propertyId -> {
try {
object.setString("propertyUrl", controller.organization().propertyUri(propertyId).toString());
object.setString("contactsUrl", controller.organization().contactsUri(propertyId).toString());
object.setString("issueCreationUrl", controller.organization().issueCreationUri(propertyId).toString());
Cursor lists = object.setArray("contacts");
for (List<? extends User> contactList : controller.organization().contactsFor(propertyId)) {
Cursor list = lists.addArray();
for (User contact : contactList) list.addString(contact.displayName());
}
} catch (RuntimeException e) {
log.log(Level.WARNING, "Error fetching property info for " + tenant + " with propertyId " + propertyId + ": " + Exceptions.toMessageString(e));
}
});
}
Aggregations