From 19afb93b23f264471c6e8db77b54e9a301a3114b Mon Sep 17 00:00:00 2001 From: Instrumental Date: Thu, 21 Jun 2018 15:08:47 -0500 Subject: Update REST Samples for required behavior Issue-ID: AAF-361 Change-Id: Ia6dabfa3eeec2253c3f017ddc2d70afe4afbd54b Signed-off-by: Instrumental --- .../java/org/onap/aaf/auth/hello/API_Hello.java | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'auth/auth-hello/src/main/java/org') 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(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(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"); + + + } } -- cgit 1.2.3-korg