Pass authorization headers to DMI from ProvMnS request 74/143074/1
authorseanbeirne <sean.beirne@est.tech>
Wed, 28 Jan 2026 10:42:36 +0000 (10:42 +0000)
committerseanbeirne <sean.beirne@est.tech>
Wed, 28 Jan 2026 10:42:36 +0000 (10:42 +0000)
Issue-ID: CPS-3150
Change-Id: I6acb76847bd1ec228eebcdd865dadec2f4dda41a
Signed-off-by: seanbeirne <sean.beirne@est.tech>
cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/ProvMnSController.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiRestClient.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiRestClientIntegrationSpec.groovy

index b8d6a03..b23436c 100644 (file)
@@ -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);
         }
index d94a69f..e09940a 100644 (file)
@@ -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<Object> 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<Object> 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<Object> 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<Object> 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();
     }
index 0270de6..288cd2a 100644 (file)
@@ -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)
     }