From 600aab4f869d5b632f055dce5cb910ce1d5a348e Mon Sep 17 00:00:00 2001 From: Ganesh Chandrasekaran Date: Tue, 12 Jun 2018 18:39:44 +0900 Subject: support oAuth authentication method Issue-ID: CCSDK-298 Change-Id: I16d3e15f0250c78b48886c80d9a4427838ae36b3 Signed-off-by: Ganesh Chandrasekaran --- .../ccsdk/sli/plugins/restapicall/Parameters.java | 4 ++++ .../sli/plugins/restapicall/RestapiCallNode.java | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'restapi-call-node/provider/src/main/java') diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/Parameters.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/Parameters.java index 47bb655f..3a4bc76c 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/Parameters.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/Parameters.java @@ -44,4 +44,8 @@ public class Parameters { public String partner; public Boolean dumpHeaders; public String requestBody; + public String oAuthConsumerKey; + public String oAuthConsumerSecret; + public String oAuthSignatureMethod; + public String oAuthVersion; } diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java index ea2d259b..bd2fc826 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java @@ -62,6 +62,9 @@ import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import com.sun.jersey.oauth.client.OAuthClientFilter; +import com.sun.jersey.oauth.signature.OAuthParameters; +import com.sun.jersey.oauth.signature.OAuthSecrets; import com.sun.jersey.client.urlconnection.HTTPSProperties; public class RestapiCallNode implements SvcLogicJavaPlugin { @@ -94,6 +97,10 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { * restapiUrlMandatoryurl to send the request tohttps://sdncodl:8543/restconf/operations/L3VNF-API:create-update-vnf-request * restapiUserOptionaluser name to use for http basic authenticationsdnc_ws * restapiPasswordOptionalunencrypted password to use for http basic authenticationplain_password + * oAuthConsumerKeyOptionalConsumer key to use for http oAuth authenticationplain_key + * oAuthConsumerSecretOptionalConsumer secret to use for http oAuth authenticationplain_secret + * oAuthSignatureMethodOptionalConsumer method to use for http oAuth authenticationmethod + * oAuthVersionOptionalVersion http oAuth authenticationversion * contentTypeOptionalhttp content type to set in the http headerusually application/json or application/xml * formatOptionalshould match request body formatjson or xml * httpMethodOptionalhttp method to use when sending the requestget post put delete patch @@ -216,6 +223,10 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { validateUrl(p.restapiUrl); p.restapiUser = parseParam(paramMap, "restapiUser", false, null); p.restapiPassword = parseParam(paramMap, "restapiPassword", false, null); + p.oAuthConsumerKey = parseParam(paramMap, "oAuthConsumerKey", false, null); + p.oAuthConsumerSecret = parseParam(paramMap, "oAuthConsumerSecret", false, null); + p.oAuthSignatureMethod = parseParam(paramMap, "oAuthSignatureMethod", false, null); + p.oAuthVersion = parseParam(paramMap, "oAuthVersion", false, null); p.contentType = parseParam(paramMap, "contentType", false, null); p.format = Format.fromString(parseParam(paramMap, "format", false, "json")); p.httpMethod = HttpMethod.fromString(parseParam(paramMap, "httpMethod", false, "post")); @@ -439,6 +450,17 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { client.setConnectTimeout(5000); if (p.restapiUser != null && p.restapiPassword != null) client.addFilter(new HTTPBasicAuthFilter(p.restapiUser, p.restapiPassword)); + else if(p.oAuthConsumerKey != null && p.oAuthConsumerSecret != null && p.oAuthSignatureMethod != null && p.oAuthVersion != null) + { + OAuthParameters params = new OAuthParameters() + .signatureMethod(p.oAuthSignatureMethod) + .consumerKey(p.oAuthConsumerKey) + .version(p.oAuthVersion); + + OAuthSecrets secrets = new OAuthSecrets() + .consumerSecret(p.oAuthConsumerSecret); + client.addFilter(new OAuthClientFilter(client.getProviders(), params, secrets)); + } WebResource webResource = client.resource(p.restapiUrl); log.info("Sending request:"); -- cgit 1.2.3-korg