From: seanbeirne Date: Wed, 28 Jan 2026 10:42:36 +0000 (+0000) Subject: Pass authorization headers to DMI from ProvMnS request X-Git-Tag: 3.7.5~2^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=9f6d589769ad30a19e732858a9d0539bd8fdd96c;p=cps.git Pass authorization headers to DMI from ProvMnS request Issue-ID: CPS-3150 Change-Id: I6acb76847bd1ec228eebcdd865dadec2f4dda41a Signed-off-by: seanbeirne --- diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/ProvMnSController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/ProvMnSController.java index b8d6a03d18..b23436c236 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/ProvMnSController.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/ProvMnSController.java @@ -101,7 +101,8 @@ public class ProvMnSController implements ProvMnS { final YangModelCmHandle yangModelCmHandle = getAndValidateYangModelCmHandle(requestParameters); final UrlTemplateParameters urlTemplateParameters = parametersBuilder.createUrlTemplateParametersForRead( yangModelCmHandle, requestParameters.fdn(), scope, filter, attributes, fields, dataNodeSelector); - return dmiRestClient.synchronousGetOperation(DATA, urlTemplateParameters); + return dmiRestClient.synchronousGetOperation(DATA, + urlTemplateParameters, requestParameters.authorization()); } catch (final Exception exception) { throw toProvMnSException(httpServletRequest.getMethod(), exception, NO_OP); } @@ -123,7 +124,7 @@ public class ProvMnSController implements ProvMnS { final UrlTemplateParameters urlTemplateParameters = parametersBuilder.createUrlTemplateParametersForWrite(yangModelCmHandle, requestParameters.fdn()); return dmiRestClient.synchronousPatchOperation(DATA, patchItems, urlTemplateParameters, - httpServletRequest.getContentType()); + httpServletRequest.getContentType(), requestParameters.authorization()); } catch (final Exception exception) { throw toProvMnSException(httpServletRequest.getMethod(), exception, NO_OP); } @@ -139,7 +140,8 @@ public class ProvMnSController implements ProvMnS { checkPermission(yangModelCmHandle, operationDetails, requestParameters); final UrlTemplateParameters urlTemplateParameters = parametersBuilder.createUrlTemplateParametersForWrite(yangModelCmHandle, requestParameters.fdn()); - return dmiRestClient.synchronousPutOperation(DATA, resource, urlTemplateParameters); + return dmiRestClient.synchronousPutOperation(DATA, resource, + urlTemplateParameters, requestParameters.authorization()); } catch (final Exception exception) { throw toProvMnSException(httpServletRequest.getMethod(), exception, NO_OP); } @@ -155,7 +157,8 @@ public class ProvMnSController implements ProvMnS { checkPermission(yangModelCmHandle, operationDetails, requestParameters); final UrlTemplateParameters urlTemplateParameters = parametersBuilder.createUrlTemplateParametersForWrite(yangModelCmHandle, requestParameters.fdn()); - return dmiRestClient.synchronousDeleteOperation(DATA, urlTemplateParameters); + return dmiRestClient.synchronousDeleteOperation(DATA, + urlTemplateParameters, requestParameters.authorization()); } catch (final Exception exception) { throw toProvMnSException(httpServletRequest.getMethod(), exception, NO_OP); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java index d94a69f064..e09940a0ef 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java @@ -124,14 +124,16 @@ public class DmiRestClient { * * @param requiredDmiService Determines if the required service is for a data or model operation. * @param urlTemplateParameters The DMI resource URL template with variables. + * @param authorization The authorization token to be added to the request headers. * @return ResponseEntity containing the response from the DMI. */ public ResponseEntity synchronousGetOperation(final RequiredDmiService requiredDmiService, - final UrlTemplateParameters urlTemplateParameters) { + final UrlTemplateParameters urlTemplateParameters, + final String authorization) { return getWebClient(requiredDmiService) .get() .uri(urlTemplateParameters.urlTemplate(), urlTemplateParameters.urlVariables()) - .headers(httpHeaders -> configureHttpHeaders(httpHeaders, NO_AUTHORIZATION)) + .headers(httpHeaders -> configureHttpHeaders(httpHeaders, authorization)) .exchangeToMono(this::createIdenticalResponseForClient) .block(); } @@ -142,11 +144,13 @@ public class DmiRestClient { * @param requiredDmiService Determines if the required service is for a data or model operation. * @param body resource object to be forwarded. * @param urlTemplateParameters The DMI resource URL template with variables. + * @param authorization The authorization token to be added to the request headers. * @return ResponseEntity containing the response from the DMI. */ public ResponseEntity synchronousPutOperation(final RequiredDmiService requiredDmiService, final Object body, - final UrlTemplateParameters urlTemplateParameters) { + final UrlTemplateParameters urlTemplateParameters, + final String authorization) { return getWebClient(requiredDmiService) .put() .uri(urlTemplateParameters.urlTemplate(), urlTemplateParameters.urlVariables()) @@ -163,16 +167,18 @@ public class DmiRestClient { * @param body object * @param urlTemplateParameters The DMI resource URL template with variables. * @param contentType Content type example: application/json + * @param authorization The authorization token to be added to the request headers. * @return ResponseEntity containing the response from the DMI. */ public ResponseEntity synchronousPatchOperation(final RequiredDmiService requiredDmiService, final Object body, final UrlTemplateParameters urlTemplateParameters, - final String contentType) { + final String contentType, + final String authorization) { return getWebClient(requiredDmiService) .patch() .uri(urlTemplateParameters.urlTemplate(), urlTemplateParameters.urlVariables()) - .headers(httpHeaders -> configureHttpHeaders(httpHeaders, NO_AUTHORIZATION)) + .headers(httpHeaders -> configureHttpHeaders(httpHeaders, authorization)) .contentType(MediaType.parseMediaType(contentType)) .bodyValue(body) .exchangeToMono(this::createIdenticalResponseForClient) @@ -228,15 +234,17 @@ public class DmiRestClient { * * @param requiredDmiService Determines if the required service is for a data or model operation. * @param urlTemplateParameters The DMI resource URL template with variables. + * @param authorization The authorization token to be added to the request headers. * @return ResponseEntity containing the response from the DMI. * */ public ResponseEntity synchronousDeleteOperation(final RequiredDmiService requiredDmiService, - final UrlTemplateParameters urlTemplateParameters) { + final UrlTemplateParameters urlTemplateParameters, + final String authorization) { return getWebClient(requiredDmiService) .delete() .uri(urlTemplateParameters.urlTemplate(), urlTemplateParameters.urlVariables()) - .headers(httpHeaders -> configureHttpHeaders(httpHeaders, NO_AUTHORIZATION)) + .headers(httpHeaders -> configureHttpHeaders(httpHeaders, authorization)) .exchangeToMono(this::createIdenticalResponseForClient) .block(); } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiRestClientIntegrationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiRestClientIntegrationSpec.groovy index 0270de62f4..288cd2a696 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiRestClientIntegrationSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiRestClientIntegrationSpec.groovy @@ -66,19 +66,19 @@ class DmiRestClientIntegrationSpec extends Specification { def result switch(method) { case 'get': - result = objectUnderTest.synchronousGetOperation(DATA, urlTemplateParameters) + result = objectUnderTest.synchronousGetOperation(DATA, urlTemplateParameters, 'some-authorization') break case 'post': result = objectUnderTest.synchronousPostOperation(DATA, urlTemplateParameters, 'body', CREATE, '') break case 'put': - result = objectUnderTest.synchronousPutOperation(DATA, 'body', urlTemplateParameters) + result = objectUnderTest.synchronousPutOperation(DATA, 'body', urlTemplateParameters, 'some-authorization') break case 'patch': - result = objectUnderTest.synchronousPatchOperation(DATA, 'body', urlTemplateParameters, 'application/json-patch+json') + result = objectUnderTest.synchronousPatchOperation(DATA, 'body', urlTemplateParameters, 'application/json-patch+json', 'some-authorization') break case 'delete': - result = objectUnderTest.synchronousDeleteOperation(DATA, urlTemplateParameters) + result = objectUnderTest.synchronousDeleteOperation(DATA, urlTemplateParameters, 'some-authorization') } then: 'the result has the same status code of 200' assert result.statusCode.value() == 200 @@ -128,7 +128,7 @@ class DmiRestClientIntegrationSpec extends Specification { given: 'Mock a bad URL that causes IllegalArgumentException before HTTP call' def badUrlParameters = new UrlTemplateParameters(':://bad url', [someParam: 'value']) when: 'a synchronous request is attempted' - objectUnderTest.synchronousGetOperation(DATA, badUrlParameters) + objectUnderTest.synchronousGetOperation(DATA, badUrlParameters, 'some-authorization') then: 'a invalid url exception is thrown (no mapping)' thrown(InvalidUrlException) }