use of cz.metacentrum.perun.webgui.json.attributesManager.GetLogins in project perun by CESNET.
the class PasswordResetFormPage method getContent.
/**
* Returns page content
*
* @return page content
*/
public Widget getContent() {
bodyContents.clear();
final VerticalPanel vp = new VerticalPanel();
vp.setSize("50%", "50%");
vp.getElement().setAttribute("style", "margin: auto; position: relative; top: 50px;");
bodyContents.setWidget(vp);
// if using backup pwd-reset option, draw different content
if (Location.getParameterMap().keySet().contains("m") && Location.getParameterMap().keySet().contains("i") && session.getRpcUrl().startsWith("/non/rpc")) {
return drawNonAuthzPasswordReset(vp);
}
if (Location.getParameter("login-namespace") != null && !Location.getParameter("login-namespace").isEmpty()) {
namespace = Location.getParameter("login-namespace");
} else {
namespace = "";
}
final Label headerLabel = new Label();
final ExtendedPasswordBox passBox = new ExtendedPasswordBox();
final ExtendedPasswordBox secondPassBox = new ExtendedPasswordBox();
final ExtendedTextBox.TextBoxValidator validator;
final ExtendedTextBox.TextBoxValidator validator2;
final CustomButton resetPass = new CustomButton("Reset password", "Reset password in namespace: " + namespace, SmallIcons.INSTANCE.keyIcon());
validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (passBox.getTextBox().getValue().trim().isEmpty()) {
passBox.setError("Password can't be empty !");
return false;
} else if (!passBox.getTextBox().getValue().trim().equals(secondPassBox.getTextBox().getValue().trim())) {
passBox.setError("Password in both textboxes must be the same !");
return false;
} else {
passBox.setOk();
secondPassBox.setOk();
return true;
}
}
};
validator2 = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (secondPassBox.getTextBox().getValue().trim().isEmpty()) {
secondPassBox.setError("Password can't be empty !");
return false;
} else if (!secondPassBox.getTextBox().getValue().trim().equals(passBox.getTextBox().getValue().trim())) {
secondPassBox.setError("Password in both textboxes must be the same !");
return false;
} else {
secondPassBox.setOk();
passBox.setOk();
return true;
}
}
};
passBox.setValidator(validator);
secondPassBox.setValidator(validator2);
FlexTable ft = new FlexTable();
ft.setSize("300px", "100px");
ft.addStyleName("inputFormFlexTable");
ft.getElement().setAttribute("style", "margin: auto;");
ft.setHTML(1, 0, "New password:");
ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
ft.setWidget(1, 1, passBox);
ft.setHTML(2, 0, "Retype new password:");
ft.getFlexCellFormatter().setStyleName(2, 0, "itemName");
ft.setWidget(2, 1, secondPassBox);
final FlexTable header = new FlexTable();
header.setWidget(0, 0, new AjaxLoaderImage());
header.setWidget(0, 1, headerLabel);
GetLogins loginsCall = new GetLogins(session.getUser().getId(), new JsonCallbackEvents() {
@Override
public void onError(PerunError error) {
bodyContents.clear();
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>Error occurred when getting your login from Perun. Please, reload page to retry.</h2><p>" + error.getErrorId() + ": " + error.getErrorInfo() + "</p>");
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
bodyContents.setWidget(ft);
}
@Override
public void onFinished(JavaScriptObject jso) {
header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.keyIcon()));
logins = JsonUtils.jsoAsList(jso);
if (logins != null && !logins.isEmpty()) {
for (Attribute a : logins) {
// if have login in namespace
if (a.getFriendlyNameParameter().equals(namespace)) {
boolean found = false;
for (String name : Utils.getSupportedPasswordNamespaces()) {
if (a.getFriendlyNameParameter().equalsIgnoreCase(name)) {
found = true;
}
}
if (found) {
// HAVE LOGIN AND SUPPORTED
headerLabel.setText("Password reset for " + a.getValue() + "@" + namespace);
return;
} else {
// NOT SUPPORTED
bodyContents.clear();
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>Password reset in selected namespace is not supported !</h2>");
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
bodyContents.setWidget(ft);
return;
}
}
}
}
// DO NOT HAVE LOGIN IN NAMESPACE
bodyContents.clear();
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
if (namespace != null && !namespace.isEmpty()) {
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>You don't have login in selected namespace !</h2>");
} else {
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>You must specify login-namespace in URL !</h2>");
}
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
bodyContents.setWidget(ft);
}
});
loginsCall.retrieveData();
resetPass.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ChangePassword changepw = new ChangePassword(JsonCallbackEvents.disableButtonEvents(resetPass, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
bodyContents.clear();
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.acceptIcon()) + "<h2>Password successfully changed!</h2>");
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
ft.setHTML(1, 0, "<h2>New password will work on all resources in approx. 15 minutes after reset.</h2>");
ft.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
bodyContents.setWidget(ft);
}
}), false);
if (validator.validateTextBox() && validator2.validateTextBox()) {
changepw.changePassword(session.getUser(), namespace, "", passBox.getTextBox().getText().trim());
}
}
});
headerLabel.setText("Password reset for ");
headerLabel.setStyleName("now-managing");
vp.add(header);
vp.add(ft);
TabMenu menu = new TabMenu();
menu.addWidget(resetPass);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
return bodyContents;
}
use of cz.metacentrum.perun.webgui.json.attributesManager.GetLogins 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, a.getValue());
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>" + a.getLogin() + "</strong>");
tab.setHTML(i++, 0, "Issuer: " + a.getExtSource().getName());
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.json.attributesManager.GetLogins in project perun by CESNET.
the class SendPasswordResetRequestTabItem method draw.
public Widget draw() {
this.titleWidget.setText("Send password reset request");
VerticalPanel vp = new VerticalPanel();
vp.setSize("300px", "100%");
final FlexTable layout = new FlexTable();
layout.setSize("100%", "100%");
layout.setStyleName("inputFormFlexTable");
layout.setHTML(0, 0, "Select namespace:");
layout.getFlexCellFormatter().setStyleName(0, 0, "itemName");
layout.setHTML(1, 0, "Login:");
layout.getFlexCellFormatter().setStyleName(1, 0, "itemName");
final ListBox namespaces = new ListBox();
layout.setWidget(0, 1, namespaces);
final CustomButton changeButton = new CustomButton("Send", "Send email with reset password link", SmallIcons.INSTANCE.emailIcon());
GetLogins logins = new GetLogins(member.getUserId(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
namespaces.clear();
ArrayList<Attribute> logins = JsonUtils.jsoAsList(jso);
if (logins != null && !logins.isEmpty()) {
changeButton.setEnabled(true);
for (Attribute a : logins) {
if (Utils.getSupportedPasswordNamespaces().contains(a.getFriendlyNameParameter())) {
namespaces.addItem(a.getFriendlyNameParameter().toUpperCase(), a.getValue());
layout.setHTML(1, 1, a.getValue());
}
}
}
}
public void onLoadingStart() {
changeButton.setEnabled(false);
namespaces.clear();
namespaces.addItem("Loading...");
}
public void onError(PerunError error) {
namespaces.clear();
namespaces.addItem("Error while loading");
}
});
logins.retrieveData();
namespaces.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
layout.setHTML(1, 1, namespaces.getValue(namespaces.getSelectedIndex()));
}
});
TabMenu menu = new TabMenu();
final TabItem tab = this;
// by default false
changeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
SendPasswordResetLinkEmail request = new SendPasswordResetLinkEmail(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab));
request.sendEmail(member, namespaces.getItemText(namespaces.getSelectedIndex()).toLowerCase());
}
});
menu.addWidget(changeButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, ButtonTranslation.INSTANCE.cancelButton(), new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations