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.net.ConnectException;
26 import java.util.ArrayList;
27 import java.util.List;
29 import org.eclipse.jetty.http.HttpStatus;
30 import org.onap.aaf.auth.env.AuthzEnv;
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.misc.env.APIException;
47 import org.onap.aaf.misc.env.Env;
48 import org.onap.aaf.misc.env.Slot;
49 import org.onap.aaf.misc.env.TimeTaken;
52 import aaf.v2_0.Perms;
55 * Detail Page for Permissions
60 public class PermDetail extends Page {
61 public static final String HREF = "/gui/permdetail";
62 public static final String NAME = "PermDetail";
63 private static final String BLANK = "";
65 public PermDetail(final AAF_GUI gui, Page ... breadcrumbs) throws APIException, IOException {
66 super(gui.env, NAME, HREF, new String[] {"type","instance","action"},
67 new BreadCrumbs(breadcrumbs),
68 new Table<AAF_GUI,AuthzTrans>("Permission Details",gui.env.newTransNoAvg(),new Model(gui.env),"class=detail")
73 * Implement the table content for Permissions Detail
78 private static class Model extends TableData<AAF_GUI,AuthzTrans> {
79 private Slot type, instance, action;
80 public Model(AuthzEnv env) {
81 type = env.slot(NAME+".type");
82 instance = env.slot(NAME+".instance");
83 action = env.slot(NAME+".action");
86 public Cells get(final AuthzTrans trans, final AAF_GUI gui) {
87 final String pType = trans.get(type, null);
88 final String pInstance = trans.get(instance, null);
89 final String pAction = trans.get(action, null);
90 Validator v = new Validator();
92 .permInstance(pInstance)
96 trans.warn().printf("Error in PermDetail Request: %s", v.errs());
99 final ArrayList<AbsCell[]> rv = new ArrayList<>();
100 rv.add(new AbsCell[]{new TextCell("Type:"),new TextCell(pType)});
101 rv.add(new AbsCell[]{new TextCell("Instance:"),new TextCell(pInstance)});
102 rv.add(new AbsCell[]{new TextCell("Action:"),new TextCell(pAction)});
104 gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
106 public Void code(Rcli<?> client)throws CadiException, ConnectException, APIException {
107 TimeTaken tt = trans.start("AAF Perm Details",Env.REMOTE);
109 Future<Perms> fp= client.read("/authz/perms/"+pType + '/' + pInstance + '/' + pAction,gui.getDF(Perms.class));
111 if (fp.get(AAF_GUI.TIMEOUT)) {
113 tt = trans.start("Load Data", Env.SUB);
114 List<Perm> ps = fp.value.getPerm();
116 Perm perm = fp.value.getPerm().get(0);
117 String desc = (perm.getDescription()!=null?perm.getDescription():BLANK);
118 rv.add(new AbsCell[]{new TextCell("Description:"),new TextCell(desc)});
120 for (String r : perm.getRoles()) {
123 rv.add(new AbsCell[] {
124 new TextCell("Associated Roles:"),
128 rv.add(new AbsCell[] {
135 String historyLink = PermHistory.HREF
136 + "?type=" + pType + "&instance=" + pInstance + "&action=" + pAction;
138 rv.add(new AbsCell[] {new RefCell("See History",historyLink,false)});
140 rv.add(new AbsCell[] {new TextCell(
141 fp.code()==HttpStatus.NOT_FOUND_404?
142 "*** Implicit Permission ***":
143 "*** Data Unavailable ***"
153 } catch (Exception e) {
156 return new Cells(rv,null);