diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2024-02-28 16:05:07 +0000 |
---|---|---|
committer | danielhanrahan <daniel.hanrahan@est.tech> | 2024-02-29 12:21:52 +0000 |
commit | c5222a72ef11bd440f5c2bd017e820922ff6735a (patch) | |
tree | 072780e0dc9426a0828f29447eedeb4e4f75116d /cps-ncmp-rest/src/main/java | |
parent | 181c63d7007e685657cbd0d2c9b7693a073835dc (diff) |
Add bearer token to NCMP passthrough operations (CPS-2126 #2)
For NCMP resource data passthrough operations, accept an
authorization header and propagate it to outgoing DMI request
if it has a bearer token, otherwise use same behaviour as before
Issue-ID: CPS-2128
Change-Id: Ib3bf401abce4221a8b706989fb6f07618aa33fe2
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Diffstat (limited to 'cps-ncmp-rest/src/main/java')
4 files changed, 39 insertions, 22 deletions
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java index 6ec24448d7..1c6aaf2262 100755 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java @@ -94,6 +94,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { * @param optionsParamInQuery options query parameter * @param topicParamInQuery topic query parameter * @param includeDescendants whether to include descendants or not + * @param authorization contents of Authorization header, or null if not present * @return {@code ResponseEntity} response from dmi plugin */ @Override @@ -103,16 +104,17 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery, - final Boolean includeDescendants) { + final Boolean includeDescendants, + final String authorization) { final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler = getNcmpDatastoreRequestHandler(datastoreName); return ncmpDatastoreRequestHandler.executeRequest(datastoreName, cmHandle, resourceIdentifier, - optionsParamInQuery, topicParamInQuery, includeDescendants); + optionsParamInQuery, topicParamInQuery, includeDescendants, authorization); } @Override public ResponseEntity<Object> executeDataOperationForCmHandles(final String topicParamInQuery, - final DataOperationRequest - dataOperationRequest) { + final DataOperationRequest dataOperationRequest, + final String authorization) { return ncmpPassthroughResourceRequestHandler.executeRequest(topicParamInQuery, dataOperationRequestMapper.toDataOperationRequest(dataOperationRequest)); } @@ -148,6 +150,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { * @param resourceIdentifier resource identifier * @param requestBody the request body * @param contentType content type of body + * @param authorization contents of Authorization header, or null if not present * @return {@code ResponseEntity} response from dmi plugin */ @@ -156,14 +159,15 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { final String cmHandle, final String resourceIdentifier, final Object requestBody, - final String contentType) { + final String contentType, + final String authorization) { validateDataStore(PASSTHROUGH_RUNNING, datastoreName); final Object responseObject = networkCmProxyDataService .writeResourceDataPassThroughRunningForCmHandle( cmHandle, resourceIdentifier, PATCH, - jsonObjectMapper.asJsonString(requestBody), contentType); + jsonObjectMapper.asJsonString(requestBody), contentType, authorization); return ResponseEntity.ok(responseObject); } @@ -175,6 +179,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { * @param resourceIdentifier resource identifier * @param requestBody the request body * @param contentType content type of body + * @param authorization contents of Authorization header, or null if not present * @return {@code ResponseEntity} response from dmi plugin */ @Override @@ -182,12 +187,12 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { final String cmHandle, final String resourceIdentifier, final Object requestBody, - final String contentType) { - + final String contentType, + final String authorization) { validateDataStore(PASSTHROUGH_RUNNING, datastoreName); networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, - resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType); + resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType, authorization); return new ResponseEntity<>(HttpStatus.CREATED); } @@ -199,6 +204,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { * @param resourceIdentifier resource identifier * @param requestBody the request body * @param contentType content type of the body + * @param authorization contents of Authorization header, or null if not present * @return response entity */ @@ -207,11 +213,12 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { final String cmHandle, final String resourceIdentifier, final Object requestBody, - final String contentType) { + final String contentType, + final String authorization) { validateDataStore(PASSTHROUGH_RUNNING, datastoreName); networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, - resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType); + resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType, authorization); return new ResponseEntity<>(HttpStatus.OK); } @@ -222,18 +229,20 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { * @param cmHandle cm handle identifier * @param resourceIdentifier resource identifier * @param contentType content type of the body + * @param authorization contents of Authorization header, or null if not present * @return response entity no content if request is successful */ @Override public ResponseEntity<Void> deleteResourceDataRunningForCmHandle(final String datastoreName, final String cmHandle, final String resourceIdentifier, - final String contentType) { + final String contentType, + final String authorization) { validateDataStore(PASSTHROUGH_RUNNING, datastoreName); networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, - resourceIdentifier, DELETE, NO_BODY, contentType); + resourceIdentifier, DELETE, NO_BODY, contentType, authorization); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpCachedResourceRequestHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpCachedResourceRequestHandler.java index 85a1eae234..430c0996f9 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpCachedResourceRequestHandler.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpCachedResourceRequestHandler.java @@ -74,7 +74,8 @@ public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandle final String optionsParamInQuery, final String topicParamInQuery, final String requestId, - final boolean includeDescendants) { + final boolean includeDescendants, + final String authorization) { final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendants); diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandler.java index d40ab9b390..8b08090905 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandler.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandler.java @@ -56,6 +56,7 @@ public abstract class NcmpDatastoreRequestHandler { * @param optionsParamInQuery the options param in query * @param topicParamInQuery the topic param in query * @param includeDescendants whether include descendants + * @param authorization contents of Authorization header, or null if not present * @return the response entity */ public ResponseEntity<Object> executeRequest(final String datastoreName, @@ -63,12 +64,13 @@ public abstract class NcmpDatastoreRequestHandler { final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery, - final boolean includeDescendants) { + final boolean includeDescendants, + final String authorization) { final boolean asyncResponseRequested = topicParamInQuery != null; if (asyncResponseRequested && notificationFeatureEnabled) { return executeAsyncTaskAndGetResponseEntity(datastoreName, cmHandleId, resourceIdentifier, - optionsParamInQuery, topicParamInQuery, includeDescendants); + optionsParamInQuery, topicParamInQuery, includeDescendants, authorization); } if (asyncResponseRequested) { @@ -76,7 +78,7 @@ public abstract class NcmpDatastoreRequestHandler { + "will use synchronous operation."); } final Supplier<Object> taskSupplier = getTaskSupplierForGetRequest(datastoreName, cmHandleId, - resourceIdentifier, optionsParamInQuery, NO_TOPIC, NO_REQUEST_ID, includeDescendants); + resourceIdentifier, optionsParamInQuery, NO_TOPIC, NO_REQUEST_ID, includeDescendants, authorization); return executeTaskSync(taskSupplier); } @@ -99,10 +101,12 @@ public abstract class NcmpDatastoreRequestHandler { final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery, - final boolean includeDescendants) { + final boolean includeDescendants, + final String authorization) { final String requestId = UUID.randomUUID().toString(); final Supplier<Object> taskSupplier = getTaskSupplierForGetRequest(datastoreName, cmHandleId, - resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId, includeDescendants); + resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId, includeDescendants, + authorization); return executeTaskAsync(topicParamInQuery, requestId, taskSupplier); } @@ -112,6 +116,7 @@ public abstract class NcmpDatastoreRequestHandler { final String optionsParamInQuery, final String topicParamInQuery, final String requestId, - final boolean includeDescendant); + final boolean includeDescendant, + final String authorization); } diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java index 8a3257576d..5da8c91207 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/NcmpPassthroughResourceRequestHandler.java @@ -81,10 +81,12 @@ public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestH final String optionsParamInQuery, final String topicParamInQuery, final String requestId, - final boolean includeDescendants) { + final boolean includeDescendants, + final String authorization) { return () -> networkCmProxyDataService.getResourceDataForCmHandle( - datastoreName, cmHandleId, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId); + datastoreName, cmHandleId, resourceIdentifier, optionsParamInQuery, topicParamInQuery, requestId, + authorization); } private ResponseEntity<Object> getRequestIdAndSendDataOperationRequestToDmiService(final String topicParamInQuery, |