2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.cmd.ns;
24 import java.util.HashSet;
27 import org.onap.aaf.auth.cmd.AAFcli;
28 import org.onap.aaf.auth.cmd.Cmd;
29 import org.onap.aaf.auth.cmd.Param;
30 import org.onap.aaf.auth.rserv.HttpMethods;
31 import org.onap.aaf.cadi.CadiException;
32 import org.onap.aaf.cadi.LocatorException;
33 import org.onap.aaf.cadi.client.Future;
34 import org.onap.aaf.cadi.client.Rcli;
35 import org.onap.aaf.cadi.client.Retryable;
36 import org.onap.aaf.misc.env.APIException;
39 import aaf.v2_0.Nss.Ns;
41 import aaf.v2_0.Perms;
42 import aaf.v2_0.Users;
43 import aaf.v2_0.Users.User;
50 public class ListUsersWithPerm extends Cmd {
51 private static final String HEADER="List Users of Permissions of Namespace ";
53 public ListUsersWithPerm(ListUsers parent) {
55 new Param("ns-name",true));
59 public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException {
61 final String ns=args[idx++];
62 final boolean detail = aafcli.isDetailed();
63 return same(new Retryable<Integer>() {
65 public Integer code(Rcli<?> client) throws CadiException, APIException {
66 ((ListUsers)parent).report(HEADER,ns);
67 Future<Nss> fn = client.read("/authz/nss/"+ns,getDF(Nss.class));
68 if (fn.get(AAFcli.timeout())) {
70 Set<String> uset = detail?null:new HashSet<>();
72 for (Ns n : fn.value.getNs()) {
73 Future<Perms> fp = client.read("/authz/perms/ns/"+n.getName()+(aafcli.isDetailed()?"?ns":"")
74 , getDF(Perms.class));
75 if (fp.get(AAFcli.timeout())) {
76 for (Perm p : fp.value.getPerm()) {
77 String perm = p.getType()+'/'+p.getInstance()+'/'+p.getAction();
78 if (detail)((ListUsers)parent).report(perm);
79 Future<Users> fus = client.read(
80 "/authz/users/perm/"+perm,
83 if (fus.get(AAFcli.timeout())) {
84 for (User u : fus.value.getUser()) {
86 ((ListUsers)parent).report(" ",u);
90 } else if (fn.code()==404) {
97 for (String u : uset) {
103 } else if (fn.code()==404) {
114 public void detailedHelp(int _indent, StringBuilder sb) {
115 int indent = _indent;
116 detailLine(sb,indent,HEADER);
118 detailLine(sb,indent,"Report Users associated with this Namespace's Permissions");
120 detailLine(sb,indent,"If \"set detail=true\" is specified, then Permissions are printed with the associated");
121 detailLine(sb,indent,"users and expiration dates");
123 api(sb,indent,HttpMethods.GET,"authz/nss/<ns>",Nss.class,true);
124 api(sb,indent,HttpMethods.GET,"authz/perms/ns/<ns>",Perms.class,false);
125 api(sb,indent,HttpMethods.GET,"authz/users/perm/<type>/<instance>/<action>",Users.class,false);