X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-cmd%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fcmd%2Fns%2FList.java;h=84a01614630bab072daeaa564b31f4c674b37ee9;hb=HEAD;hp=387bae003b4c5d7fbc2a8d9104593a3d3ea7cab5;hpb=ceda6e8bc270202bcb24340b86617110289c902e;p=aaf%2Fauthz.git diff --git a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/ns/List.java b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/ns/List.java index 387bae00..84a01614 100644 --- a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/ns/List.java +++ b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/ns/List.java @@ -7,9 +7,9 @@ * 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. @@ -26,6 +26,7 @@ import java.util.Comparator; import org.onap.aaf.auth.cmd.BaseCmd; import org.onap.aaf.auth.cmd.DeprecatedCMD; +import org.onap.aaf.auth.common.Define; import org.onap.aaf.cadi.client.Future; import org.onap.aaf.misc.env.util.Chrono; @@ -38,139 +39,132 @@ import aaf.v2_0.Users.User; public class List extends BaseCmd { - public List(NS parent) { - super(parent,"list"); - cmds.add(new ListByName(this)); - -// TODO: uncomment when on cassandra 2.1.2 if we like cli command to get all ns's -// a user is admin or responsible for - cmds.add(new ListAdminResponsible(this)); - cmds.add(new DeprecatedCMD(this,"responsible","'responsible' is deprecated. use 'owner'")); // deprecated - cmds.add(new ListActivity(this)); - cmds.add(new ListUsers(this)); - cmds.add(new ListChildren(this)); - cmds.add(new ListNsKeysByAttrib(this)); - } - - private static final String sformat = " %-72s\n"; - protected static final String kformat = " %-72s\n"; - - - public void report(Future fp, String ... str) { - reportHead(str); - if(fp==null) { - pw().println(" *** Namespace Not Found ***"); - } - - if(fp!=null && fp.value!=null) { - for(Ns ns : fp.value.getNs()) { - pw().println(ns.getName()); - if (this.aafcli.isDetailed()) { - pw().println(" Description"); - pw().format(sformat,ns.getDescription()==null?"":ns.getDescription()); - } - if(ns.getAdmin().size()>0) { - pw().println(" Administrators"); - for(String admin : ns.getAdmin()) { - pw().format(sformat,admin); - } - } - if(ns.getResponsible().size()>0) { - pw().println(" Owners (Responsible for Namespace)"); - for(String responsible : ns.getResponsible()) { - pw().format(sformat,responsible); - } - } - if(ns.getAttrib().size()>0) { - pw().println(" Namespace Attributes"); - for( Ns.Attrib attr : ns.getAttrib()) { - StringBuilder sb = new StringBuilder(attr.getKey()); - if(attr.getValue()==null || attr.getValue().length()>0) { - sb.append('='); - sb.append(attr.getValue()); - } - pw().format(sformat,sb.toString()); - } - - } - } - } - } - - public void reportName(Future fp, String ... str) { - reportHead(str); - if(fp!=null && fp.value!=null) { - java.util.List nss = fp.value.getNs(); - Collections.sort(nss, new Comparator() { - @Override - public int compare(Ns ns1, Ns ns2) { - return ns1.getName().compareTo(ns2.getName()); - } - }); - - for(Ns ns : nss) { - pw().println(ns.getName()); - if (this.aafcli.isDetailed() && ns.getDescription() != null) { - pw().println(" " + ns.getDescription()); - } - } - } - } - - public void reportRole(Future fr) { - if(fr!=null && fr.value!=null && fr.value.getRole().size()>0) { - pw().println(" Roles"); - for(aaf.v2_0.Role r : fr.value.getRole()) { - pw().format(sformat,r.getName()); - } - } - } - - private static final String pformat = " %-30s %-24s %-15s\n"; - public void reportPerm(Future fp) { - if(fp!=null && fp.value!=null && fp.value.getPerm().size()>0) { - pw().println(" Permissions"); - for(aaf.v2_0.Perm p : fp.value.getPerm()) { - pw().format(pformat,p.getType(),p.getInstance(),p.getAction()); - } - } - } - - - private static final String cformat = " %-30s %-6s %-24s\n"; - public void reportCred(Future fc) { - if(fc!=null && fc.value!=null && fc.value.getUser().size()>0) { - pw().println(" Credentials"); - java.util.List users = fc.value.getUser(); - Collections.sort(users, new Comparator() { - @Override - public int compare(User u1, User u2) { - return u1.getId().compareTo(u2.getId()); - } - }); - for(aaf.v2_0.Users.User u : users) { - if (this.aafcli.isTest()) { - pw().format(sformat,u.getId()); - } else { - pw().format(cformat,u.getId(),getType(u),Chrono.niceDateStamp(u.getExpires())); - } - } - } - } - - public static String getType(User u) { - Integer type; - if((type=u.getType())==null) { - type = 9999; - } - switch(type) { - case 1: return "U/P"; - case 2: return "U/P2"; - case 10: return "Cert"; - case 200: return "x509"; - default: - return "n/a"; - } - } + private static final String cformat = " %-30s %-6s %-24s %-20s\n"; + private static final String pformat = " %-30s %-24s %-15s\n"; + private static final String sformat = " %-72s\n"; + protected static final String kformat = " %-72s\n"; + + public List(NS parent) { + super(parent,"list"); + cmds.add(new ListByName(this)); + +// TODO: uncomment when on cassandra 2.1.2 if we like cli command to get all ns's +// a user is admin or responsible for + cmds.add(new ListAdminResponsible(this)); + cmds.add(new DeprecatedCMD(this,"responsible","'responsible' is deprecated. use 'owner'")); // deprecated + cmds.add(new ListActivity(this)); + cmds.add(new ListUsers(this)); + cmds.add(new ListChildren(this)); + cmds.add(new ListNsKeysByAttrib(this)); + } + + public void report(Future fp, String ... str) { + reportHead(str); + if (fp==null) { + pw().println(" *** Namespace Not Found ***"); + } + + if (fp!=null && fp.value!=null) { + for (Ns ns : fp.value.getNs()) { + pw().println(ns.getName()); + if (this.aafcli.isDetailed()) { + pw().println(" Description"); + pw().format(sformat,ns.getDescription()==null?"":ns.getDescription()); + } + if (!(ns.getAdmin().isEmpty())) { + pw().println(" Administrators"); + for (String admin : ns.getAdmin()) { + pw().format(sformat,admin); + } + } + if (!(ns.getResponsible().isEmpty())) { + pw().println(" Owners (Responsible for Namespace)"); + for (String responsible : ns.getResponsible()) { + pw().format(sformat,responsible); + } + } + if (!(ns.getAttrib().isEmpty())) { + pw().println(" Namespace Attributes"); + for ( Ns.Attrib attr : ns.getAttrib()) { + StringBuilder sb = new StringBuilder(attr.getKey()); + if (attr.getValue()==null || attr.getValue().length()>0) { + sb.append('='); + sb.append(attr.getValue()); + } + pw().format(sformat,sb.toString()); + } + + } + } + } + } + + public void reportName(Future fp, String ... str) { + reportHead(str); + if (fp!=null && fp.value!=null) { + java.util.List nss = fp.value.getNs(); + Collections.sort(nss, new Comparator() { + @Override + public int compare(Ns ns1, Ns ns2) { + return ns1.getName().compareTo(ns2.getName()); + } + }); + + for (Ns ns : nss) { + pw().println(ns.getName()); + if (this.aafcli.isDetailed() && ns.getDescription() != null) { + pw().println(" " + ns.getDescription()); + } + } + } + } + + public void reportRole(Future fr) { + if (fr!=null && fr.value!=null && !(fr.value.getRole().isEmpty())) { + pw().println(" Roles"); + for (aaf.v2_0.Role r : fr.value.getRole()) { + pw().format(sformat,r.getName()); + } + } + } + + public void reportPerm(Future fp) { + if (fp!=null && fp.value!=null && !(fp.value.getPerm().isEmpty())) { + pw().println(" Permissions"); + for (aaf.v2_0.Perm p : fp.value.getPerm()) { + pw().format(pformat,p.getType(),p.getInstance(),p.getAction()); + } + } + } + + + public void reportCred(Future fc) { + if (fc!=null && fc.value!=null && !(fc.value.getUser().isEmpty())) { + pw().println(" Credentials"); + java.util.List users = fc.value.getUser(); + Collections.sort(users, new Comparator() { + @Override + public int compare(User u1, User u2) { + return u1.getId().compareTo(u2.getId()); + } + }); + for (aaf.v2_0.Users.User u : users) { + if (this.aafcli.isTest()) { + pw().format(sformat,u.getId()); + } else { + pw().format(cformat,u.getId(),getType(u),Chrono.niceDateStamp(u.getExpires()),u.getTag()); + } + } + } + } + + public static String getType(User u) { + Integer type; + if ((type=u.getType())==null) { + type = 9999; + } + return Define.getCredType(type); + } + }