summaryrefslogtreecommitdiffstats
path: root/auth
diff options
context:
space:
mode:
authorInstrumental <jonathan.gathman@att.com>2018-07-22 07:49:16 -0500
committerInstrumental <jonathan.gathman@att.com>2018-07-22 07:49:20 -0500
commitcf52d77279f8d5a70429d45abad0ef3d1135070c (patch)
treef084fd660d3e201abc853df8f17542a044120070 /auth
parent65c40b3bffb78a1a77d82fc74bbf633a6d0d906f (diff)
Finish RESTful Client API
Issue-ID: AAF-361 Change-Id: I999cb419a79c5995baf3757fdbbe047528901597 Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'auth')
-rw-r--r--auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/HMangrStub.java4
-rw-r--r--auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Create.java8
-rw-r--r--auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Delete.java10
-rw-r--r--auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Describe.java8
-rw-r--r--auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Grant.java8
-rw-r--r--auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/API_Hello.java81
6 files changed, 95 insertions, 24 deletions
diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/HMangrStub.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/HMangrStub.java
index 7ceb1233..c1b87540 100644
--- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/HMangrStub.java
+++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/HMangrStub.java
@@ -49,6 +49,10 @@ public class HMangrStub extends HMangr {
return null;
}
@Override public<RET> RET oneOf(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable, boolean notify, String host) {
+ try {
+ return retryable.code(clientMock);
+ } catch (Exception e) {
+ }
return null;
}
}
diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Create.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Create.java
index 1fb27470..41295c79 100644
--- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Create.java
+++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Create.java
@@ -60,7 +60,7 @@ public class JU_Create {
@Mock private Locator<URI> locMock;
@Mock private Writer wrtMock;
@Mock private Rcli<HttpURLConnection> clientMock;
- @Mock private Future<Object> futureMock;
+ @Mock private Future<String> futureMock;
private static Create create;
@@ -74,9 +74,9 @@ public class JU_Create {
public void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException {
MockitoAnnotations.initMocks(this);
- when(clientMock.create(any(), any(), any())).thenReturn(futureMock);
- when(clientMock.delete(any(), any(), any())).thenReturn(futureMock);
- when(clientMock.update(any(), any(), any())).thenReturn(futureMock);
+ when(clientMock.create(any(), any(), any(String.class))).thenReturn(futureMock);
+ when(clientMock.delete(any(), any(), any(String.class))).thenReturn(futureMock);
+ when(clientMock.update(any(), any(), any(String.class))).thenReturn(futureMock);
hman = new HMangrStub(access, locMock, clientMock);
access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Delete.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Delete.java
index 4fd7892a..19cacedb 100644
--- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Delete.java
+++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Delete.java
@@ -24,7 +24,7 @@ package org.onap.aaf.auth.cmd.test.perm;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
-
+import org.hamcrest.core.AnyOf;
import org.junit.Before;
import org.onap.aaf.auth.cmd.test.HMangrStub;
@@ -62,7 +62,7 @@ public class JU_Delete {
@Mock private Locator<URI> locMock;
@Mock private Writer wrtMock;
@Mock private Rcli<HttpURLConnection> clientMock;
- @Mock private Future<Object> futureMock;
+ @Mock private Future<String> futureMock;
private static Delete del;
@@ -75,9 +75,9 @@ public class JU_Delete {
public void setUp() throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException {
MockitoAnnotations.initMocks(this);
- when(clientMock.create(any(), any(), any())).thenReturn(futureMock);
- when(clientMock.delete(any(), any(), any())).thenReturn(futureMock);
- when(clientMock.update(any(), any(), any())).thenReturn(futureMock);
+ when(clientMock.create(any(), any(), any(String.class))).thenReturn(futureMock);
+ when(clientMock.delete(any(), any(), any(String.class))).thenReturn(futureMock);
+ when(clientMock.update(any(), any(), any(String.class))).thenReturn(futureMock);
hman = new HMangrStub(access, locMock, clientMock);
access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Describe.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Describe.java
index 224b5c75..9a5fc734 100644
--- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Describe.java
+++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Describe.java
@@ -61,7 +61,7 @@ public class JU_Describe {
@Mock private Locator<URI> locMock;
@Mock private Writer wrtMock;
@Mock private Rcli<HttpURLConnection> clientMock;
- @Mock private Future<Object> futureMock;
+ @Mock private Future<String> futureMock;
private PropAccess access;
private HMangrStub hman;
@@ -74,9 +74,9 @@ public class JU_Describe {
public void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException {
MockitoAnnotations.initMocks(this);
- when(clientMock.create(any(), any(), any())).thenReturn(futureMock);
- when(clientMock.delete(any(), any(), any())).thenReturn(futureMock);
- when(clientMock.update(any(), any(), any())).thenReturn(futureMock);
+ when(clientMock.create(any(), any(), any(String.class))).thenReturn(futureMock);
+ when(clientMock.delete(any(), any(), any(String.class))).thenReturn(futureMock);
+ when(clientMock.update(any(), any(), any(String.class))).thenReturn(futureMock);
hman = new HMangrStub(access, locMock, clientMock);
access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Grant.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Grant.java
index 17280c64..975b83d2 100644
--- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Grant.java
+++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Grant.java
@@ -63,7 +63,7 @@ public class JU_Grant {
@Mock private Locator<URI> locMock;
@Mock private Writer wrtMock;
@Mock private Rcli<HttpURLConnection> clientMock;
- @Mock private Future<Object> futureMock;
+ @Mock private Future<String> futureMock;
private PropAccess access;
private HMangrStub hman;
@@ -74,9 +74,9 @@ public class JU_Grant {
public void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException {
MockitoAnnotations.initMocks(this);
- when(clientMock.create(any(), any(), any())).thenReturn(futureMock);
- when(clientMock.delete(any(), any(), any())).thenReturn(futureMock);
- when(clientMock.update(any(), any(), any())).thenReturn(futureMock);
+ when(clientMock.create(any(), any(), any(String.class))).thenReturn(futureMock);
+ when(clientMock.delete(any(), any(), any(String.class))).thenReturn(futureMock);
+ when(clientMock.update(any(), any(), any(String.class))).thenReturn(futureMock);
hman = new HMangrStub(access, locMock, clientMock);
access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
diff --git a/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/API_Hello.java b/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/API_Hello.java
index 2be162cc..030073a7 100644
--- a/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/API_Hello.java
+++ b/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/API_Hello.java
@@ -21,6 +21,9 @@
package org.onap.aaf.auth.hello;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -40,6 +43,9 @@ import org.onap.aaf.misc.env.TimeTaken;
public class API_Hello {
+ private static final String APPLICATION_JSON = "application/json";
+ protected static final byte[] NOT_JSON = "Data does not look like JSON".getBytes();
+
// Hide Public Constructor
private API_Hello() {}
@@ -85,10 +91,37 @@ public class API_Hello {
}
});
- ////////
- // REST APIs
- ///////
- oauthHello.route(oauthHello.env,HttpMethods.GET,"/resthello/:perm*",new HttpCode<AuthzTrans, AAF_Hello>(oauthHello,"REST Hello OAuth") {
+////////////////
+// REST APIs
+////////////////
+
+ ////////////////
+ // CREATE/POST
+ ////////////////
+ oauthHello.route(oauthHello.env,HttpMethods.POST,"/resthello/:id",new HttpCode<AuthzTrans, AAF_Hello>(oauthHello,"REST Hello Create") {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream()));
+ StringBuilder sb = new StringBuilder();
+ while(br.ready()) {
+ sb.append(br.readLine());
+ }
+ String content = sb.toString();
+ trans.info().printf("Content from %s: %s\n", pathParam(req, ":id"),content);
+ if(content.startsWith("{") && content.endsWith("}")) {
+ resp.setStatus(201 /* OK */);
+ } else {
+ resp.getOutputStream().write(NOT_JSON);
+ resp.setStatus(406);
+ }
+ }
+ },APPLICATION_JSON);
+
+
+ ////////////////
+ // READ/GET
+ ////////////////
+ oauthHello.route(oauthHello.env,HttpMethods.GET,"/resthello/:id/:perm*",new HttpCode<AuthzTrans, AAF_Hello>(oauthHello,"REST Hello Read") {
@Override
public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
resp.setStatus(200 /* OK */);
@@ -96,6 +129,7 @@ public class API_Hello {
sb.append(req.getUserPrincipal().getName());
sb.append('"');
String perm = pathParam(req, "perm");
+ trans.info().printf("Read request from %s: %s\n", pathParam(req, ":id"),perm);
if(perm!=null && perm.length()>0) {
TimeTaken tt = trans.start("Authorize perm", Env.REMOTE);
try {
@@ -113,9 +147,42 @@ public class API_Hello {
os.println(sb.toString());
trans.info().printf("Said 'RESTful Hello' to %s, Authentication type: %s",trans.getUserPrincipal().getName(),trans.getUserPrincipal().getClass().getSimpleName());
}
- },"application/json");
-
-
+ },APPLICATION_JSON);
+ ////////////////
+ // UPDATE/PUT
+ ////////////////
+ oauthHello.route(oauthHello.env,HttpMethods.PUT,"/resthello/:id",new HttpCode<AuthzTrans, AAF_Hello>(oauthHello,"REST Hello Update") {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream()));
+ StringBuilder sb = new StringBuilder();
+ while(br.ready()) {
+ sb.append(br.readLine());
+ }
+ String content = sb.toString();
+ trans.info().printf("Content from %s: %s\n", pathParam(req, ":id"),content);
+ if(content.startsWith("{") && content.endsWith("}")) {
+ resp.setStatus(200 /* OK */);
+ resp.getOutputStream().print(content);
+ } else {
+ resp.getOutputStream().write(NOT_JSON);
+ resp.setStatus(406);
+ }
+ }
+ },APPLICATION_JSON);
+
+
+ ////////////////
+ // DELETE
+ ////////////////
+ oauthHello.route(oauthHello.env,HttpMethods.DELETE,"/resthello/:id",new HttpCode<AuthzTrans, AAF_Hello>(oauthHello,"REST Hello Delete") {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ trans.info().printf("Delete requested on %s\n", pathParam(req, ":id"));
+ resp.setStatus(200 /* OK */);
+ }
+ },APPLICATION_JSON);
+
}
}