X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-cmd%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fcmd%2Fperm%2FCreate.java;h=c444722b32a34d68909538f251385deb358e4a41;hb=f5fdc4f2d1f87001364ccf462c1398a10e84fdcf;hp=1f123cff034fcba2bffcea040c16e0d1a5200141;hpb=4b5a7d721d994a49057e9bfb403c7bff1b376660;p=aaf%2Fauthz.git diff --git a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/perm/Create.java b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/perm/Create.java index 1f123cff..c444722b 100644 --- a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/perm/Create.java +++ b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/perm/Create.java @@ -3,13 +3,14 @@ * org.onap.aaf * =========================================================================== * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 IBM. * =========================================================================== * 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. @@ -36,14 +37,14 @@ import aaf.v2_0.PermRequest; import aaf.v2_0.RoleRequest; /** - * + * * @author Jonathan * */ public class Create extends Cmd { public Create(Perm parent) { - super(parent,"create", - new Param("type",true), + super(parent,"create", + new Param("type",true), new Param("instance",true), new Param("action", true), new Param("role[,role]* (to Grant to)", false) @@ -56,7 +57,7 @@ public class Create extends Cmd { @Override public Integer code(Rcli client) throws CadiException, APIException { int idx = index; - final PermRequest pr = new PermRequest(); + final PermRequest pr = new PermRequest(); pr.setType(args[idx++]); pr.setInstance(args[idx++]); pr.setAction(args[idx++]); @@ -64,10 +65,10 @@ public class Create extends Cmd { String[] roles = roleCommas==null?null:roleCommas.split("\\s*,\\s*"); boolean force = aafcli.forceString()!=null; int rv; - - if(roles!=null && force) { // Make sure Roles are Created + + if (roles!=null && force) { // Make sure Roles are Created RoleRequest rr = new RoleRequest(); - for(String role : roles) { + for (String role : roles) { rr.setName(role);; Future fr = client.create( "/authz/role", @@ -81,7 +82,7 @@ public class Create extends Cmd { break; case 409: break; - default: + default: pw().println("Role [" + role + "] does not exist, and cannot be created."); return 206 /*HttpStatus.PARTIAL_CONTENT_206*/; } @@ -96,13 +97,13 @@ public class Create extends Cmd { getDF(PermRequest.class), pr ); - if(fp.get(AAFcli.timeout())) { + if (fp.get(AAFcli.timeout())) { rv = fp.code(); pw().println("Created Permission"); - if(roles!=null) { - if(aafcli.forceString()!=null) { // Make sure Roles are Created + if (roles!=null) { + if (aafcli.forceString()!=null) { // Make sure Roles are Created RoleRequest rr = new RoleRequest(); - for(String role : roles) { + for (String role : roles) { rr.setName(role);; Future fr = client.create( "/authz/role", @@ -113,14 +114,14 @@ public class Create extends Cmd { switch(fr.code()){ case 201: case 409:break; - default: - + default: + } } } - + try { - if(201!=(rv=((Perm)parent)._exec(0, + if (201!=(rv=((Perm)parent)._exec(0, new String[] {"grant",pr.getType(),pr.getInstance(),pr.getAction(),roleCommas}))) { rv = 206 /*HttpStatus.PARTIAL_CONTENT_206*/; } @@ -130,9 +131,9 @@ public class Create extends Cmd { } } else { rv = fp.code(); - if(rv==409 && force) { + if (rv==409 && force) { rv = 201; - } else if(rv==202) { + } else if (rv==202) { pw().println("Permission Creation Accepted, but requires Approvals before actualizing"); if (roles!=null) pw().println("You need to grant the roles after approval."); @@ -144,12 +145,13 @@ public class Create extends Cmd { } }); } - + @Override public void detailedHelp(int _indent, StringBuilder sb) { int indent = _indent; detailLine(sb,indent,"Create a Permission with:"); - detailLine(sb,indent+=2,"type - A Namespace qualified identifier identifying the kind of"); + indent=indent+2; + detailLine(sb,indent,"type - A Namespace qualified identifier identifying the kind of"); detailLine(sb,indent+11,"resource to be protected"); detailLine(sb,indent,"instance - A name that distinguishes a particular instance of resource"); detailLine(sb,indent,"action - What kind of action is allowed");