summaryrefslogtreecommitdiffstats
path: root/auth/auth-hello/src/main
diff options
context:
space:
mode:
authorInstrumental <jonathan.gathman@att.com>2018-06-21 15:08:47 -0500
committerInstrumental <jonathan.gathman@att.com>2018-06-21 15:08:54 -0500
commit19afb93b23f264471c6e8db77b54e9a301a3114b (patch)
treed791495495ce243ab16333623671166c8c813cee /auth/auth-hello/src/main
parenta7024ad2f0df65a2005e29d24a5974304d2b58c6 (diff)
Update REST Samples for required behavior
Issue-ID: AAF-361 Change-Id: Ia6dabfa3eeec2253c3f017ddc2d70afe4afbd54b Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'auth/auth-hello/src/main')
-rw-r--r--auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/API_Hello.java35
1 files changed, 34 insertions, 1 deletions
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 e2252236..2be162cc 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
@@ -52,8 +52,9 @@ public class API_Hello {
*/
public static void init(final AAF_Hello oauthHello) throws Exception {
////////
- // Overall APIs
+ // Simple "GET" API
///////
+
oauthHello.route(HttpMethods.GET,"/hello/:perm*",API.TOKEN,new HttpCode<AuthzTrans, AAF_Hello>(oauthHello,"Hello OAuth"){
@Override
public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
@@ -84,5 +85,37 @@ public class API_Hello {
}
});
+ ////////
+ // REST APIs
+ ///////
+ oauthHello.route(oauthHello.env,HttpMethods.GET,"/resthello/:perm*",new HttpCode<AuthzTrans, AAF_Hello>(oauthHello,"REST Hello OAuth") {
+ @Override
+ public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
+ resp.setStatus(200 /* OK */);
+ StringBuilder sb = new StringBuilder("{\"resp\": \"Hello REST AAF\",\"principal\": \"");
+ sb.append(req.getUserPrincipal().getName());
+ sb.append('"');
+ String perm = pathParam(req, "perm");
+ if(perm!=null && perm.length()>0) {
+ TimeTaken tt = trans.start("Authorize perm", Env.REMOTE);
+ try {
+ sb.append(",\"validation\": { \"permission\" : \"");
+ sb.append(perm);
+ sb.append("\",\"has\" : \"");
+ sb.append(req.isUserInRole(perm));
+ sb.append("\"}");
+ } finally {
+ tt.done();
+ }
+ }
+ sb.append("}");
+ ServletOutputStream os = resp.getOutputStream();
+ os.println(sb.toString());
+ trans.info().printf("Said 'RESTful Hello' to %s, Authentication type: %s",trans.getUserPrincipal().getName(),trans.getUserPrincipal().getClass().getSimpleName());
+ }
+ },"application/json");
+
+
+
}
}