Added support for PMS sending an authorization token in each REST call(in the HTTP header).
The token is read from a file.
Issue-ID: CCSDK-3560
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Change-Id: I92229f67d2c1486530f3c6ebb22f60bd3b359676
org.springframework.data: ERROR
org.springframework.web.reactive.function.client.ExchangeFunctions: ERROR
org.onap.ccsdk.oran.a1policymanagementservice: INFO
- # org.onap.ccsdk.oran.a1policymanagementservice.tasks: TRACE
+ # org.onap.ccsdk.oran.a1policymanagementservice.tasks: TRACE
file:
name: /var/log/policy-agent/application.log
server:
http.proxy-type: HTTP
# path where the service can store data
vardata-directory: /var/policy-management-service
- # the config-file-schema-path referres to a location in the jar file. If this property is empty or missing,
- # no schema validation will be executed.
+ # the config-file-schema-path referres to a location in the jar file. If this property is empty or missing,
+ # no schema validation will be executed.
config-file-schema-path: /application_configuration_schema.json
+ # A file containing an authorization token, which shall be inserted in each HTTP header (authorization).
+ # If the file name is empty, no authorization token is sent.
+ auth-token-file:
import org.apache.catalina.connector.Connector;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
}
@Bean
- public A1ClientFactory getA1ClientFactory(@Autowired ApplicationConfig applicationConfig) {
- return new A1ClientFactory(applicationConfig);
+ public A1ClientFactory getA1ClientFactory(@Autowired ApplicationConfig applicationConfig,
+ @Autowired SecurityContext securityContext) {
+ return new A1ClientFactory(applicationConfig, securityContext);
}
@Bean
private final AsyncRestClientFactory restClientFactory;
@Autowired
- public A1ClientFactory(ApplicationConfig appConfig) {
+ public A1ClientFactory(ApplicationConfig appConfig, SecurityContext securityContext) {
this.appConfig = appConfig;
- this.restClientFactory = new AsyncRestClientFactory(appConfig.getWebClientConfig());
+ this.restClientFactory = new AsyncRestClientFactory(appConfig.getWebClientConfig(), securityContext);
}
/**
* ========================LICENSE_START=================================
* ONAP : ccsdk oran
* ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2019-2022 Nordix Foundation. All rights reserved.
* ======================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.lang.Nullable;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec;
-import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Mono;
import reactor.netty.http.client.HttpClient;
+import reactor.netty.transport.ProxyProvider;
/**
* Generic reactive REST client.
private static final AtomicInteger sequenceNumber = new AtomicInteger();
private final SslContext sslContext;
private final HttpProxyConfig httpProxyConfig;
+ private final SecurityContext securityContext;
- public AsyncRestClient(String baseUrl, @Nullable SslContext sslContext, @Nullable HttpProxyConfig httpProxyConfig) {
+ public AsyncRestClient(String baseUrl, @Nullable SslContext sslContext, @Nullable HttpProxyConfig httpProxyConfig,
+ SecurityContext securityContext) {
this.baseUrl = baseUrl;
this.sslContext = sslContext;
this.httpProxyConfig = httpProxyConfig;
+ this.securityContext = securityContext;
}
public Mono<ResponseEntity<String>> postForEntity(String uri, @Nullable String body) {
- Object traceTag = createTraceTag();
- logger.debug("{} POST uri = '{}{}'", traceTag, baseUrl, uri);
- logger.trace("{} POST body: {}", traceTag, body);
Mono<String> bodyProducer = body != null ? Mono.just(body) : Mono.empty();
RequestHeadersSpec<?> request = getWebClient() //
.uri(uri) //
.contentType(MediaType.APPLICATION_JSON) //
.body(bodyProducer, String.class);
- return retrieve(traceTag, request);
+ return retrieve(request);
}
public Mono<String> post(String uri, @Nullable String body) {
}
public Mono<String> postWithAuthHeader(String uri, String body, String username, String password) {
- Object traceTag = createTraceTag();
- logger.debug("{} POST (auth) uri = '{}{}'", traceTag, baseUrl, uri);
- logger.trace("{} POST body: {}", traceTag, body);
-
RequestHeadersSpec<?> request = getWebClient() //
.post() //
.uri(uri) //
.headers(headers -> headers.setBasicAuth(username, password)) //
.contentType(MediaType.APPLICATION_JSON) //
.bodyValue(body);
- return retrieve(traceTag, request) //
+ return retrieve(request) //
.map(this::toBody);
}
public Mono<ResponseEntity<String>> putForEntity(String uri, String body) {
- Object traceTag = createTraceTag();
- logger.debug("{} PUT uri = '{}{}'", traceTag, baseUrl, uri);
- logger.trace("{} PUT body: {}", traceTag, body);
-
RequestHeadersSpec<?> request = getWebClient() //
.put() //
.uri(uri) //
.contentType(MediaType.APPLICATION_JSON) //
.bodyValue(body);
- return retrieve(traceTag, request);
+ return retrieve(request);
}
public Mono<ResponseEntity<String>> putForEntity(String uri) {
- Object traceTag = createTraceTag();
- logger.debug("{} PUT uri = '{}{}'", traceTag, baseUrl, uri);
- logger.trace("{} PUT body: <empty>", traceTag);
RequestHeadersSpec<?> request = getWebClient() //
.put() //
.uri(uri);
- return retrieve(traceTag, request);
+ return retrieve(request);
}
public Mono<String> put(String uri, String body) {
}
public Mono<ResponseEntity<String>> getForEntity(String uri) {
- Object traceTag = createTraceTag();
- logger.debug("{} GET uri = '{}{}'", traceTag, baseUrl, uri);
- RequestHeadersSpec<?> request = getWebClient() //
- .get() //
- .uri(uri);
- return retrieve(traceTag, request);
+ RequestHeadersSpec<?> request = getWebClient().get().uri(uri);
+ return retrieve(request);
}
public Mono<String> get(String uri) {
}
public Mono<ResponseEntity<String>> deleteForEntity(String uri) {
- Object traceTag = createTraceTag();
- logger.debug("{} DELETE uri = '{}{}'", traceTag, baseUrl, uri);
- RequestHeadersSpec<?> request = getWebClient() //
- .delete() //
- .uri(uri);
- return retrieve(traceTag, request);
+ RequestHeadersSpec<?> request = getWebClient().delete().uri(uri);
+ return retrieve(request);
}
public Mono<String> delete(String uri) {
.map(this::toBody);
}
- private Mono<ResponseEntity<String>> retrieve(Object traceTag, RequestHeadersSpec<?> request) {
- final Class<String> clazz = String.class;
+ private Mono<ResponseEntity<String>> retrieve(RequestHeadersSpec<?> request) {
+ if (securityContext.isConfigured()) {
+ request.headers(h -> h.setBearerAuth(securityContext.getBearerAuthToken()));
+ }
return request.retrieve() //
- .toEntity(clazz) //
- .doOnNext(entity -> logReceivedData(traceTag, entity)) //
- .doOnError(throwable -> onHttpError(traceTag, throwable));
- }
-
- private void logReceivedData(Object traceTag, ResponseEntity<String> entity) {
- logger.trace("{} Received: {} {}", traceTag, entity.getBody(), entity.getHeaders().getContentType());
+ .toEntity(String.class);
}
private static Object createTraceTag() {
return sequenceNumber.incrementAndGet();
}
- private void onHttpError(Object traceTag, Throwable t) {
- if (t instanceof WebClientResponseException) {
- WebClientResponseException exception = (WebClientResponseException) t;
- logger.debug("{} HTTP error status = '{}', body '{}'", traceTag, exception.getStatusCode(),
- exception.getResponseBodyAsString());
- } else {
- logger.debug("{} HTTP error {}", traceTag, t.getMessage());
- }
- }
-
private String toBody(ResponseEntity<String> entity) {
if (entity.getBody() == null) {
return "";
}
if (isHttpProxyConfigured()) {
- httpClient = httpClient.proxy(proxy -> proxy.type(httpProxyConfig.httpProxyType()) //
- .host(httpProxyConfig.httpProxyHost()) //
- .port(httpProxyConfig.httpProxyPort()));
+ httpClient = httpClient.proxy(proxy -> proxy.type(ProxyProvider.Proxy.HTTP)
+ .host(httpProxyConfig.httpProxyHost()).port(httpProxyConfig.httpProxyPort()));
}
return httpClient;
}
- private WebClient buildWebClient(String baseUrl) {
+ public WebClient buildWebClient(String baseUrl) {
+ Object traceTag = createTraceTag();
+
final HttpClient httpClient = buildHttpClient();
ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder() //
.codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(-1)) //
.build();
+
+ ExchangeFilterFunction reqLogger = ExchangeFilterFunction.ofRequestProcessor(req -> {
+ logger.debug("{} {} uri = '{}''", traceTag, req.method(), req.url());
+ return Mono.just(req);
+ });
+
+ ExchangeFilterFunction respLogger = ExchangeFilterFunction.ofResponseProcessor(resp -> {
+ logger.debug("{} resp: {}", traceTag, resp.statusCode());
+ return Mono.just(resp);
+ });
+
return WebClient.builder() //
.clientConnector(new ReactorClientHttpConnector(httpClient)) //
.baseUrl(baseUrl) //
.exchangeStrategies(exchangeStrategies) //
+ .filter(reqLogger) //
+ .filter(respLogger) //
.build();
}
* ========================LICENSE_START=================================
* ONAP : ccsdk oran
* ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2019-2022 Nordix Foundation. All rights reserved.
* ======================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* Factory for a generic reactive REST client.
*/
-@SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally
public class AsyncRestClientFactory {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final SslContextFactory sslContextFactory;
private final HttpProxyConfig httpProxyConfig;
+ private final SecurityContext securityContext;
- public AsyncRestClientFactory(WebClientConfig clientConfig) {
+ public AsyncRestClientFactory(WebClientConfig clientConfig, SecurityContext securityContext) {
if (clientConfig != null) {
this.sslContextFactory = new CachingSslContextFactory(clientConfig);
this.httpProxyConfig = clientConfig.httpProxyConfig();
this.sslContextFactory = null;
this.httpProxyConfig = null;
}
+ this.securityContext = securityContext;
}
public AsyncRestClient createRestClientNoHttpProxy(String baseUrl) {
if (this.sslContextFactory != null) {
try {
return new AsyncRestClient(baseUrl, this.sslContextFactory.createSslContext(),
- useHttpProxy ? httpProxyConfig : null);
+ useHttpProxy ? httpProxyConfig : null, this.securityContext);
} catch (Exception e) {
String exceptionString = e.toString();
logger.error("Could not init SSL context, reason: {}", exceptionString);
}
}
- return new AsyncRestClient(baseUrl, null, httpProxyConfig);
+ return new AsyncRestClient(baseUrl, null, httpProxyConfig, this.securityContext);
}
private class SslContextFactory {
--- /dev/null
+/*-
+ * ========================LICENSE_START=================================
+ * ONAP : ccsdk oran
+ * ======================================================================
+ * Copyright (C) 2019-2022 Nordix Foundation. All rights reserved.
+ * ======================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================LICENSE_END===================================
+ */
+
+package org.onap.ccsdk.oran.a1policymanagementservice.clients;
+
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import lombok.Setter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@EnableConfigurationProperties
+@ConfigurationProperties()
+@Component
+public class SecurityContext {
+
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ private long tokenTimestamp = 0;
+
+ private String authToken = "";
+
+ @Setter
+ private Path authTokenFilePath;
+
+ public SecurityContext(@Value("${app.auth-token-file:\"\"}") String authTokenFilename) {
+ if (!authTokenFilename.isEmpty()) {
+ this.authTokenFilePath = Path.of(authTokenFilename);
+ }
+ }
+
+ public boolean isConfigured() {
+ return authTokenFilePath != null;
+ }
+
+ public synchronized String getBearerAuthToken() {
+ if (!isConfigured()) {
+ return "";
+ }
+ try {
+ long lastModified = authTokenFilePath.toFile().lastModified();
+ if (lastModified != this.tokenTimestamp) {
+ this.authToken = Files.readString(authTokenFilePath);
+ this.tokenTimestamp = lastModified;
+ }
+ } catch (Exception e) {
+ logger.warn("Could not read auth token file: {}, reason: {}", authTokenFilePath, e.getMessage());
+ }
+ return this.authToken;
+ }
+
+}
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@Autowired
- public DmaapMessageConsumer(ApplicationConfig applicationConfig) {
+ public DmaapMessageConsumer(ApplicationConfig applicationConfig, SecurityContext securityContext) {
this.applicationConfig = applicationConfig;
GsonBuilder gsonBuilder = new GsonBuilder();
this.gson = gsonBuilder.create();
- this.restClientFactory = new AsyncRestClientFactory(applicationConfig.getWebClientConfig());
+ this.restClientFactory = new AsyncRestClientFactory(applicationConfig.getWebClientConfig(), securityContext);
}
/**
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig.RicConfigUpdate;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfigParser;
@Autowired
public RefreshConfigTask(ConfigurationFile configurationFile, ApplicationConfig appConfig, Rics rics,
- Policies policies, Services services, PolicyTypes policyTypes, A1ClientFactory a1ClientFactory) {
+ Policies policies, Services services, PolicyTypes policyTypes, A1ClientFactory a1ClientFactory,
+ SecurityContext securityContext) {
this.configurationFile = configurationFile;
this.appConfig = appConfig;
this.rics = rics;
this.services = services;
this.policyTypes = policyTypes;
this.a1ClientFactory = a1ClientFactory;
- this.restClientFactory = new AsyncRestClientFactory(appConfig.getWebClientConfig());
+ this.restClientFactory = new AsyncRestClientFactory(appConfig.getWebClientConfig(), securityContext);
}
public void start() {
/**
* for an added RIC after a restart it is nesessary to get the suypported policy
* types from the RIC unless a full synchronization is wanted.
- *
+ *
* @param ric the ric to get supprted types from
* @return the same ric
*/
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Lock.LockType;
@Autowired
public RicSupervision(Rics rics, Policies policies, A1ClientFactory a1ClientFactory, PolicyTypes policyTypes,
- Services services, ApplicationConfig config) {
+ Services services, ApplicationConfig config, SecurityContext securityContext) {
this.rics = rics;
this.policies = policies;
this.a1ClientFactory = a1ClientFactory;
this.policyTypes = policyTypes;
this.services = services;
- this.restClientFactory = new AsyncRestClientFactory(config.getWebClientConfig());
+ this.restClientFactory = new AsyncRestClientFactory(config.getWebClientConfig(), securityContext);
}
/**
@BeforeEach
void createFactoryUnderTest() {
- factoryUnderTest = spy(new A1ClientFactory(applicationConfigMock));
+ SecurityContext sec = new SecurityContext("");
+ factoryUnderTest = spy(new A1ClientFactory(applicationConfigMock, sec));
this.ric = new Ric(ricConfig(""));
}
InternalLoggerFactory.setDefaultFactory(JdkLoggerFactory.INSTANCE);
Loggers.useJdkLoggers();
mockWebServer = new MockWebServer();
- clientUnderTest = new AsyncRestClient(mockWebServer.url(BASE_URL).toString(), null, null);
+ clientUnderTest =
+ new AsyncRestClient(mockWebServer.url(BASE_URL).toString(), null, null, new SecurityContext(""));
}
@AfterAll
@Test
void createClientWithWrongProtocol_thenErrorIsThrown() {
- AsyncRestClient asyncRestClient = new AsyncRestClient("", null, null);
+ AsyncRestClient asyncRestClient = new AsyncRestClient("", null, null, new SecurityContext(""));
assertThrows(IllegalArgumentException.class, () -> {
new CcsdkA1AdapterClient(A1ProtocolType.STD_V1_1, null, null, asyncRestClient);
});
* ========================LICENSE_START=================================
* ONAP : ccsdk oran
* ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2019-2022 Nordix Foundation. All rights reserved.
* ======================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.Instant;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig.RicConfigUpdate;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
@TestPropertySource(properties = { //
"server.ssl.key-store=./src/test/resources/keystore.jks", //
"app.webclient.trust-store=./src/test/resources/truststore.jks", //
+ "app.webclient.trust-store-used=true", //
"app.vardata-directory=./target/testdata", //
"app.filepath=" //
})
@Autowired
RefreshConfigTask refreshConfigTask;
+ @Autowired
+ SecurityContext securityContext;
+
private static Gson gson = new GsonBuilder().create();
/**
a1ClientFactory.reset();
this.rAppSimulator.getTestResults().clear();
this.a1ClientFactory.setPolicyTypes(policyTypes); // Default same types in RIC and in this app
+ this.securityContext.setAuthTokenFilePath(null);
}
@AfterEach
}
@Test
- void testServiceNotification() throws ServiceException {
+ void testServiceNotification() throws Exception {
+
+ final String AUTH_TOKEN = "testToken";
+ Path authFile = Files.createTempFile("pmsTestAuthToken", ".txt");
+ Files.write(authFile, AUTH_TOKEN.getBytes());
+ this.securityContext.setAuthTokenFilePath(authFile);
+
putService("junkService");
Service junkService = this.services.get("junkService");
junkService.setCallbackUrl("https://junk");
ServiceCallbackInfo callbackInfo = receivedCallbacks.getReceivedInfo().get(0);
assertThat(callbackInfo.ricId).isEqualTo("ric1");
assertThat(callbackInfo.eventType).isEqualTo(ServiceCallbackInfo.EventType.AVAILABLE);
+
+ var headers = receivedCallbacks.receivedHeaders.get(0);
+ assertThat(headers).containsEntry("authorization", "Bearer " + AUTH_TOKEN);
+
+ Files.delete(authFile);
}
private Policy addPolicy(String id, String typeName, String service, String ric) throws ServiceException {
.httpProxyConfig(config.httpProxyConfig()) //
.build();
- AsyncRestClientFactory f = new AsyncRestClientFactory(config);
+ AsyncRestClientFactory f = new AsyncRestClientFactory(config, new SecurityContext(""));
return f.createRestClientNoHttpProxy(baseUrl);
}
import org.junit.jupiter.api.io.TempDir;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableWebClientConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.WebClientConfig;
.httpProxyConfig(config.httpProxyConfig()) //
.build();
- AsyncRestClientFactory f = new AsyncRestClientFactory(config);
+ AsyncRestClientFactory f = new AsyncRestClientFactory(config, new SecurityContext(""));
return f.createRestClientNoHttpProxy("https://localhost:" + port);
}
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import java.util.Vector;
import lombok.Getter;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
@RestController("RappCallbacksController")
@Getter
private Vector<ServiceCallbackInfo> receivedInfo = new Vector<>();
+ public List<Map<String, String>> receivedHeaders =
+ Collections.synchronizedList(new ArrayList<Map<String, String>>());
+
public void clear() {
receivedInfo.clear();
+ receivedHeaders.clear();
}
}
)
public ResponseEntity<Object> serviceCallback( //
- @RequestBody ServiceCallbackInfo body) {
+ @RequestBody ServiceCallbackInfo body, @RequestHeader Map<String, String> headers) {
+ logHeaders(headers);
logger.info("R-App callback body: {}", gson.toJson(body));
+ this.testResults.receivedHeaders.add(headers);
this.testResults.receivedInfo.add(body);
return new ResponseEntity<>(HttpStatus.OK);
}
+ private void logHeaders(Map<String, String> headers) {
+ logger.debug("Header begin");
+ headers.forEach((key, value) -> logger.debug(" key: {}, value: {}", key, value));
+ logger.debug("Header end");
+ }
+
}
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.dmaap.DmaapRequestMessage.Operation;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
@Test
void successfulCase_dmaapNotConfigured_thenSleepAndRetryUntilConfig() throws Exception {
- messageConsumerUnderTest = spy(new DmaapMessageConsumer(applicationConfigMock));
+ messageConsumerUnderTest = spy(new DmaapMessageConsumer(applicationConfigMock, new SecurityContext("")));
setTaskNumberOfLoops(3);
disableTaskDelay();
@Test
void returnErrorFromDmapp_thenSleepAndRetry() throws Exception {
- messageConsumerUnderTest = spy(new DmaapMessageConsumer(applicationConfigMock));
+ messageConsumerUnderTest = spy(new DmaapMessageConsumer(applicationConfigMock, new SecurityContext("")));
setTaskNumberOfLoops(2);
disableTaskDelay();
@Test
void unParsableMessage_thenSendResponseAndContinue() throws Exception {
- messageConsumerUnderTest = spy(new DmaapMessageConsumer(applicationConfigMock));
+ messageConsumerUnderTest = spy(new DmaapMessageConsumer(applicationConfigMock, new SecurityContext("")));
setTaskNumberOfLoops(2);
setUpMrConfig();
@Test
void testMessageParsing() throws ServiceException {
- messageConsumerUnderTest = new DmaapMessageConsumer(applicationConfigMock);
+ messageConsumerUnderTest = new DmaapMessageConsumer(applicationConfigMock, new SecurityContext(""));
String json = gson.toJson(dmaapRequestMessage());
{
String jsonArrayOfObject = jsonArray(json);
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig.RicConfigUpdate.Type;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfigParser;
private RefreshConfigTask createTestObject(boolean configFileExists, Rics rics, Policies policies,
boolean stubConfigFileExists) {
-
- RefreshConfigTask obj = spy(new RefreshConfigTask(configurationFileMock, appConfig, rics, policies,
- new Services(appConfig), new PolicyTypes(appConfig), new A1ClientFactory(appConfig)));
+ SecurityContext secContext = new SecurityContext("");
+ RefreshConfigTask obj =
+ spy(new RefreshConfigTask(configurationFileMock, appConfig, rics, policies, new Services(appConfig),
+ new PolicyTypes(appConfig), new A1ClientFactory(appConfig, secContext), secContext));
if (stubConfigFileExists) {
when(configurationFileMock.readFile()).thenReturn(Optional.empty());
doReturn(123L).when(configurationFileMock).getLastModified();
import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Lock;
private RicSupervision createRicSupervision() {
ApplicationConfig config = new ApplicationConfig();
- return new RicSupervision(rics, policies, a1ClientFactory, types, null, config);
+ return new RicSupervision(rics, policies, a1ClientFactory, types, null, config, new SecurityContext(""));
}
}
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
private RicSynchronizationTask createTask() {
ApplicationConfig config = new ApplicationConfig();
- AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config.getWebClientConfig());
+ AsyncRestClientFactory restClientFactory =
+ new AsyncRestClientFactory(config.getWebClientConfig(), new SecurityContext(""));
return new RicSynchronizationTask(a1ClientFactoryMock, policyTypes, policies, services, restClientFactory,
rics);
};
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
private final ApplicationConfig appConfig;
public MockA1ClientFactory(ApplicationConfig config, PolicyTypes policyTypes) {
- super(config);
+ super(config, new SecurityContext(""));
this.policyTypes = policyTypes;
this.appConfig = config;
}
/**
* Simulate network latency. The REST responses will be generated by separate
* threads
- *
+ *
* @param delay the delay between the request and the response
*/
public void setResponseDelay(Duration delay) {
],
"tags": ["A1 Policy Management"]
}},
+ "/actuator/threaddump": {"get": {
+ "summary": "Actuator web endpoint 'threaddump'",
+ "operationId": "threaddump_2",
+ "responses": {"200": {
+ "description": "OK",
+ "content": {"*/*": {"schema": {"type": "object"}}}
+ }},
+ "tags": ["Actuator"]
+ }},
"/a1-policy/v2/status": {"get": {
"summary": "Returns status and statistics of this service",
"operationId": "getStatus",
}},
"tags": ["Health Check"]
}},
- "/actuator/threaddump": {"get": {
- "summary": "Actuator web endpoint 'threaddump'",
- "operationId": "threaddump_4",
+ "/actuator/loggers": {"get": {
+ "summary": "Actuator web endpoint 'loggers'",
+ "operationId": "loggers",
+ "responses": {"200": {
+ "description": "OK",
+ "content": {"*/*": {"schema": {"type": "object"}}}
+ }},
+ "tags": ["Actuator"]
+ }},
+ "/actuator/health/**": {"get": {
+ "summary": "Actuator web endpoint 'health-path'",
+ "operationId": "health-path",
"responses": {"200": {
"description": "OK",
"content": {"*/*": {"schema": {"type": "object"}}}
],
"tags": ["NearRT-RIC Repository"]
}},
- "/actuator/loggers": {"get": {
- "summary": "Actuator web endpoint 'loggers'",
- "operationId": "loggers_2",
- "responses": {"200": {
- "description": "OK",
- "content": {"*/*": {"schema": {"type": "object"}}}
- }},
- "tags": ["Actuator"]
- }},
- "/actuator/health/**": {"get": {
- "summary": "Actuator web endpoint 'health-path'",
- "operationId": "health-path_2",
- "responses": {"200": {
- "description": "OK",
- "content": {"*/*": {"schema": {"type": "object"}}}
- }},
- "tags": ["Actuator"]
- }},
"/a1-policy/v2/policy-types": {"get": {
"summary": "Query policy type identities",
"operationId": "getPolicyTypes",
},
"/actuator/metrics/{requiredMetricName}": {"get": {
"summary": "Actuator web endpoint 'metrics-requiredMetricName'",
- "operationId": "metrics-requiredMetricName_2",
+ "operationId": "metrics-requiredMetricName",
"responses": {"200": {
"description": "OK",
"content": {"*/*": {"schema": {"type": "object"}}}
},
"/actuator": {"get": {
"summary": "Actuator root web endpoint",
- "operationId": "links_1",
+ "operationId": "links",
"responses": {"200": {
"description": "OK",
"content": {"*/*": {"schema": {
"/actuator/loggers/{name}": {
"post": {
"summary": "Actuator web endpoint 'loggers-name'",
- "operationId": "loggers-name_3",
+ "operationId": "loggers-name",
"responses": {"200": {
"description": "OK",
"content": {"*/*": {"schema": {"type": "object"}}}
},
"get": {
"summary": "Actuator web endpoint 'loggers-name'",
- "operationId": "loggers-name_4",
+ "operationId": "loggers-name_2",
"responses": {"200": {
"description": "OK",
"content": {"*/*": {"schema": {"type": "object"}}}
}},
"/actuator/metrics": {"get": {
"summary": "Actuator web endpoint 'metrics'",
- "operationId": "metrics_2",
+ "operationId": "metrics",
"responses": {"200": {
"description": "OK",
"content": {"*/*": {"schema": {"type": "object"}}}
},
"/actuator/info": {"get": {
"summary": "Actuator web endpoint 'info'",
- "operationId": "info_2",
+ "operationId": "info",
"responses": {"200": {
"description": "OK",
"content": {"*/*": {"schema": {"type": "object"}}}
}},
"/actuator/logfile": {"get": {
"summary": "Actuator web endpoint 'logfile'",
- "operationId": "logfile_2",
+ "operationId": "logfile",
"responses": {"200": {
"description": "OK",
"content": {"*/*": {"schema": {"type": "object"}}}
}},
"/actuator/health": {"get": {
"summary": "Actuator web endpoint 'health'",
- "operationId": "health_2",
+ "operationId": "health",
"responses": {"200": {
"description": "OK",
"content": {"*/*": {"schema": {"type": "object"}}}
}],
"tags": ["Service Registry and Supervision"]
}},
+ "/actuator/heapdump": {"get": {
+ "summary": "Actuator web endpoint 'heapdump'",
+ "operationId": "heapdump",
+ "responses": {"200": {
+ "description": "OK",
+ "content": {"*/*": {"schema": {"type": "object"}}}
+ }},
+ "tags": ["Actuator"]
+ }},
"/a1-policy/v2/policies/{policy_id}/status": {"get": {
"summary": "Returns a policy status",
"operationId": "getPolicyStatus",
"required": true
}],
"tags": ["A1 Policy Management"]
- }},
- "/actuator/heapdump": {"get": {
- "summary": "Actuator web endpoint 'heapdump'",
- "operationId": "heapdump_2",
- "responses": {"200": {
- "description": "OK",
- "content": {"*/*": {"schema": {"type": "object"}}}
- }},
- "tags": ["Actuator"]
}}
},
"info": {
{"name": "NearRT-RIC Repository"},
{"name": "Callbacks"},
{"name": "Health Check"},
- {"name": "Management of configuration"},
{
"name": "Actuator",
"description": "Monitor and interact",
"description": "Spring Boot Actuator Web API Documentation",
"url": "https://docs.spring.io/spring-boot/docs/current/actuator-api/html/"
}
- }
+ },
+ {"name": "Management of configuration"}
]
}
\ No newline at end of file
- name: NearRT-RIC Repository
- name: Callbacks
- name: Health Check
-- name: Management of configuration
- name: Actuator
description: Monitor and interact
externalDocs:
description: Spring Boot Actuator Web API Documentation
url: https://docs.spring.io/spring-boot/docs/current/actuator-api/html/
+- name: Management of configuration
paths:
/a1-policy/v2/policy-instances:
get:
application/json:
schema:
$ref: '#/components/schemas/error_information'
+ /actuator/threaddump:
+ get:
+ tags:
+ - Actuator
+ summary: Actuator web endpoint 'threaddump'
+ operationId: threaddump_2
+ responses:
+ 200:
+ description: OK
+ content:
+ '*/*':
+ schema:
+ type: object
/a1-policy/v2/status:
get:
tags:
application/json:
schema:
$ref: '#/components/schemas/status_info_v2'
- /actuator/threaddump:
+ /actuator/loggers:
get:
tags:
- Actuator
- summary: Actuator web endpoint 'threaddump'
- operationId: threaddump_4
+ summary: Actuator web endpoint 'loggers'
+ operationId: loggers
+ responses:
+ 200:
+ description: OK
+ content:
+ '*/*':
+ schema:
+ type: object
+ /actuator/health/**:
+ get:
+ tags:
+ - Actuator
+ summary: Actuator web endpoint 'health-path'
+ operationId: health-path
responses:
200:
description: OK
application/json:
schema:
$ref: '#/components/schemas/error_information'
- /actuator/loggers:
- get:
- tags:
- - Actuator
- summary: Actuator web endpoint 'loggers'
- operationId: loggers_2
- responses:
- 200:
- description: OK
- content:
- '*/*':
- schema:
- type: object
- /actuator/health/**:
- get:
- tags:
- - Actuator
- summary: Actuator web endpoint 'health-path'
- operationId: health-path_2
- responses:
- 200:
- description: OK
- content:
- '*/*':
- schema:
- type: object
/a1-policy/v2/policy-types:
get:
tags:
tags:
- Actuator
summary: Actuator web endpoint 'metrics-requiredMetricName'
- operationId: metrics-requiredMetricName_2
+ operationId: metrics-requiredMetricName
parameters:
- name: requiredMetricName
in: path
tags:
- Actuator
summary: Actuator root web endpoint
- operationId: links_1
+ operationId: links
responses:
200:
description: OK
tags:
- Actuator
summary: Actuator web endpoint 'loggers-name'
- operationId: loggers-name_4
+ operationId: loggers-name_2
parameters:
- name: name
in: path
tags:
- Actuator
summary: Actuator web endpoint 'loggers-name'
- operationId: loggers-name_3
+ operationId: loggers-name
parameters:
- name: name
in: path
tags:
- Actuator
summary: Actuator web endpoint 'metrics'
- operationId: metrics_2
+ operationId: metrics
responses:
200:
description: OK
tags:
- Actuator
summary: Actuator web endpoint 'info'
- operationId: info_2
+ operationId: info
responses:
200:
description: OK
tags:
- Actuator
summary: Actuator web endpoint 'logfile'
- operationId: logfile_2
+ operationId: logfile
responses:
200:
description: OK
tags:
- Actuator
summary: Actuator web endpoint 'health'
- operationId: health_2
+ operationId: health
responses:
200:
description: OK
'*/*':
schema:
$ref: '#/components/schemas/error_information'
+ /actuator/heapdump:
+ get:
+ tags:
+ - Actuator
+ summary: Actuator web endpoint 'heapdump'
+ operationId: heapdump
+ responses:
+ 200:
+ description: OK
+ content:
+ '*/*':
+ schema:
+ type: object
/a1-policy/v2/policies/{policy_id}/status:
get:
tags:
application/json:
schema:
$ref: '#/components/schemas/error_information'
- /actuator/heapdump:
- get:
- tags:
- - Actuator
- summary: Actuator web endpoint 'heapdump'
- operationId: heapdump_2
- responses:
- 200:
- description: OK
- content:
- '*/*':
- schema:
- type: object
components:
schemas:
error_information: