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;
28 import org.onap.aaf.auth.env.AuthzTrans;
29 import org.onap.aaf.auth.gui.AAF_GUI;
30 import org.onap.aaf.auth.gui.BreadCrumbs;
31 import org.onap.aaf.auth.gui.Page;
32 import org.onap.aaf.auth.gui.Table;
33 import org.onap.aaf.auth.gui.Table.Cells;
34 import org.onap.aaf.auth.gui.table.AbsCell;
35 import org.onap.aaf.auth.gui.table.RefCell;
36 import org.onap.aaf.auth.gui.table.TableData;
37 import org.onap.aaf.auth.gui.table.TextCell;
38 import org.onap.aaf.cadi.CadiException;
39 import org.onap.aaf.cadi.client.Future;
40 import org.onap.aaf.cadi.client.Rcli;
41 import org.onap.aaf.cadi.client.Retryable;
42 import org.onap.aaf.misc.env.APIException;
43 import org.onap.aaf.misc.env.Env;
44 import org.onap.aaf.misc.env.TimeTaken;
47 import aaf.v2_0.Perms;
50 * Page content for My Permissions
55 public class PermsShow extends Page {
56 public static final String HREF = "/gui/myperms";
58 public PermsShow(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
59 super(gui.env, "MyPerms",HREF, NO_FIELDS,
60 new BreadCrumbs(breadcrumbs),
61 new Table<AAF_GUI,AuthzTrans>("Permissions",gui.env.newTransNoAvg(),new Model(), "class=std"));
65 * Implement the Table Content for Permissions by User
70 private static class Model extends TableData<AAF_GUI,AuthzTrans> {
71 private static final String[] headers = new String[] {"Type","Instance","Action"};
74 public String[] headers() {
79 public Cells get(final AuthzTrans trans, final AAF_GUI gui) {
80 final ArrayList<AbsCell[]> rv = new ArrayList<>();
81 TimeTaken tt = trans.start("AAF Perms by User",Env.REMOTE);
83 gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
85 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
86 Future<Perms> fp = client.read("/authz/perms/user/"+trans.user(), gui.getDF(Perms.class));
88 TimeTaken ttld = trans.start("Load Data", Env.SUB);
91 for (Perm p : fp.value.getPerm()) {
92 AbsCell[] sa = new AbsCell[] {
93 new RefCell(p.getType(),PermDetail.HREF
95 +"&instance="+p.getInstance()
96 +"&action="+p.getAction(),
98 new TextCell(p.getInstance()),
99 new TextCell(p.getAction())
104 gui.writeError(trans, fp, null,0);
113 } catch (Exception e) {
114 trans.error().log(e);
118 return new Cells(rv,null);