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";
61 private static SimpleDateFormat expiresDF;
64 expiresDF = new SimpleDateFormat(DATE_TIME_FORMAT);
67 public RolesShow(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
68 super(gui.env, "MyRoles",HREF, NO_FIELDS,
69 new BreadCrumbs(breadcrumbs),
70 new Table<AAF_GUI,AuthzTrans>("Roles",gui.env.newTransNoAvg(),new Model(), "class=std"));
74 * Implement the Table Content for Permissions by User
79 private static class Model extends TableData<AAF_GUI,AuthzTrans> {
80 private static final String[] headers = new String[] {"Role","Expires","Remediation","Actions"};
83 public String[] headers() {
88 public Cells get(final AuthzTrans trans, final AAF_GUI gui) {
89 Cells rv = Cells.EMPTY;
92 rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Cells>() {
94 public Cells code(Rcli<?> client) throws CadiException, ConnectException, APIException {
95 ArrayList<AbsCell[]> rv = new ArrayList<AbsCell[]>();
96 TimeTaken tt = trans.start("AAF Roles by User",Env.REMOTE);
98 Future<UserRoles> fur = client.read("/authz/userRoles/user/"+trans.user(),gui.getDF(UserRoles.class));
100 if(fur.value != null) for (UserRole u : fur.value.getUserRole()) {
101 if(u.getExpires().compare(Chrono.timeStamp()) < 0) {
102 AbsCell[] sa = new AbsCell[] {
103 new TextCell(u.getRole() + "*", "class=expired"),
104 new TextCell(expiresDF.format(u.getExpires().toGregorianCalendar().getTime()),"class=expired"),
105 new RefCell("Extend",
106 UserRoleExtend.HREF + "?user="+trans.user()+"&role="+u.getRole(),
108 new String[]{"class=expired"}),
109 new RefCell("Remove",
110 UserRoleRemove.HREF + "?user="+trans.user()+"&role="+u.getRole(),
112 new String[]{"class=expired"})
117 AbsCell[] sa = new AbsCell[] {
118 new RefCell(u.getRole(),
119 RoleDetail.HREF+"?role="+u.getRole(),
121 new TextCell(expiresDF.format(u.getExpires().toGregorianCalendar().getTime())),
123 new RefCell("Remove",
124 UserRoleRemove.HREF + "?user="+trans.user()+"&role="+u.getRole(),
135 return new Cells(rv,null);
138 } catch (Exception e) {
139 trans.error().log(e);