X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-cmd%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fcmd%2Fuser%2FRole.java;h=04b444a130ad6e4bd838bbe60c4d32541d6f91d6;hb=4b5a7d721d994a49057e9bfb403c7bff1b376660;hp=70bc16a37af6763234ba2557ed1509a8395ae4c9;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/Role.java b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/Role.java index 70bc16a3..04b444a1 100644 --- a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/Role.java +++ b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/Role.java @@ -41,115 +41,115 @@ import aaf.v2_0.UserRoleRequest; * */ public class Role extends Cmd { - private static final String[] options = {"add", "del", "setTo","extend"}; - public Role(User parent) { - super(parent, "role", new Param(optionsToString(options), true), new Param("user", true), new Param( - "role[,role]* (!REQ S)", false)); - } + private static final String[] options = {"add", "del", "setTo","extend"}; + public Role(User parent) { + super(parent, "role", new Param(optionsToString(options), true), new Param("user", true), new Param( + "role[,role]* (!REQ S)", false)); + } - @Override - public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { - return same(new Retryable() { - @Override - public Integer code(Rcli client) throws CadiException, APIException { - int idx = index; - String key = args[idx++]; - int option = whichOption(options, key); - final String user = fullID(args[idx++]); + @Override + public int _exec(final int index, final String ... args) throws CadiException, APIException, LocatorException { + return same(new Retryable() { + @Override + public Integer code(Rcli client) throws CadiException, APIException { + int idx = index; + String key = args[idx++]; + int option = whichOption(options, key); + final String user = fullID(args[idx++]); - UserRoleRequest urr = new UserRoleRequest(); - urr.setUser(user); - // Set Start/End commands - setStartEnd(urr); + UserRoleRequest urr = new UserRoleRequest(); + urr.setUser(user); + // Set Start/End commands + setStartEnd(urr); - Future fp = null; + Future fp = null; - if (option != 2) { - if (args.length < 5) { - throw new CadiException(build(new StringBuilder("Too few args: "), null).toString()); - } - String[] roles = args[idx++].split(","); - for (String role : roles) { - String verb = null,participle=null; - urr.setRole(role); - // You can request to be added or removed from role. - setQueryParamsOn(client); - switch(option) { - case 0: - fp = client.create("/authz/userRole", getDF(UserRoleRequest.class), urr); - verb = "Added"; - participle = "] to User [" ; - break; - case 1: - fp = client.delete("/authz/userRole/" + urr.getUser() + '/' + urr.getRole(), Void.class); - verb = "Removed"; - participle = "] from User [" ; - break; - case 3: - fp = client.update("/authz/userRole/extend/" + urr.getUser() + '/' + urr.getRole()); - verb = "Extended"; - participle = "] to User [" ; - break; - default: - throw new CadiException("Invalid action [" + key + ']'); - } - if (fp.get(AAFcli.timeout())) { - pw().print(verb); - pw().print(" Role ["); - pw().print(urr.getRole()); - pw().print(participle); - pw().print(urr.getUser()); - pw().println(']'); - } else { - switch(fp.code()) { - case 202: - pw().print("UserRole "); - pw().print(option == 0 ? "Creation" : option==1?"Deletion":"Extension"); - pw().println(" Accepted, but requires Approvals before actualizing"); - break; - case 404: - if(option==3) { - pw().println("Failed with code 404: UserRole is not found, or you do not have permission to view"); - break; - } - default: - error(fp); - } - } - } - } else { - // option 2 is setTo command (an update call) - String allRoles = ""; - if (idx < args.length) - allRoles = args[idx++]; + if (option != 2) { + if (args.length < 5) { + throw new CadiException(build(new StringBuilder("Too few args: "), null).toString()); + } + String[] roles = args[idx++].split(","); + for (String role : roles) { + String verb = null,participle=null; + urr.setRole(role); + // You can request to be added or removed from role. + setQueryParamsOn(client); + switch(option) { + case 0: + fp = client.create("/authz/userRole", getDF(UserRoleRequest.class), urr); + verb = "Added"; + participle = "] to User [" ; + break; + case 1: + fp = client.delete("/authz/userRole/" + urr.getUser() + '/' + urr.getRole(), Void.class); + verb = "Removed"; + participle = "] from User [" ; + break; + case 3: + fp = client.update("/authz/userRole/extend/" + urr.getUser() + '/' + urr.getRole()); + verb = "Extended"; + participle = "] to User [" ; + break; + default: + throw new CadiException("Invalid action [" + key + ']'); + } + if (fp.get(AAFcli.timeout())) { + pw().print(verb); + pw().print(" Role ["); + pw().print(urr.getRole()); + pw().print(participle); + pw().print(urr.getUser()); + pw().println(']'); + } else { + switch(fp.code()) { + case 202: + pw().print("UserRole "); + pw().print(option == 0 ? "Creation" : option==1?"Deletion":"Extension"); + pw().println(" Accepted, but requires Approvals before actualizing"); + break; + case 404: + if(option==3) { + pw().println("Failed with code 404: UserRole is not found, or you do not have permission to view"); + break; + } + default: + error(fp); + } + } + } + } else { + // option 2 is setTo command (an update call) + String allRoles = ""; + if (idx < args.length) + allRoles = args[idx++]; - urr.setRole(allRoles); - fp = client.update("/authz/userRole/user", getDF(UserRoleRequest.class), urr); - if (fp.get(AAFcli.timeout())) { - pw().println("Set User's Roles to [" + allRoles + "]"); - } else { - error(fp); - } - } - return fp == null ? 0 : fp.code(); - } - }); - } + urr.setRole(allRoles); + fp = client.update("/authz/userRole/user", getDF(UserRoleRequest.class), urr); + if (fp.get(AAFcli.timeout())) { + pw().println("Set User's Roles to [" + allRoles + "]"); + } else { + error(fp); + } + } + return fp == null ? 0 : fp.code(); + } + }); + } - @Override - public void detailedHelp(int indent, StringBuilder sb) { - detailLine(sb, indent, "Add OR Delete a User to/from a Role OR"); - detailLine(sb, indent, "Set a User's Roles to the roles supplied"); - detailLine(sb, indent + 2, "user - ID of User"); - detailLine(sb, indent + 2, "role(s) - Role or Roles to which to add the User"); - sb.append('\n'); - detailLine(sb, indent + 2, "Note: this is the same as \"role user add...\" except allows"); - detailLine(sb, indent + 2, "assignment of user to multiple roles"); - detailLine(sb, indent + 2, "WARNING: Roles supplied with setTo will be the ONLY roles attached to this user"); - detailLine(sb, indent + 2, "If no roles are supplied, user's roles are reset."); - api(sb, indent, HttpMethods.POST, "authz/userRole", UserRoleRequest.class, true); - api(sb, indent, HttpMethods.DELETE, "authz/userRole//", Void.class, false); - api(sb, indent, HttpMethods.PUT, "authz/userRole/", UserRoleRequest.class, false); - } + @Override + public void detailedHelp(int indent, StringBuilder sb) { + detailLine(sb, indent, "Add OR Delete a User to/from a Role OR"); + detailLine(sb, indent, "Set a User's Roles to the roles supplied"); + detailLine(sb, indent + 2, "user - ID of User"); + detailLine(sb, indent + 2, "role(s) - Role or Roles to which to add the User"); + sb.append('\n'); + detailLine(sb, indent + 2, "Note: this is the same as \"role user add...\" except allows"); + detailLine(sb, indent + 2, "assignment of user to multiple roles"); + detailLine(sb, indent + 2, "WARNING: Roles supplied with setTo will be the ONLY roles attached to this user"); + detailLine(sb, indent + 2, "If no roles are supplied, user's roles are reset."); + api(sb, indent, HttpMethods.POST, "authz/userRole", UserRoleRequest.class, true); + api(sb, indent, HttpMethods.DELETE, "authz/userRole//", Void.class, false); + api(sb, indent, HttpMethods.PUT, "authz/userRole/", UserRoleRequest.class, false); + } }