mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(core): share JSON authorization and CBOR test helpers (#9133)
* refactor(core): share JSON authorization and CBOR test helpers
This commit is contained in:
1 parent
e725ed6e9a
commit
98efc5f949
7 files changed
+100
-68
No files matched your search
@@ -315,10 +315,7 @@ public class AwsJson11Controller {
|
||||
|
||||
try {
|
||||
String region = regionResolver.getRegion();
|
||||
String authorization = httpHeaders.getHeaderString("Authorization");
|
||||
if (authorization == null || authorization.isBlank()) {
|
||||
authorization = IamEnforcementFilter.requestAuthorization(null, uriInfo.getQueryParameters());
|
||||
}
|
||||
String authorization = requestAuthorization(httpHeaders, uriInfo);
|
||||
|
||||
Response delegated = dispatch(targetMatch, request, region, authorization, uriInfo.getBaseUri());
|
||||
// catalog.matchTarget is protocol-agnostic: a JSON 1.0 target
|
||||
@@ -336,6 +333,15 @@ public class AwsJson11Controller {
|
||||
}
|
||||
}
|
||||
|
||||
/** Uses the header credential, falling back to the query only when the header is absent or blank. */
|
||||
static String requestAuthorization(HttpHeaders headers, UriInfo uriInfo) {
|
||||
String authorization = headers.getHeaderString("Authorization");
|
||||
if (authorization == null || authorization.isBlank()) {
|
||||
authorization = IamEnforcementFilter.requestAuthorization(null, uriInfo.getQueryParameters());
|
||||
}
|
||||
return authorization;
|
||||
}
|
||||
|
||||
/** Dispatches an already-decoded request before HTTP-specific response encoding. */
|
||||
Response dispatch(ServiceCatalog.TargetMatch targetMatch, JsonNode request, String region,
|
||||
String authorization, URI baseUri) throws Exception {
|
||||
|
||||
@@ -576,10 +576,7 @@ public class AwsJsonCborController {
|
||||
if (request == null || !request.isObject()) {
|
||||
throw new AwsException("SerializationException", "Request body must be a structure", 400);
|
||||
}
|
||||
String authorization = headers.getHeaderString("Authorization");
|
||||
if (authorization == null || authorization.isBlank()) {
|
||||
authorization = IamEnforcementFilter.requestAuthorization(null, uriInfo.getQueryParameters());
|
||||
}
|
||||
String authorization = AwsJson11Controller.requestAuthorization(headers, uriInfo);
|
||||
Response response = json11Controller.dispatch(target, request, region, authorization, uriInfo.getBaseUri());
|
||||
return response != null ? response : jsonController.dispatch(target, request, region, null);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user