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.perm;
\r
25 import java.util.ArrayList;
\r
26 import java.util.Collections;
\r
27 import java.util.Comparator;
\r
29 import com.att.cadi.CadiException;
\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.BaseCmd;
\r
35 import com.att.inno.env.APIException;
\r
37 import aaf.v2_0.Nss;
\r
38 import aaf.v2_0.Perms;
\r
39 import aaf.v2_0.Pkey;
\r
42 public class List extends BaseCmd<Perm> {
\r
43 // private static final String LIST_PERM_DETAILS = "list permission details";
\r
45 public List(Perm parent) {
\r
46 super(parent,"list");
\r
48 cmds.add(new ListByUser(this));
\r
49 cmds.add(new ListByName(this));
\r
50 cmds.add(new ListByNS(this));
\r
51 cmds.add(new ListByRole(this));
\r
52 cmds.add(new ListActivity(this));
\r
54 // Package Level on purpose
\r
55 abstract class ListPerms extends Retryable<Integer> {
\r
56 protected int list(Future<Perms> fp,Rcli<?> client, String header, String parentPerm) throws CadiException, APIException {
\r
57 if(fp.get(AAFcli.timeout())) {
\r
58 ArrayList<String> permNss = null;
\r
59 if (aafcli.isDetailed()) {
\r
60 permNss = new ArrayList<String>();
\r
61 String permNs = null;
\r
62 for(Pkey perm : fp.value.getPerm()) {
\r
63 if (permNs != null && perm.getType().contains(permNs)) {
\r
64 permNss.add(permNs);
\r
66 Future<Nss> fpn = null;
\r
67 String permType = perm.getType();
\r
70 permNs = permType.substring(0,permNs.lastIndexOf('.'));
\r
71 fpn = client.read("/authz/nss/"+permNs,getDF(Nss.class));
\r
72 } while (!fpn.get(AAFcli.timeout()));
\r
73 permNss.add(permNs);
\r
77 report(fp,permNss,header, parentPerm);
\r
85 private static final Comparator<aaf.v2_0.Perm> permCompare = new Comparator<aaf.v2_0.Perm>() {
\r
87 public int compare(aaf.v2_0.Perm a, aaf.v2_0.Perm b) {
\r
89 if((rc=a.getType().compareTo(b.getType()))!=0) {
\r
92 if((rc=a.getInstance().compareTo(b.getInstance()))!=0) {
\r
95 return a.getAction().compareTo(b.getAction());
\r
99 void report(Future<Perms> fp, ArrayList<String> permNss, String ... str) {
\r
101 if (this.aafcli.isDetailed()) {
\r
102 String format = reportColHead("%-20s %-15s %-30s %-15s\n %-75s\n","PERM NS","Type","Instance","Action", "Description");
\r
103 Collections.sort(fp.value.getPerm(),permCompare);
\r
104 for(aaf.v2_0.Perm p : fp.value.getPerm()) {
\r
105 String permNs = permNss.remove(0);
\r
106 pw().format(format,
\r
108 p.getType().substring(permNs.length()+1),
\r
111 p.getDescription()==null?"":p.getDescription());
\r
115 String format = reportColHead("%-30s %-30s %-10s\n","PERM Type","Instance","Action");
\r
117 Collections.sort(fp.value.getPerm(),permCompare);
\r
118 for(aaf.v2_0.Perm p : fp.value.getPerm()) {
\r
119 pw().format(format,
\r