1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * Copyright © 2017 Amdocs
\r
7 * * ===========================================================================
\r
8 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * * you may not use this file except in compliance with the License.
\r
10 * * You may obtain a copy of the License at
\r
12 * * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * * Unless required by applicable law or agreed to in writing, software
\r
15 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * * See the License for the specific language governing permissions and
\r
18 * * limitations under the License.
\r
19 * * ============LICENSE_END====================================================
\r
21 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 ******************************************************************************/
\r
24 package com.att.cmd.perm;
\r
26 import java.util.ArrayList;
\r
27 import java.util.Collections;
\r
28 import java.util.Comparator;
\r
30 import com.att.cadi.CadiException;
\r
31 import com.att.cadi.client.Future;
\r
32 import com.att.cadi.client.Rcli;
\r
33 import com.att.cadi.client.Retryable;
\r
34 import com.att.cmd.AAFcli;
\r
35 import com.att.cmd.BaseCmd;
\r
36 import com.att.inno.env.APIException;
\r
38 import aaf.v2_0.Nss;
\r
39 import aaf.v2_0.Perms;
\r
40 import aaf.v2_0.Pkey;
\r
43 public class List extends BaseCmd<Perm> {
\r
44 // private static final String LIST_PERM_DETAILS = "list permission details";
\r
46 public List(Perm parent) {
\r
47 super(parent,"list");
\r
49 cmds.add(new ListByUser(this));
\r
50 cmds.add(new ListByName(this));
\r
51 cmds.add(new ListByNS(this));
\r
52 cmds.add(new ListByRole(this));
\r
53 cmds.add(new ListActivity(this));
\r
55 // Package Level on purpose
\r
56 abstract class ListPerms extends Retryable<Integer> {
\r
57 protected int list(Future<Perms> fp,Rcli<?> client, String header, String parentPerm) throws CadiException, APIException {
\r
58 if(fp.get(AAFcli.timeout())) {
\r
59 ArrayList<String> permNss = null;
\r
60 if (aafcli.isDetailed()) {
\r
61 permNss = new ArrayList<String>();
\r
62 String permNs = null;
\r
63 for(Pkey perm : fp.value.getPerm()) {
\r
64 if (permNs != null && perm.getType().contains(permNs)) {
\r
65 permNss.add(permNs);
\r
67 Future<Nss> fpn = null;
\r
68 String permType = perm.getType();
\r
71 permNs = permType.substring(0,permNs.lastIndexOf('.'));
\r
72 fpn = client.read("/authz/nss/"+permNs,getDF(Nss.class));
\r
73 } while (!fpn.get(AAFcli.timeout()));
\r
74 permNss.add(permNs);
\r
78 report(fp,permNss,header, parentPerm);
\r
86 private static final Comparator<aaf.v2_0.Perm> permCompare = new Comparator<aaf.v2_0.Perm>() {
\r
88 public int compare(aaf.v2_0.Perm a, aaf.v2_0.Perm b) {
\r
90 if((rc=a.getType().compareTo(b.getType()))!=0) {
\r
93 if((rc=a.getInstance().compareTo(b.getInstance()))!=0) {
\r
96 return a.getAction().compareTo(b.getAction());
\r
100 void report(Future<Perms> fp, ArrayList<String> permNss, String ... str) {
\r
102 if (this.aafcli.isDetailed()) {
\r
103 String format = reportColHead("%-20s %-15s %-30s %-15s\n %-75s\n","PERM NS","Type","Instance","Action", "Description");
\r
104 Collections.sort(fp.value.getPerm(),permCompare);
\r
105 for(aaf.v2_0.Perm p : fp.value.getPerm()) {
\r
106 String permNs = permNss.remove(0);
\r
107 pw().format(format,
\r
109 p.getType().substring(permNs.length()+1),
\r
112 p.getDescription()==null?"":p.getDescription());
\r
116 String format = reportColHead("%-30s %-30s %-10s\n","PERM Type","Instance","Action");
\r
118 Collections.sort(fp.value.getPerm(),permCompare);
\r
119 for(aaf.v2_0.Perm p : fp.value.getPerm()) {
\r
120 pw().format(format,
\r