aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java
diff options
context:
space:
mode:
authorSylvain Desbureaux <sylvain.desbureaux@orange.com>2020-04-03 11:51:58 +0200
committerSylvain Desbureaux <sylvain.desbureaux@orange.com>2020-04-03 17:22:22 +0200
commit2c41d11de03c07739ae395683c9d834ab282821c (patch)
treea2259956aa2fc83af2c2c6df50dacb89f1aee563 /sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java
parent0aae60b7882b816a6a7e32d4a91339935d61ff6b (diff)
Allow SDC client to connect to SDC in HTTP
I've added a toggle which allow to connect to SDC using HTTP and not only HTTPS. By default, we're still on HTTPS. Issue-ID: SDC-2721 Signed-off-by: Sylvain Desbureaux <sylvain.desbureaux@orange.com> Change-Id: I48046c19aed7d81f9e03a30b3b081b9d8dd1495e
Diffstat (limited to 'sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java')
-rw-r--r--sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java31
1 files changed, 24 insertions, 7 deletions
diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java b/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java
index 7871816..44f1295 100644
--- a/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java
+++ b/sdc-distribution-client/src/main/java/org/onap/sdc/http/HttpAsdcClient.java
@@ -70,18 +70,28 @@ public class HttpAsdcClient implements IHttpAsdcClient {
private static final String TLS = "TLSv1.2";
private static final String AUTHORIZATION_HEADER = "Authorization";
private static final String HTTPS = "https://";
+ private static final String HTTP = "http://";
public static final int AUTHORIZATION_SCOPE_PORT = 443;
+ public static final int AUTHORIZATION_SCOPE_PLAIN_PORT = 80;
private static Logger log = LoggerFactory.getLogger(HttpAsdcClient.class.getName());
private CloseableHttpClient httpClient = null;
private String serverFqdn = null;
private String authHeaderValue = "";
+ private Boolean use_ssl = true;
- public HttpAsdcClient(IConfiguration configuraion) {
- this.serverFqdn = configuraion.getAsdcAddress();
+ public HttpAsdcClient(IConfiguration configuration) {
+ this.serverFqdn = configuration.getAsdcAddress();
- String username = configuraion.getUser();
- String password = configuraion.getPassword();
- initSSL(username, password, configuraion.getKeyStorePath(), configuraion.getKeyStorePassword(), configuraion.activateServerTLSAuth());
+ String username = configuration.getUser();
+ String password = configuration.getPassword();
+ this.use_ssl = configuration.isUseHttpsWithSDC();
+ if (this.use_ssl) {
+ initSSL(username, password, configuration.getKeyStorePath(), configuration.getKeyStorePassword(), configuration.activateServerTLSAuth());
+ } else {
+ CredentialsProvider credsProvider = new BasicCredentialsProvider();
+ credsProvider.setCredentials(new AuthScope("localhost", AUTHORIZATION_SCOPE_PLAIN_PORT), new UsernamePasswordCredentials(username, password));
+ httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
+ }
String userNameAndPassword = username + ":" + password;
this.authHeaderValue = "Basic " + Base64.getEncoder().encodeToString(userNameAndPassword.getBytes());
@@ -217,7 +227,7 @@ public class HttpAsdcClient implements IHttpAsdcClient {
Pair<HttpAsdcResponse, CloseableHttpResponse> ret;
CloseableHttpResponse httpResponse = null;
HttpAsdcResponse response = null;
- HttpPost httpPost = new HttpPost(HTTPS + serverFqdn + requestUrl);
+ HttpPost httpPost = new HttpPost(getScheme() + serverFqdn + requestUrl);
List<Header> headers = addHeadersToHttpRequest(headersMap);
for (Header header : headers) {
httpPost.addHeader(header);
@@ -268,7 +278,7 @@ public class HttpAsdcClient implements IHttpAsdcClient {
public Pair<HttpAsdcResponse, CloseableHttpResponse> getRequest(String requestUrl, Map<String, String> headersMap, boolean closeTheRequest) {
Pair<HttpAsdcResponse, CloseableHttpResponse> ret;
CloseableHttpResponse httpResponse = null;
- String url = HTTPS + serverFqdn + requestUrl;
+ String url = getScheme() + serverFqdn + requestUrl;
log.debug("url to send {}", url);
HttpGet httpGet = new HttpGet(url);
List<Header> headers = addHeadersToHttpRequest(headersMap);
@@ -354,4 +364,11 @@ public class HttpAsdcClient implements IHttpAsdcClient {
return requestHeaders;
}
+ private String getScheme() {
+ if (this.use_ssl) {
+ return HTTPS;
+ }
+ return HTTP;
+ }
+
}