X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-gui%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fgui%2Fpages%2FRoleDetailAction.java;h=745263610bc8a6db4f7a529b40172409cd322fe0;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=f2d2c01fec97090207b24ad79654948f92b29057;hpb=71037c39a37d3549dcfe31926832a657744fbe05;p=aaf%2Fauthz.git diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/RoleDetailAction.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/RoleDetailAction.java index f2d2c01f..74526361 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/RoleDetailAction.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/RoleDetailAction.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -54,135 +54,135 @@ import aaf.v2_0.RolePermRequest; import aaf.v2_0.RoleRequest; public class RoleDetailAction extends Page { - public RoleDetailAction(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException { - super(gui.env,RoleDetail.NAME, RoleDetail.HREF, TableData.headers, - new BreadCrumbs(breadcrumbs), - new NamedCode(true,"content") { - final Slot sReq = gui.env.slot(AAF_GUI.HTTP_SERVLET_REQUEST); - - @Override - public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { - cache.dynamic(hgen, new DynamicCode() { - @Override - public void code(final AAF_GUI gui, final AuthzTrans trans,final Cache cache, final HTMLGen hgen) throws APIException, IOException { - final HttpServletRequest req = trans.get(sReq, null); - final String role = getSingleParam(req,"role"); - if(role==null) { - hgen.text("Parameter 'role' is required").end(); - } else { - // Run Validations -// boolean fail; - try { - /*fail =*/ gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { - @Override - public Boolean code(Rcli client) throws CadiException, ConnectException, APIException { - List ltf = new ArrayList(); - String text; - Map pm = (Map)req.getParameterMap(); - for(final Entry es : pm.entrySet()) { - for(final String v : es.getValue()) { - TimeTaken tt = null; - try { - switch(es.getKey()) { - case "desc": // Check box set - String desc = getSingleParam(req, "description"); - if(desc!=null) { - text = "Setting Description on " + role + " to " + desc; - tt = trans.start(text, Env.REMOTE); - RoleRequest rr = new RoleRequest(); - rr.setName(role); - rr.setDescription(desc); - ltf.add(new TypedFuture(ActionType.desc, text, - client.update("/authz/role", - gui.getDF(RoleRequest.class),rr - ))); - } - break; - case "perm.ungrant": - text = "Ungranting Permission '" + v + "' from '" + role + '\''; - tt = trans.start(text, Env.REMOTE); - String[] pf = Split.splitTrim('|', v); - if(pf.length==3) { - Pkey perm = new Pkey(); - perm.setType(pf[0]); - perm.setInstance(pf[1]); - perm.setAction(pf[2]); - RolePermRequest rpr = new RolePermRequest(); - rpr.setPerm(perm); - rpr.setRole(role); - ltf.add(new TypedFuture(ActionType.ungrant,text, - client.delete("/authz/role/" + role + "/perm", - gui.getDF(RolePermRequest.class),rpr - ))); - } else { - hgen.p(v + " is not a valid Perm for ungranting"); - } - break; - case "userrole.extend": - text = "Extending " + v + " in " + role; - tt = trans.start(text, Env.REMOTE); - ltf.add(new TypedFuture(ActionType.extendUR,text, - client.update("/authz/userRole/extend/" + v + '/' + role))); - break; - case "userrole.delete": - text = "Deleting " + v + " from " + role; - tt = trans.start(text, Env.REMOTE); - ltf.add(new TypedFuture(ActionType.deleteUR,text, - client.delete("/authz/userRole/" + v + '/' + role, Void.class))); - break; + public RoleDetailAction(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,RoleDetail.NAME, RoleDetail.HREF, TableData.headers, + new BreadCrumbs(breadcrumbs), + new NamedCode(true,"content") { + final Slot sReq = gui.env.slot(AAF_GUI.HTTP_SERVLET_REQUEST); + + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(final AAF_GUI gui, final AuthzTrans trans,final Cache cache, final HTMLGen hgen) throws APIException, IOException { + final HttpServletRequest req = trans.get(sReq, null); + final String role = getSingleParam(req,"role"); + if (role==null) { + hgen.text("Parameter 'role' is required").end(); + } else { + // Run Validations +// boolean fail; + try { + /*fail =*/ gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Boolean code(Rcli client) throws CadiException, ConnectException, APIException { + List ltf = new ArrayList<>(); + String text; + Map pm = (Map)req.getParameterMap(); + for (final Entry es : pm.entrySet()) { + for (final String v : es.getValue()) { + TimeTaken tt = null; + try { + switch(es.getKey()) { + case "desc": // Check box set + String desc = getSingleParam(req, "description"); + if (desc!=null) { + text = "Setting Description on " + role + " to " + desc; + tt = trans.start(text, Env.REMOTE); + RoleRequest rr = new RoleRequest(); + rr.setName(role); + rr.setDescription(desc); + ltf.add(new TypedFuture(ActionType.desc, text, + client.update("/authz/role", + gui.getDF(RoleRequest.class),rr + ))); + } + break; + case "perm.ungrant": + text = "Ungranting Permission '" + v + "' from '" + role + '\''; + tt = trans.start(text, Env.REMOTE); + String[] pf = Split.splitTrim('|', v); + if (pf.length==3) { + Pkey perm = new Pkey(); + perm.setType(pf[0]); + perm.setInstance(pf[1]); + perm.setAction(pf[2]); + RolePermRequest rpr = new RolePermRequest(); + rpr.setPerm(perm); + rpr.setRole(role); + ltf.add(new TypedFuture(ActionType.ungrant,text, + client.delete("/authz/role/" + role + "/perm", + gui.getDF(RolePermRequest.class),rpr + ))); + } else { + hgen.p(v + " is not a valid Perm for ungranting"); + } + break; + case "userrole.extend": + text = "Extending " + v + " in " + role; + tt = trans.start(text, Env.REMOTE); + ltf.add(new TypedFuture(ActionType.extendUR,text, + client.update("/authz/userRole/extend/" + v + '/' + role))); + break; + case "userrole.delete": + text = "Deleting " + v + " from " + role; + tt = trans.start(text, Env.REMOTE); + ltf.add(new TypedFuture(ActionType.deleteUR,text, + client.delete("/authz/userRole/" + v + '/' + role, Void.class))); + break; + + default: +// System.out.println(es.getKey() + "=" + v); + } + } finally { + if (tt!=null) { + tt.done(); + tt=null; + } + } + } + } + + if (ltf.isEmpty()) { + hgen.p("No Changes"); + } else { + for (TypedFuture tf : ltf) { + if (tf.future.get(5000)) { + hgen.p("Success: " + tf.text); + } else { + // Note: if handling of special Error codes is required, use + // switch(tf.type) { + // } + hgen.p(tf.text); + gui.writeError(trans, tf.future, hgen,4); + } + } + } + return true; + } + }); + } catch (Exception e) { + hgen.p("Unknown Error"); + e.printStackTrace(); + } + } + } + + }); + } + }); + } - default: -// System.out.println(es.getKey() + "=" + v); - } - } finally { - if(tt!=null) { - tt.done(); - tt=null; - } - } - } - } - - if(ltf.isEmpty()) { - hgen.p("No Changes"); - } else { - for(TypedFuture tf : ltf) { - if(tf.future.get(5000)) { - hgen.p("Success: " + tf.text); - } else { - // Note: if handling of special Error codes is required, use - // switch(tf.type) { - // } - hgen.p(tf.text); - gui.writeError(trans, tf.future, hgen,4); - } - } - } - return true; - } - }); - } catch (Exception e) { - hgen.p("Unknown Error"); - e.printStackTrace(); - } - } - } + enum ActionType {desc, ungrant, deleteUR, extendUR}; + private static class TypedFuture { +// public final ActionType type; + public final Future future; + public final String text; - }); - } - }); - } - - enum ActionType {desc, ungrant, deleteUR, extendUR}; - private static class TypedFuture { -// public final ActionType type; - public final Future future; - public final String text; - - public TypedFuture(ActionType type, String text, Future future) { -// this.type = type; - this.future = future; - this.text = text; - } - } + public TypedFuture(ActionType type, String text, Future future) { +// this.type = type; + this.future = future; + this.text = text; + } + } }