support oAuth authentication method 95/51195/3
authorGanesh Chandrasekaran <ganesh.c@samsung.com>
Tue, 12 Jun 2018 09:39:44 +0000 (18:39 +0900)
committerGanesh Chandrasekaran <ganesh.c@samsung.com>
Tue, 12 Jun 2018 10:28:36 +0000 (19:28 +0900)
Issue-ID: CCSDK-298
Change-Id: I16d3e15f0250c78b48886c80d9a4427838ae36b3
Signed-off-by: Ganesh Chandrasekaran <ganesh.c@samsung.com>
restapi-call-node/features/src/main/resources/features.xml
restapi-call-node/provider/pom.xml
restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/Parameters.java
restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java
restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java
restapi-call-node/provider/src/test/resources/test.xml

index da9266f..a764aa4 100644 (file)
@@ -33,6 +33,8 @@
                <feature>spring</feature>
                <feature>spring-dm</feature>
                <bundle>mvn:com.sun.jersey/jersey-client/${jersey.version}</bundle>
+               <bundle>mvn:com.sun.jersey.contribs.jersey-oauth/oauth-signature/${jersey.version}</bundle>
+               <bundle>mvn:com.sun.jersey.contribs.jersey-oauth/oauth-client/${jersey.version}</bundle>
                <bundle>mvn:org.codehaus.jettison/jettison/${jettison.version}</bundle>
                <bundle>mvn:org.onap.ccsdk.sli.plugins/restapi-call-node-provider/${project.version}</bundle>
        </feature>
index 45fbdff..4831356 100755 (executable)
             <artifactId>jersey-client</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
+            <artifactId>oauth-signature</artifactId>
+            <version>${jersey.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
+            <artifactId>oauth-client</artifactId>
+            <version>${jersey.version}</version>
+            <scope>provided</scope>
+        </dependency>
         <dependency>
             <groupId>org.codehaus.jettison</groupId>
             <artifactId>jettison</artifactId>
index 47bb655..3a4bc76 100644 (file)
@@ -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;
 }
index ea2d259..bd2fc82 100644 (file)
@@ -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 {
      *      <tr><td>restapiUrl</td><td>Mandatory</td><td>url to send the request to</td><td>https://sdncodl:8543/restconf/operations/L3VNF-API:create-update-vnf-request</td></tr>
      *      <tr><td>restapiUser</td><td>Optional</td><td>user name to use for http basic authentication</td><td>sdnc_ws</td></tr>
      *      <tr><td>restapiPassword</td><td>Optional</td><td>unencrypted password to use for http basic authentication</td><td>plain_password</td></tr>
+     *      <tr><td>oAuthConsumerKey</td><td>Optional</td><td>Consumer key to use for http oAuth authentication</td><td>plain_key</td></tr>
+     *      <tr><td>oAuthConsumerSecret</td><td>Optional</td><td>Consumer secret to use for http oAuth authentication</td><td>plain_secret</td></tr>
+     *      <tr><td>oAuthSignatureMethod</td><td>Optional</td><td>Consumer method to use for http oAuth authentication</td><td>method</td></tr>
+     *      <tr><td>oAuthVersion</td><td>Optional</td><td>Version http oAuth authentication</td><td>version</td></tr>
      *      <tr><td>contentType</td><td>Optional</td><td>http content type to set in the http header</td><td>usually application/json or application/xml</td></tr>
      *      <tr><td>format</td><td>Optional</td><td>should match request body format</td><td>json or xml</td></tr>
      *      <tr><td>httpMethod</td><td>Optional</td><td>http method to use when sending the request</td><td>get post put delete patch</td></tr>
@@ -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:");
index 4809ca7..88a1eea 100644 (file)
@@ -417,4 +417,22 @@ public class TestRestapiCallNode {
         RestapiCallNode rcn = new RestapiCallNode();
         rcn.sendRequest(p, ctx);
     }
+
+    @Test
+    public void testDeleteOAuthType() throws SvcLogicException {
+        SvcLogicContext ctx = new SvcLogicContext();
+
+        Map<String, String> p = new HashMap<String, String>();
+        p.put("restapiUrl", "https://echo.getpostman.com/delete");
+        p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
+        p.put("oAuthConsumerSecret", "secret");
+        p.put("oAuthSignatureMethod", "plainTEXT");
+        p.put("oAuthVersion", "1.0");
+        p.put("httpMethod", "delete");
+        p.put("format", "none");
+        p.put("skipSending", "true");
+
+        RestapiCallNode rcn = new RestapiCallNode();
+        rcn.sendRequest(p, ctx);
+    }
 }
index b60b535..1974f68 100644 (file)
             <artifactId>jersey-client</artifactId>
             <version>1.17</version>
         </dependency>
+        <dependency>
+            <groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
+            <artifactId>oauth-signature</artifactId>
+            <version>1.17</version>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.jersey.contribs.jersey-oauth</groupId>
+            <artifactId>oauth-client</artifactId>
+            <version>1.17</version>
+        </dependency>
         <dependency>
             <groupId>commons-codec</groupId>
             <artifactId>commons-codec</artifactId>