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.text.SimpleDateFormat;
9 import java.util.ArrayList;
11 import com.att.authz.env.AuthzTrans;
12 import com.att.authz.gui.AuthGUI;
13 import com.att.authz.gui.BreadCrumbs;
14 import com.att.authz.gui.Page;
15 import com.att.authz.gui.Table;
16 import com.att.authz.gui.Table.Cells;
17 import com.att.authz.gui.table.AbsCell;
18 import com.att.authz.gui.table.RefCell;
19 import com.att.authz.gui.table.TextCell;
20 import org.onap.aaf.cadi.CadiException;
21 import org.onap.aaf.cadi.client.Future;
22 import org.onap.aaf.cadi.client.Rcli;
23 import org.onap.aaf.cadi.client.Retryable;
24 import org.onap.aaf.inno.env.APIException;
25 import org.onap.aaf.inno.env.Env;
26 import org.onap.aaf.inno.env.TimeTaken;
27 import org.onap.aaf.inno.env.util.Chrono;
29 import aaf.v2_0.UserRole;
30 import aaf.v2_0.UserRoles;
34 * Page content for My Roles
38 public class RolesShow extends Page {
39 public static final String HREF = "/gui/myroles";
40 private static final String DATE_TIME_FORMAT = "yyyy-MM-dd";
41 private static SimpleDateFormat expiresDF;
44 expiresDF = new SimpleDateFormat(DATE_TIME_FORMAT);
47 public RolesShow(final AuthGUI gui, final Page ... breadcrumbs) throws APIException, IOException {
48 super(gui.env, "MyRoles",HREF, NO_FIELDS,
49 new BreadCrumbs(breadcrumbs),
50 new Table<AuthGUI,AuthzTrans>("Roles",gui.env.newTransNoAvg(),new Model(), "class=std"));
54 * Implement the Table Content for Permissions by User
58 private static class Model implements Table.Data<AuthGUI,AuthzTrans> {
59 private static final String[] headers = new String[] {"Role","Expires","Remediation","Actions"};
62 public String[] headers() {
67 public Cells get(final AuthGUI gui, final AuthzTrans trans) {
68 Cells rv = Cells.EMPTY;
71 rv = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Cells>() {
73 public Cells code(Rcli<?> client) throws CadiException, ConnectException, APIException {
74 ArrayList<AbsCell[]> rv = new ArrayList<AbsCell[]>();
75 TimeTaken tt = trans.start("AAF Roles by User",Env.REMOTE);
77 Future<UserRoles> fur = client.read("/authz/userRoles/user/"+trans.user(),gui.userrolesDF);
79 if(fur.value != null) for (UserRole u : fur.value.getUserRole()) {
80 if(u.getExpires().compare(Chrono.timeStamp()) < 0) {
81 AbsCell[] sa = new AbsCell[] {
82 new TextCell(u.getRole() + "*", "class=expired"),
83 new TextCell(expiresDF.format(u.getExpires().toGregorianCalendar().getTime()),"class=expired"),
85 UserRoleExtend.HREF + "?user="+trans.user()+"&role="+u.getRole(),
86 new String[]{"class=expired"}),
88 UserRoleRemove.HREF + "?user="+trans.user()+"&role="+u.getRole(),
89 new String[]{"class=expired"})
94 AbsCell[] sa = new AbsCell[] {
95 new RefCell(u.getRole(),
96 RoleDetail.HREF+"?role="+u.getRole()),
97 new TextCell(expiresDF.format(u.getExpires().toGregorianCalendar().getTime())),
100 UserRoleRemove.HREF + "?user="+trans.user()+"&role="+u.getRole())
110 return new Cells(rv,null);
113 } catch (Exception e) {
114 trans.error().log(e);