1 /*******************************************************************************
2 * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
3 *******************************************************************************/
4 package com.att.authz.gui.pages;
6 import java.io.IOException;
7 import java.net.ConnectException;
8 import java.util.ArrayList;
11 import com.att.aft.dme2.internal.jetty.http.HttpStatus;
12 import com.att.authz.env.AuthzEnv;
13 import com.att.authz.env.AuthzTrans;
14 import com.att.authz.gui.AuthGUI;
15 import com.att.authz.gui.BreadCrumbs;
16 import com.att.authz.gui.Page;
17 import com.att.authz.gui.Table;
18 import com.att.authz.gui.Table.Cells;
19 import com.att.authz.gui.table.AbsCell;
20 import com.att.authz.gui.table.RefCell;
21 import com.att.authz.gui.table.TextCell;
22 import com.att.cadi.CadiException;
23 import com.att.cadi.client.Future;
24 import com.att.cadi.client.Rcli;
25 import com.att.cadi.client.Retryable;
26 import com.att.inno.env.APIException;
27 import com.att.inno.env.Env;
28 import com.att.inno.env.Slot;
29 import com.att.inno.env.TimeTaken;
32 import aaf.v2_0.Perms;
35 * Detail Page for Permissions
38 public class PermDetail extends Page {
39 public static final String HREF = "/gui/permdetail";
40 public static final String NAME = "PermDetail";
41 private static final String BLANK = "";
43 public PermDetail(final AuthGUI gui, Page ... breadcrumbs) throws APIException, IOException {
44 super(gui.env, NAME, HREF, new String[] {"type","instance","action"},
45 new BreadCrumbs(breadcrumbs),
46 new Table<AuthGUI,AuthzTrans>("Permission Details",gui.env.newTransNoAvg(),new Model(gui.env()),"class=detail")
51 * Implement the table content for Permissions Detail
55 private static class Model implements Table.Data<AuthGUI,AuthzTrans> {
56 private static final String[] headers = new String[0];
57 private Slot type, instance, action;
58 public Model(AuthzEnv env) {
59 type = env.slot(NAME+".type");
60 instance = env.slot(NAME+".instance");
61 action = env.slot(NAME+".action");
65 public String[] headers() {
70 public Cells get(final AuthGUI gui, final AuthzTrans trans) {
71 final String pType = trans.get(type, null);
72 final String pInstance = trans.get(instance, null);
73 final String pAction = trans.get(action, null);
74 if(pType==null || pInstance==null || pAction==null) {
77 ArrayList<AbsCell[]> rv = new ArrayList<AbsCell[]>();
78 rv.add(new AbsCell[]{new TextCell("Type:"),new TextCell(pType)});
79 rv.add(new AbsCell[]{new TextCell("Instance:"),new TextCell(pInstance)});
80 rv.add(new AbsCell[]{new TextCell("Action:"),new TextCell(pAction)});
82 gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
84 public Void code(Rcli<?> client)throws CadiException, ConnectException, APIException {
85 TimeTaken tt = trans.start("AAF Perm Details",Env.REMOTE);
87 Future<Perms> fp= client.read("/authz/perms/"+pType + '/' + pInstance + '/' + pAction,gui.permsDF);
89 if(fp.get(AuthGUI.TIMEOUT)) {
91 tt = trans.start("Load Data", Env.SUB);
92 List<Perm> ps = fp.value.getPerm();
94 Perm perm = fp.value.getPerm().get(0);
95 String desc = (perm.getDescription()!=null?perm.getDescription():BLANK);
96 rv.add(new AbsCell[]{new TextCell("Description:"),new TextCell(desc)});
98 for(String r : perm.getRoles()) {
101 rv.add(new AbsCell[] {
102 new TextCell("Associated Roles:"),
106 rv.add(new AbsCell[] {
113 String historyLink = PermHistory.HREF
114 + "?type=" + pType + "&instance=" + pInstance + "&action=" + pAction;
116 rv.add(new AbsCell[] {new RefCell("See History",historyLink)});
118 rv.add(new AbsCell[] {new TextCell(
119 fp.code()==HttpStatus.NOT_FOUND_404?
120 "*** Implicit Permission ***":
121 "*** Data Unavailable ***"
131 } catch (Exception e) {
134 return new Cells(rv,null);