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.text.SimpleDateFormat;
27 import java.util.ArrayList;
29 import org.onap.aaf.auth.env.AuthzTrans;
30 import org.onap.aaf.auth.gui.AAF_GUI;
31 import org.onap.aaf.auth.gui.BreadCrumbs;
32 import org.onap.aaf.auth.gui.Page;
33 import org.onap.aaf.auth.gui.Table;
34 import org.onap.aaf.auth.gui.Table.Cells;
35 import org.onap.aaf.auth.gui.table.AbsCell;
36 import org.onap.aaf.auth.gui.table.RefCell;
37 import org.onap.aaf.auth.gui.table.TableData;
38 import org.onap.aaf.auth.gui.table.TextCell;
39 import org.onap.aaf.cadi.CadiException;
40 import org.onap.aaf.cadi.client.Future;
41 import org.onap.aaf.cadi.client.Rcli;
42 import org.onap.aaf.cadi.client.Retryable;
43 import org.onap.aaf.misc.env.APIException;
44 import org.onap.aaf.misc.env.Env;
45 import org.onap.aaf.misc.env.TimeTaken;
46 import org.onap.aaf.misc.env.util.Chrono;
48 import aaf.v2_0.UserRole;
49 import aaf.v2_0.UserRoles;
53 * Page content for My Roles
58 public class RolesShow extends Page {
59 public static final String HREF = "/gui/myroles";
60 private static final String DATE_TIME_FORMAT = "yyyy-MM-dd";
62 public RolesShow(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
63 super(gui.env, "MyRoles",HREF, NO_FIELDS,
64 new BreadCrumbs(breadcrumbs),
65 new Table<AAF_GUI,AuthzTrans>("Roles",gui.env.newTransNoAvg(),new Model(), "class=std"));
69 * Implement the Table Content for Permissions by User
74 private static class Model extends TableData<AAF_GUI,AuthzTrans> {
75 private static final String[] headers = new String[] {"Role","Expires","Remediation","Actions"};
76 private static final String ROLE = "&role=";
77 private static final String USER = "?user=";
78 private static final String CLASS_EXPIRED = "class=expired";
81 public String[] headers() {
86 public Cells get(final AuthzTrans trans, final AAF_GUI gui) {
87 Cells rv = Cells.EMPTY;
90 rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Cells>() {
92 public Cells code(Rcli<?> client) throws CadiException, ConnectException, APIException {
93 ArrayList<AbsCell[]> rv = new ArrayList<>();
94 TimeTaken tt = trans.start("AAF Roles by User",Env.REMOTE);
96 Future<UserRoles> fur = client.read("/authz/userRoles/user/"+trans.user(),gui.getDF(UserRoles.class));
97 if (fur.get(5000) && fur.value != null) for (UserRole u : fur.value.getUserRole()) {
98 if (u.getExpires().compare(Chrono.timeStamp()) < 0) {
99 AbsCell[] sa = new AbsCell[] {
100 new TextCell(u.getRole() + "*", CLASS_EXPIRED),
101 new TextCell(new SimpleDateFormat(DATE_TIME_FORMAT).format(u.getExpires().toGregorianCalendar().getTime()),CLASS_EXPIRED),
102 new RefCell("Extend",
103 UserRoleExtend.HREF+USER+trans.user()+ROLE+u.getRole(),
105 new String[]{CLASS_EXPIRED}),
106 new RefCell("Remove",
107 UserRoleRemove.HREF+USER +trans.user()+ROLE+u.getRole(),
109 new String[]{CLASS_EXPIRED})
114 AbsCell[] sa = new AbsCell[] {
115 new RefCell(u.getRole(),
116 RoleDetail.HREF+"?role="+u.getRole(),
118 new TextCell(new SimpleDateFormat(DATE_TIME_FORMAT).format(u.getExpires().toGregorianCalendar().getTime())),
120 new RefCell("Remove",
121 UserRoleRemove.HREF+USER+trans.user()+ROLE+u.getRole(),
131 return new Cells(rv,null);
134 } catch (Exception e) {
135 trans.error().log(e);