diff options
author | Instrumental <jonathan.gathman@att.com> | 2018-06-21 15:08:47 -0500 |
---|---|---|
committer | Instrumental <jonathan.gathman@att.com> | 2018-06-21 15:08:54 -0500 |
commit | 19afb93b23f264471c6e8db77b54e9a301a3114b (patch) | |
tree | d791495495ce243ab16333623671166c8c813cee /auth | |
parent | a7024ad2f0df65a2005e29d24a5974304d2b58c6 (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')
4 files changed, 45 insertions, 9 deletions
diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/HttpCode.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/HttpCode.java index 0bfe310a..d209ddcd 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/HttpCode.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/HttpCode.java @@ -78,11 +78,14 @@ public abstract class HttpCode<TRANS extends Trans, CONTEXT> { * @return */ public String pathParam(HttpServletRequest req, String key) { - String rv = match.param(req.getPathInfo(), key); - if(rv!=null) { - rv = rv.trim(); - if(rv.endsWith("/")) { - rv = rv.substring(0, rv.length()-1); + String rv = req.getParameter(key); + if(rv==null) { + rv = match.param(req.getPathInfo(), key); + if(rv!=null) { + rv = rv.trim(); + if(rv.endsWith("/")) { + rv = rv.substring(0, rv.length()-1); + } } } return rv; diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/UserRoleExtend.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/UserRoleExtend.java index c0ba16da..8a78fd74 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/UserRoleExtend.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/UserRoleExtend.java @@ -67,7 +67,7 @@ public class UserRoleExtend extends Page { gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() { @Override public Void code(Rcli<?> client)throws CadiException, ConnectException, APIException { - Future<Void> fv = client.setQueryParams("request=true").update("/authz/userRole/extend/"+user+"/"+role); + Future<Void> fv = client.update("/authz/userRole/extend/"+user+"/"+role+"?request=true"); if(fv.get(5000)) { // not sure if we'll ever hit this hgen.p("Extended User ["+ user+"] in Role [" +role+"]"); diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/UserRoleRemove.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/UserRoleRemove.java index 5f8adf2d..84f3640d 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/UserRoleRemove.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/UserRoleRemove.java @@ -67,8 +67,8 @@ public class UserRoleRemove extends Page { gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() { @Override public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException { - Future<Void> fv = client.setQueryParams("request=true").delete( - "/authz/userRole/"+user+"/"+role,Void.class); + Future<Void> fv = client.delete( + "/authz/userRole/"+user+"/"+role+"?request=true",Void.class); if(fv.get(5000)) { // not sure if we'll ever hit this 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"); + + + } } |