1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package com.att.cmd.ns;
\r
25 import java.util.HashSet;
\r
26 import java.util.Set;
\r
28 import com.att.cadi.CadiException;
\r
29 import com.att.cadi.LocatorException;
\r
30 import com.att.cadi.client.Future;
\r
31 import com.att.cadi.client.Rcli;
\r
32 import com.att.cadi.client.Retryable;
\r
33 import com.att.cmd.AAFcli;
\r
34 import com.att.cmd.Cmd;
\r
35 import com.att.cmd.Param;
\r
36 import com.att.cssa.rserv.HttpMethods;
\r
37 import com.att.inno.env.APIException;
\r
39 import aaf.v2_0.Nss;
\r
40 import aaf.v2_0.Nss.Ns;
\r
41 import aaf.v2_0.Role;
\r
42 import aaf.v2_0.Roles;
\r
43 import aaf.v2_0.Users;
\r
44 import aaf.v2_0.Users.User;
\r
50 public class ListUsersInRole extends Cmd {
\r
51 private static final String HEADER="List Users in Roles of Namespace ";
\r
53 public ListUsersInRole(ListUsers parent) {
\r
54 super(parent,"role",
\r
55 new Param("ns",true));
\r
59 public int _exec(int _idx, final String ... args) throws CadiException, APIException, LocatorException {
\r
61 final String ns=args[idx++];
\r
62 final boolean detail = aafcli.isDetailed();
\r
63 return same(new Retryable<Integer>() {
\r
65 public Integer code(Rcli<?> client) throws CadiException, APIException {
\r
66 ((ListUsers)parent).report(HEADER,ns);
\r
67 Future<Nss> fn = client.read("/authz/nss/"+ns,getDF(Nss.class));
\r
68 if(fn.get(AAFcli.timeout())) {
\r
69 if(fn.value!=null) {
\r
70 Set<String> uset = detail?null:new HashSet<String>();
\r
71 for(Ns n : fn.value.getNs()) {
\r
72 Future<Roles> fr = client.read("/authz/roles/ns/"+n.getName(), getDF(Roles.class));
\r
73 if(fr.get(AAFcli.timeout())) {
\r
74 for(Role r : fr.value.getRole()) {
\r
76 ((ListUsers)parent).report(r.getName());
\r
78 Future<Users> fus = client.read(
\r
79 "/authz/users/role/"+r.getName(),
\r
82 if(fus.get(AAFcli.timeout())) {
\r
83 for(User u : fus.value.getUser()) {
\r
85 ((ListUsers)parent).report(" ",u);
\r
87 uset.add(u.getId());
\r
90 } else if(fn.code()==404) {
\r
97 for(String u : uset) {
\r
103 } else if(fn.code()==404) {
\r
114 public void detailedHelp(int _indent, StringBuilder sb) {
\r
115 int indent = _indent;
\r
116 detailLine(sb,indent,HEADER);
\r
118 detailLine(sb,indent,"Report Users associated with this Namespace's Roles");
\r
120 detailLine(sb,indent,"If \"set details=true\" is specified, then all roles are printed ");
\r
121 detailLine(sb,indent,"with the associated users and expiration dates");
\r
123 api(sb,indent,HttpMethods.GET,"authz/nss/<ns>",Nss.class,true);
\r
124 api(sb,indent,HttpMethods.GET,"authz/roles/ns/<ns>",Roles.class,false);
\r
125 api(sb,indent,HttpMethods.GET,"authz/users/role/<ns>",Users.class,false);
\r