use of cz.metacentrum.perun.webgui.model.UserExtSource in project perun by CESNET.
the class SelfAuthenticationsTabItem method draw.
public Widget draw() {
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": Authentication");
final String notSet = "<i>N/A</i>";
// content
ScrollPanel vp = new ScrollPanel();
vp.setSize("100%", "100%");
final VerticalPanel innerVp = new VerticalPanel();
innerVp.setSize("100%", "100%");
final TabMenu menu = new TabMenu();
innerVp.add(menu);
innerVp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
final FlexTable layout = new FlexTable();
layout.setSize("100%", "100%");
vp.add(innerVp);
innerVp.add(layout);
layout.setStyleName("perun-table");
vp.setStyleName("perun-tableScrollPanel");
session.getUiElements().resizeSmallTabPanel(vp, 350, this);
FlexTable loginsHeader = new FlexTable();
loginsHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.keyIcon()));
loginsHeader.setHTML(0, 1, "<p>Logins");
loginsHeader.getFlexCellFormatter().setStyleName(0, 1, "subsection-heading");
layout.setWidget(0, 0, loginsHeader);
FlexTable certHeader = new FlexTable();
certHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.sslCertificatesIcon()));
certHeader.setHTML(0, 1, "<p>Certificates");
certHeader.getFlexCellFormatter().setStyleName(0, 1, "subsection-heading");
layout.setWidget(3, 0, certHeader);
layout.setHTML(4, 0, "To <strong>add certificate</strong> please visit <a href=\"" + Utils.getIdentityConsolidatorLink(false) + "\" target=\"_blank\">identity consolidator >></a> and select \"Using personal certificate\" option.<br /> ");
FlexTable sshHeader = new FlexTable();
sshHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.serverKeyIcon()));
sshHeader.setHTML(0, 1, "<p>Kerberos & SSH keys");
sshHeader.getFlexCellFormatter().setStyleName(0, 1, "subsection-heading");
layout.setWidget(6, 0, sshHeader);
// login table
final FlexTable loginsTable = new FlexTable();
loginsTable.setStyleName("inputFormFlexTableDark");
final GetLogins logins = new GetLogins(userId, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
final ArrayList<Attribute> list = JsonUtils.jsoAsList(jso);
layout.setWidget(1, 0, loginsTable);
int row = 0;
if (user.isServiceUser() || user.isSponsoredUser()) {
CustomButton addLogin = TabMenu.getPredefinedButton(ButtonType.ADD, "Add new login (only for supported namespaces)");
addLogin.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new AddLoginTabItem(user, list));
}
});
loginsTable.setWidget(row, 0, addLogin);
row++;
}
if (list != null && !list.isEmpty()) {
for (final Attribute a : list) {
loginsTable.setHTML(row, 0, "Login in " + a.getFriendlyNameParameter().toUpperCase() + ":");
loginsTable.getFlexCellFormatter().setWidth(row, 0, "150px");
loginsTable.getFlexCellFormatter().addStyleName(row, 0, "itemName");
loginsTable.setHTML(row, 1, SafeHtmlUtils.fromString((a.getValue() != null) ? a.getValue() : "").asString());
loginsTable.getFlexCellFormatter().setWidth(row, 1, "150px");
// change password if possible
if (Utils.getSupportedPasswordNamespaces().contains(a.getFriendlyNameParameter())) {
FlexTable fw = new FlexTable();
fw.addStyleName("padding-vertical");
CustomButton cb = new CustomButton("Change password…", SmallIcons.INSTANCE.keyIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new SelfPasswordTabItem(user, a.getFriendlyNameParameter(), a.getValue(), SelfPasswordTabItem.Actions.CHANGE));
}
});
CustomButton cb2 = new CustomButton("Reset password…", SmallIcons.INSTANCE.keyIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
// OPEN PASSWORD RESET APPLICATION ON SAME SERVER
Window.open("" + Utils.getPasswordResetLink(a.getFriendlyNameParameter()), "_blank", "");
}
});
fw.setWidget(0, 0, cb);
if (!user.isServiceUser()) {
fw.setWidget(0, 1, cb2);
} else {
cb.setText("Reset password…");
}
loginsTable.setWidget(row, 2, fw);
}
row++;
}
} else {
loginsTable.setHTML(row, 0, "You don't have any login in supported namespaces.");
loginsTable.getFlexCellFormatter().setStyleName(0, 0, "inputFormInlineComment");
}
}
@Override
public void onLoadingStart() {
layout.setWidget(1, 0, new AjaxLoaderImage().loadingStart());
}
@Override
public void onError(PerunError error) {
layout.setHTML(1, 0, "Error while loading logins.");
layout.getFlexCellFormatter().setStyleName(1, 0, "serverResponseLabelError");
}
});
logins.retrieveData();
// certificates table
final FlexTable certTable = new FlexTable();
certTable.addStyleName("inputFormFlexTableDark");
certTable.setHTML(0, 0, "Certificates: ");
certTable.getFlexCellFormatter().addStyleName(0, 0, "itemName");
certTable.getFlexCellFormatter().setWidth(0, 0, "150px");
layout.setWidget(5, 0, certTable);
final GetUserExtSources ueses = new GetUserExtSources(userId);
ueses.setEvents(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
ArrayList<UserExtSource> list = JsonUtils.jsoAsList(jso);
if (list != null && !list.isEmpty()) {
boolean found = false;
FlexTable tab = new FlexTable();
// rowcounter
int i = 0;
for (final UserExtSource a : list) {
if (a.getExtSource().getType().equals("cz.metacentrum.perun.core.impl.ExtSourceX509")) {
found = true;
tab.setHTML(i++, 0, "<strong>" + SafeHtmlUtils.fromString((a.getLogin() != null) ? a.getLogin() : "").asString() + "</strong>");
tab.setHTML(i++, 0, "Issuer: " + SafeHtmlUtils.fromString((a.getExtSource().getName() != null) ? a.getExtSource().getName() : "").asString());
if (!a.isPersistent()) {
CustomButton removeButton = new CustomButton("Remove", SmallIcons.INSTANCE.deleteIcon(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
RemoveUserExtSource remove = new RemoveUserExtSource(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// reload whole tab
ueses.retrieveData();
}
});
remove.removeUserExtSource(userId, a.getId());
}
});
// add button to table
tab.getFlexCellFormatter().setRowSpan(i - 2, 1, 2);
tab.setWidget(i - 2, 1, removeButton);
}
}
}
if (found) {
certTable.setWidget(0, 1, tab);
} else {
certTable.setHTML(0, 1, notSet);
}
} else {
certTable.setHTML(0, 1, notSet);
}
}
@Override
public void onError(PerunError error) {
certTable.setHTML(0, 1, "Error while loading certificates. Refresh page to retry.");
certTable.getFlexCellFormatter().setStyleName(0, 1, "serverResponseLabelError");
}
@Override
public void onLoadingStart() {
certTable.setWidget(0, 1, new Image(AjaxLoaderImage.SMALL_IMAGE_URL));
}
});
ueses.retrieveData();
// Kerberos and SSH table
Map<String, Integer> ids = new HashMap<>();
ids.put("user", userId);
final PerunAttributeTableWidget table = new PerunAttributeTableWidget(ids);
table.setDark(true);
table.setDescriptionShown(true);
final GetListOfAttributes attrs2 = new GetListOfAttributes(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
table.add(JsonUtils.<Attribute>jsoAsList(jso));
layout.setWidget(7, 0, table);
}
@Override
public void onError(PerunError error) {
layout.setHTML(7, 0, "Error while loading Kerberos and SSH settings. Refresh page to retry.");
layout.getFlexCellFormatter().setStyleName(7, 0, "serverResponseLabelError");
}
@Override
public void onLoadingStart() {
layout.setWidget(7, 0, new AjaxLoaderImage().loadingStart());
}
});
ArrayList<String> list2 = new ArrayList<String>();
list2.add("urn:perun:user:attribute-def:def:kerberosAdminPrincipal");
list2.add("urn:perun:user:attribute-def:def:sshPublicAdminKey");
list2.add("urn:perun:user:attribute-def:def:sshPublicKey");
attrs2.getListOfAttributes(ids, list2);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.UserExtSource in project perun by CESNET.
the class GetUserExtSources method getTable.
/**
* Return table with checkboxes containing user external sources
*
* @return table containing user ext sources
*/
public CellTable<UserExtSource> getTable() {
// retrieve data
retrieveData();
// Table data provider.
dataProvider = new ListDataProvider<UserExtSource>(list);
// Cell table
table = new PerunTable<UserExtSource>(list);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<UserExtSource> columnSortHandler = new ListHandler<UserExtSource>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<UserExtSource>createCheckboxManager());
// set empty content & loader
table.setEmptyTableWidget(loaderImage);
// checkbox column column
com.google.gwt.user.cellview.client.Column<UserExtSource, UserExtSource> checkBoxColumn = new com.google.gwt.user.cellview.client.Column<UserExtSource, UserExtSource>(new PerunCheckboxCell<UserExtSource>(true, false, false)) {
@Override
public UserExtSource getValue(UserExtSource object) {
// Get the value from the selection model.
GeneralObject go = object.cast();
go.setChecked(selectionModel.isSelected(object));
return go.cast();
}
};
// updates the columns size
table.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);
// Add the columns
// Checkbox column header
CheckboxCell cb = new CheckboxCell();
Header<Boolean> checkBoxHeader = new Header<Boolean>(cb) {
public Boolean getValue() {
// return true to see a checked checkbox.
return false;
}
};
checkBoxHeader.setUpdater(new ValueUpdater<Boolean>() {
public void update(Boolean value) {
// sets selected to all, if value = true, unselect otherwise
for (UserExtSource obj : list) {
if (!obj.isPersistent()) {
selectionModel.setSelected(obj, value);
}
}
}
});
table.addColumn(checkBoxColumn, checkBoxHeader);
table.addIdColumn("UES ID", tableFieldUpdater, 100);
// Name column
Column<UserExtSource, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<UserExtSource, String>() {
public String getValue(UserExtSource extSource) {
return String.valueOf(extSource.getExtSource().getName());
}
}, tableFieldUpdater);
// Login column
Column<UserExtSource, String> loginColumn = JsonUtils.addColumn(new JsonUtils.GetValue<UserExtSource, String>() {
public String getValue(UserExtSource extSource) {
return String.valueOf(extSource.getLogin());
}
}, tableFieldUpdater);
// LOA column
Column<UserExtSource, String> loaColumn = JsonUtils.addColumn(new JsonUtils.GetValue<UserExtSource, String>() {
public String getValue(UserExtSource extSource) {
return String.valueOf(extSource.getLoa());
}
}, tableFieldUpdater);
// LastAccess column
Column<UserExtSource, String> lastAccessColumn = JsonUtils.addColumn(new JsonUtils.GetValue<UserExtSource, String>() {
public String getValue(UserExtSource extSource) {
if (extSource.getLastAccess() != null && !extSource.getLastAccess().isEmpty()) {
return extSource.getLastAccess().split("\\.")[0];
} else {
return "N/A";
}
}
}, tableFieldUpdater);
// sort name column
nameColumn.setSortable(true);
columnSortHandler.setComparator(nameColumn, new GeneralComparator<UserExtSource>(GeneralComparator.Column.NAME));
// sort login column
loginColumn.setSortable(true);
columnSortHandler.setComparator(loginColumn, new Comparator<UserExtSource>() {
public int compare(UserExtSource o1, UserExtSource o2) {
return o1.getLogin().compareTo(o2.getLogin());
}
});
// sort loa column
loaColumn.setSortable(true);
columnSortHandler.setComparator(loaColumn, new Comparator<UserExtSource>() {
public int compare(UserExtSource o1, UserExtSource o2) {
return o1.getLoa() - o2.getLoa();
}
});
// sort lastAccess column
lastAccessColumn.setSortable(true);
columnSortHandler.setComparator(lastAccessColumn, new Comparator<UserExtSource>() {
public int compare(UserExtSource o1, UserExtSource o2) {
String la1 = (o1.getLastAccess() != null && !o1.getLastAccess().isEmpty()) ? o1.getLastAccess().split("\\.")[0] : "N/A";
String la2 = (o2.getLastAccess() != null && !o2.getLastAccess().isEmpty()) ? o2.getLastAccess().split("\\.")[0] : "N/A";
return la1.compareTo(la2);
}
});
table.addColumn(nameColumn, "External source name");
table.addColumn(loginColumn, "ID in external source");
table.addColumn(loaColumn, "Level of assurance");
table.addColumn(lastAccessColumn, "Last access");
return table;
}
Aggregations