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.gui.pages;
24 import java.io.IOException;
25 import java.io.StringWriter;
26 import java.net.ConnectException;
27 import java.util.ArrayList;
28 import java.util.List;
30 import org.onap.aaf.auth.cmd.AAFcli;
31 import org.onap.aaf.auth.env.AuthzTrans;
32 import org.onap.aaf.auth.gui.AAF_GUI;
33 import org.onap.aaf.auth.gui.BreadCrumbs;
34 import org.onap.aaf.auth.gui.Page;
35 import org.onap.aaf.auth.gui.Table;
36 import org.onap.aaf.auth.gui.Table.Cells;
37 import org.onap.aaf.auth.gui.table.AbsCell;
38 import org.onap.aaf.auth.gui.table.RefCell;
39 import org.onap.aaf.auth.gui.table.TableData;
40 import org.onap.aaf.auth.gui.table.TextCell;
41 import org.onap.aaf.auth.validation.Validator;
42 import org.onap.aaf.cadi.CadiException;
43 import org.onap.aaf.cadi.client.Future;
44 import org.onap.aaf.cadi.client.Rcli;
45 import org.onap.aaf.cadi.client.Retryable;
46 import org.onap.aaf.cadi.config.Config;
47 import org.onap.aaf.misc.env.APIException;
48 import org.onap.aaf.misc.env.Env;
49 import org.onap.aaf.misc.env.Slot;
50 import org.onap.aaf.misc.env.TimeTaken;
51 import org.onap.aaf.misc.xgen.html.HTMLGen;
54 import aaf.v2_0.Nss.Ns;
56 import aaf.v2_0.Perms;
58 import aaf.v2_0.Roles;
60 public class NsDetail extends Page {
62 public static final String HREF = "/gui/nsdetail";
63 public static final String NAME = "NsDetail";
64 static final String WEBPHONE = "http://webphone.att.com/cgi-bin/webphones.pl?id=";
65 public static enum NS_FIELD { OWNERS, ADMINS, ROLES, PERMISSIONS, CREDS};
66 private static final String BLANK = "";
67 private static Slot keySlot;
68 private static Model model;
69 private static String gw_url;
72 public NsDetail(final AAF_GUI gui, Page ... breadcrumbs) throws APIException, IOException {
73 super(gui.env, NAME, HREF, new String[] {"ns"},
74 new BreadCrumbs(breadcrumbs),
75 new Table<AAF_GUI,AuthzTrans>("Namespace Details",gui.env.newTransNoAvg(),model=new Model(),"class=detail")
78 keySlot = gui.env.slot(NAME+".ns");
79 gw_url = gui.env.getProperty(Config.GW_URL);
88 * Implement the table content for Namespace Detail
93 private static class Model extends TableData<AAF_GUI,AuthzTrans> {
94 private static final String CSP_ATT_COM = "@csp.att.com";
97 public void set(NsDetail nsDetail) {
102 public Cells get(final AuthzTrans trans, final AAF_GUI gui) {
103 final String nsName = trans.get(keySlot, null);
104 Validator v = new Validator();
107 trans.warn().printf("Error in NsDetail Request: %s", v.errs());
114 final ArrayList<AbsCell[]> rv = new ArrayList<AbsCell[]>();
115 rv.add(new AbsCell[]{new TextCell("Name:"),new TextCell(nsName)});
117 final TimeTaken tt = trans.start("AAF Namespace Details",Env.REMOTE);
119 gui.clientAsUser(trans.getUserPrincipal(),new Retryable<Void>() {
121 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
122 Future<Nss> fn = client.read("/authz/nss/"+nsName,gui.getDF(Nss.class));
124 if(fn.get(AAF_GUI.TIMEOUT)) {
127 // TimeTaken tt = trans.start("Load Data", Env.SUB);
129 for(Ns n : fn.value.getNs()) {
130 String desc = (n.getDescription()!=null?n.getDescription():BLANK);
131 rv.add(new AbsCell[]{new TextCell("Description:"),new TextCell(desc)});
133 addField(trans, nsName, rv, n.getAdmin(), NS_FIELD.ADMINS);
134 addField(trans, nsName, rv, n.getResponsible(), NS_FIELD.OWNERS);
136 StringWriter sw = new StringWriter();
137 HTMLGen hgen = nd.clone(sw);
138 hgen.leaf(HTMLGen.A, "class=greenbutton","href="+CredDetail.HREF+"?ns="+nsName).text("Cred Details").end();
139 rv.add(new AbsCell[] {
140 new TextCell("Credentials"),
141 new TextCell(sw.toString())
145 Future<Roles> fr = client.read(
146 "/authz/roles/ns/"+nsName,
147 gui.getDF(Roles.class)
149 List<String> roles = new ArrayList<String>();
150 if(fr.get(AAFcli.timeout())) {
151 for (Role r : fr.value.getRole()) {
152 roles.add(r.getName());
155 addField(trans, nsName, rv, roles, NS_FIELD.ROLES);
158 Future<Perms> fp = client.read(
159 "/authz/perms/ns/"+nsName,
160 gui.getDF(Perms.class)
162 List<String> perms = new ArrayList<String>();
164 if(fp.get(AAFcli.timeout())) {
165 for (Perm p : fp.value.getPerm()) {
166 perms.add(p.getType() + "|" + p.getInstance() + "|" + p.getAction());
169 addField(trans, nsName, rv, perms, NS_FIELD.PERMISSIONS);
171 String historyLink = NsHistory.HREF
173 rv.add(new AbsCell[] {new RefCell("See History",historyLink,false)});
178 rv.add(new AbsCell[] {new TextCell("*** Data Unavailable ***")});
183 } catch (Exception e) {
188 return new Cells(rv,null);
191 private void addField(AuthzTrans trans, String ns, List<AbsCell[]> rv, List<String> values, NS_FIELD field) {
192 if (!values.isEmpty()) {
197 for (int i=0; i< values.size(); i++) {
198 AbsCell label = (i==0?new TextCell(sentenceCase(field)+":"):AbsCell.Null);
199 String user = values.get(i);
200 AbsCell userCell = (user.endsWith(CSP_ATT_COM)?
201 new RefCell(user,WEBPHONE + user.substring(0,user.indexOf('@')),true):new TextCell(user));
202 rv.add(new AbsCell[] {
209 for (int i=0; i< values.size(); i++) {
210 String role = values.get(i);
211 AbsCell label = (i==0?new TextCell(sentenceCase(field)+":"):AbsCell.Null);
212 rv.add(new AbsCell[] {
214 new RefCell(role,RoleDetail.HREF+"?role="+role+"&ns="+ns,false)
219 for (int i=0; i< values.size(); i++) {
220 AbsCell label = (i==0?new TextCell(sentenceCase(field)+":","style=width:20%"):AbsCell.Null);
221 String perm = values.get(i);
222 String[] fields = perm.split("\\|");
223 String grantLink = gw_url
225 + "?type=" + fields[0].trim()
226 + "&instance=" + fields[1].trim()
227 + "&action=" + fields[2].trim();
229 rv.add(new AbsCell[] {
231 new TextCell(perm,"style=width:60%;"),
232 new RefCell("Grant", grantLink,false,"class=button","style=width:20%;")
241 private String sentenceCase(NS_FIELD field) {
242 String sField = field.toString();
243 return sField.substring(0, 1).toUpperCase() + sField.substring(1).toLowerCase();