mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 23:29:28 -05:00
fix(iam): read a REST request's path and query members under a form too (#7527)
A member the table locates in a REST request's path or query was laid over a JSON body alone: a request sending a form skipped the overlay, so a form's DomainName was read in place of the path's. OpenSearch answers a form with 415, so no such request reaches its handlers today, but the next REST namespace the table reads whose handler does not refuse a form would be checked on the form's name while it acts on the path's. RequestResources now lays the located members over a form as it lays them over a JSON body, for the resources a request names and for those it creates: each is dropped from the form and read from the path or the query alone. RequestResourceMembersTest checks every resource of the table from a form as from a JSON body, each located member given in the path or the query and another value in the body and in the form; RequestResourcesTest sends OpenSearch requests as forms naming another domain than the path or the query does. iam.md says so.
This commit is contained in:
1 parent
c149ef7166
commit
26cd74e6f8
4 files changed
+95
-28
No files matched your search
@@ -98,8 +98,9 @@ public final class RequestResources {
|
||||
if (resources == null || resources.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
Map<String, String> form = IamConditionContextResolver.formParameters(ctx);
|
||||
JsonNode body = form.isEmpty() ? located(table, operation, PassedRoles.jsonBody(ctx), ctx, labels) : null;
|
||||
Map<String, String> sent = IamConditionContextResolver.formParameters(ctx);
|
||||
JsonNode body = sent.isEmpty() ? located(table, operation, PassedRoles.jsonBody(ctx), ctx, labels) : null;
|
||||
Map<String, String> form = located(table, operation, sent, ctx, labels);
|
||||
return named(resources, formats(table, operation), form, body, partition, region, accountId, stored);
|
||||
}
|
||||
|
||||
@@ -158,8 +159,9 @@ public final class RequestResources {
|
||||
if (creates == null && made.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
Map<String, String> form = IamConditionContextResolver.formParameters(ctx);
|
||||
JsonNode body = form.isEmpty() ? located(table, operation, PassedRoles.jsonBody(ctx), ctx, labels) : null;
|
||||
Map<String, String> sent = IamConditionContextResolver.formParameters(ctx);
|
||||
JsonNode body = sent.isEmpty() ? located(table, operation, PassedRoles.jsonBody(ctx), ctx, labels) : null;
|
||||
Map<String, String> form = located(table, operation, sent, ctx, labels);
|
||||
Map<String, RequestResourceMembers.ArnFormat> formats = formats(table, operation);
|
||||
if (creates == null) {
|
||||
return named(made, formats, form, body, partition, region, accountId, null);
|
||||
@@ -199,16 +201,46 @@ public final class RequestResources {
|
||||
return body;
|
||||
}
|
||||
ObjectNode overlaid = body instanceof ObjectNode object ? object.deepCopy() : JsonNodeFactory.instance.objectNode();
|
||||
located.keySet().forEach(overlaid::remove);
|
||||
locatedValues(located, ctx, labels).forEach(overlaid::put);
|
||||
return overlaid;
|
||||
}
|
||||
|
||||
/**
|
||||
* The request's form with each member the table locates laid over it, as a body has them laid over it: a REST
|
||||
* request sent as a form, to a handler that does not refuse one, is still routed by its path, so a member its path
|
||||
* or query carries is read from there alone, never from the form. The form itself when the request sends none or
|
||||
* the operation locates none.
|
||||
*/
|
||||
private static Map<String, String> located(RequestResourceMembers.Table table, String operation,
|
||||
Map<String, String> form, ContainerRequestContext ctx,
|
||||
Map<String, String> labels) {
|
||||
Map<String, String> located = table.located().getOrDefault(operation, Map.of());
|
||||
if (form.isEmpty() || located.isEmpty()) {
|
||||
return form;
|
||||
}
|
||||
Map<String, String> overlaid = new HashMap<>(form);
|
||||
overlaid.keySet().removeAll(located.keySet());
|
||||
overlaid.putAll(locatedValues(located, ctx, labels));
|
||||
return overlaid;
|
||||
}
|
||||
|
||||
/**
|
||||
* The value the request gives each member the table locates, by the member's name: a path label's from
|
||||
* {@code labels}, a query parameter's first value; none for one the request does not give.
|
||||
*/
|
||||
private static Map<String, String> locatedValues(Map<String, String> located, ContainerRequestContext ctx,
|
||||
Map<String, String> labels) {
|
||||
MultivaluedMap<String, String> query = ctx.getUriInfo() == null ? null : ctx.getUriInfo().getQueryParameters();
|
||||
Map<String, String> values = new HashMap<>();
|
||||
located.forEach((member, where) -> {
|
||||
overlaid.remove(member);
|
||||
String value = where.startsWith("{") ? labels.get(where.substring(1, where.length() - 1))
|
||||
: query == null ? null : query.getFirst(where.substring(1));
|
||||
if (value != null) {
|
||||
overlaid.put(member, value);
|
||||
values.put(member, value);
|
||||
}
|
||||
});
|
||||
return overlaid;
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user