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=69316aa635c8f28557a38aab90e3362295d0725f;hp=7c1ae929d3a5bd332b98097a9f7bed20f6130fe2;hpb=7ba76d4f4c0f92c874686d60abd12ef0322f01b0;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 7c1ae92..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 @@ -27,6 +28,7 @@ import org.oran.datafile.commons.FileCollectClient; import org.oran.datafile.exceptions.DatafileTaskException; import org.oran.datafile.exceptions.NonRetryableDatafileTaskException; import org.oran.datafile.model.FileServerData; +import org.oran.datafile.oauth2.SecurityContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,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