X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=datafilecollector%2Fsrc%2Fmain%2Fjava%2Forg%2Foran%2Fdatafile%2Fhttp%2FDfcHttpClient.java;h=f9411551250740560f0b21fe0d507ea5d497dc9d;hb=f0eefdccb07052ec048b8f6316b5952e92939f47;hp=0b44dc90088d6ce04c27c8cdfef5ec31b44fd0be;hpb=f0af18429aec79a590835103fedd753ee5ea93a9;p=nonrtric%2Fplt%2Franpm.git diff --git a/datafilecollector/src/main/java/org/oran/datafile/http/DfcHttpClient.java b/datafilecollector/src/main/java/org/oran/datafile/http/DfcHttpClient.java index 0b44dc9..f941155 100644 --- a/datafilecollector/src/main/java/org/oran/datafile/http/DfcHttpClient.java +++ b/datafilecollector/src/main/java/org/oran/datafile/http/DfcHttpClient.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START====================================================================== * Copyright (C) 2020-2021 Nokia. All rights reserved. + * Copyright (C) 2023 Nordix Foundation. * =============================================================================================== * 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 @@ -24,10 +25,10 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import org.oran.datafile.commons.FileCollectClient; -import org.oran.datafile.commons.FileServerData; import org.oran.datafile.exceptions.DatafileTaskException; import org.oran.datafile.exceptions.NonRetryableDatafileTaskException; -import org.oran.datafile.service.HttpUtils; +import org.oran.datafile.model.FileServerData; +import org.oran.datafile.oauth2.SecurityContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,31 +54,27 @@ public class DfcHttpClient implements FileCollectClient { private Disposable disposableClient; protected HttpClient client; + private final SecurityContext securityContext; - public DfcHttpClient(FileServerData fileServerData) { + public DfcHttpClient(SecurityContext securityContext, FileServerData fileServerData) { this.fileServerData = fileServerData; + this.securityContext = securityContext; } @Override public void open() throws DatafileTaskException { logger.trace("Setting httpClient for file download."); - String authorizationContent = getAuthorizationContent(); - this.client = - HttpClient.create(pool).keepAlive(true).headers(h -> h.add("Authorization", authorizationContent)); - - logger.trace("httpClient, auth header was set."); - } - - protected String getAuthorizationContent() throws DatafileTaskException { - String jwtToken = HttpUtils.getJWTToken(fileServerData); - if (!jwtToken.isEmpty()) { - return HttpUtils.jwtAuthContent(jwtToken); - } - if (!HttpUtils.isBasicAuthDataFilled(fileServerData)) { - throw new DatafileTaskException("Not sufficient basic auth data for file."); + final String authorizationContent = this.securityContext.getBearerAuthToken(); + this.client = HttpClient.create(pool).keepAlive(true); + if (!authorizationContent.isEmpty()) { + this.client = this.client.headers(h -> h.add("Authorization", "Bearer " + authorizationContent)); + logger.trace("httpClient, auth header was set."); + } else if (!this.fileServerData.password.isEmpty()) { + String basicAuthContent = + HttpUtils.basicAuthContent(this.fileServerData.userId, this.fileServerData.password); + this.client = this.client.headers(h -> h.add("Authorization", basicAuthContent)); } - return HttpUtils.basicAuthContent(this.fileServerData.userId, this.fileServerData.password); } @Override