use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class ApplicationFormPage method tryToFindUserByName.
/**
* Try to find user by name
*
* If user found, message box shown
*
* @param jso returned data
*/
private void tryToFindUserByName(JavaScriptObject jso) {
// try to find
JsonPostClient jspc = new JsonPostClient(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
ArrayList<Identity> users = JsonUtils.<Identity>jsoAsList(jso);
if (users != null && !users.isEmpty())
similarUsersFound(users);
}
});
JSONObject query = new JSONObject();
if (jso == null) {
// before app submission
jspc.sendData("registrarManager/checkForSimilarUsers", query);
} else {
// after app submission
query.put("voId", new JSONNumber(vo.getId()));
if (group != null) {
query.put("groupId", new JSONNumber(group.getId()));
} else {
query.put("groupId", new JSONNumber(0));
}
query.put("type", new JSONString(type));
jspc.sendData("registrarManager/checkForSimilarUsers", query);
}
}
use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class ApplicationFormPage method sendForm.
/**
* Send form
*/
protected void sendForm(final CustomButton button) {
PerunPrincipal pp = session.getPerunPrincipal();
// fed info
String fedInfo = "";
fedInfo += "{";
fedInfo += " displayName=\"" + pp.getAdditionInformations("displayName") + "\"";
fedInfo += " commonName=\"" + pp.getAdditionInformations("cn") + "\"";
fedInfo += " givenName=\"" + pp.getAdditionInformations("givenName") + "\"";
fedInfo += " sureName=\"" + pp.getAdditionInformations("sn") + "\"";
fedInfo += " loa=\"" + pp.getAdditionInformations("loa") + "\"";
fedInfo += " mail=\"" + pp.getAdditionInformations("mail") + "\"";
fedInfo += " organization=\"" + pp.getAdditionInformations("o") + "\"";
fedInfo += " }";
Application app = Application.construct(vo, group, type, fedInfo, pp.getActor(), pp.getExtSource(), pp.getExtSourceType(), pp.getExtSourceLoa());
if (session.getUser() != null) {
// set user association if known from perun
app.setUser(session.getUser());
}
// loading
final PopupPanel loadingBox = session.getUiElements().perunLoadingBox(ApplicationMessages.INSTANCE.processing());
// Create application request
CreateApplication ca = new CreateApplication(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {
@Override
public void onLoadingStart() {
// show loading box
loadingBox.show();
}
@Override
public void onFinished(JavaScriptObject jso) {
loadingBox.hide();
formOk(jso);
}
@Override
public void onError(PerunError err) {
loadingBox.hide();
formError(err);
}
}));
// Send the request
ca.createApplication(app, data);
}
use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class UsersApplicationsPage method refresh.
/**
* Refresh the page
*/
private void refresh() {
bodyContents.clear();
String user = "";
if (session.getUser() != null) {
user = this.session.getUser().getFullNameWithTitles().trim();
} else {
PerunPrincipal pp = session.getPerunPrincipal();
if (!pp.getAdditionInformations("displayName").equals("")) {
user = pp.getAdditionInformations("displayName");
} else if (!pp.getAdditionInformations("cn").equals("")) {
user = pp.getAdditionInformations("cn");
} else {
if (pp.getExtSourceType().equals("cz.metacentrum.perun.core.impl.ExtSourceX509")) {
user = Utils.convertCertCN(pp.getActor());
} else {
user = pp.getActor();
}
}
}
bodyContents.add(new HTML("<h1>" + ApplicationMessages.INSTANCE.applicationsForUser(user) + "</h1>"));
// callback
int userId = 0;
if (session.getUser() != null) {
userId = session.getUser().getId();
}
final GetApplicationsForUserForAppFormGui req = new GetApplicationsForUserForAppFormGui(userId);
final ListBox listBox = new ListBox();
req.setEvents(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
ArrayList<Application> appls = JsonUtils.jsoAsList(jso);
ArrayList<String> vos = new ArrayList<String>();
for (Application app : appls) {
if (!vos.contains(app.getVo().getName())) {
vos.add(app.getVo().getName());
}
}
Collections.sort(vos);
for (String s : vos) {
listBox.addItem(s);
}
if (listBox.getItemCount() > 0) {
listBox.insertItem(WidgetTranslation.INSTANCE.listboxAll(), 0);
}
for (int i = 0; i < listBox.getItemCount(); i++) {
if (listBox.getItemText(i).equals(ApplicationFormGui.getVo().getName())) {
listBox.setSelectedIndex(i);
req.filterTable(ApplicationFormGui.getVo().getName());
break;
}
}
}
@Override
public void onError(PerunError error) {
}
@Override
public void onLoadingStart() {
listBox.clear();
}
});
req.setCheckable(false);
listBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (listBox.getSelectedIndex() > 0) {
req.filterTable(listBox.getItemText(listBox.getSelectedIndex()));
} else {
// show all
req.filterTable("");
}
}
});
final TabMenu tabMenu = new TabMenu();
tabMenu.addWidget(new HTML("<strong>" + ApplicationMessages.INSTANCE.filterByVo() + ":</strong>"));
tabMenu.addWidget(listBox);
tabMenu.addWidget(new Image(SmallIcons.INSTANCE.helpIcon()));
tabMenu.addWidget(new HTML("<strong>" + ApplicationMessages.INSTANCE.clickOnApplicationToSee() + "</strong>"));
tabMenu.addStyleName("tabMenu");
final VerticalPanel applicationsWrapper = new VerticalPanel();
applicationsWrapper.setSize("100%", "100%");
applicationsWrapper.add(tabMenu);
final CellTable<Application> appsTable = req.getTable(new FieldUpdater<Application, String>() {
public void update(int index, Application object, String value) {
applicationsWrapper.clear();
applicationsWrapper.add(backButton);
applicationsWrapper.add(getApplicationDetailWidget(object));
}
});
appsTable.addStyleName("perun-table");
applicationsWrapper.add(appsTable);
backButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
applicationsWrapper.clear();
applicationsWrapper.add(tabMenu);
applicationsWrapper.add(appsTable);
}
});
bodyContents.add(applicationsWrapper);
}
use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class ApplicationFormLeftMenu method addLogoutItem.
public void addLogoutItem() {
// if not anonymous identity
if (!PerunWebSession.getInstance().getRpcUrl().startsWith("/non/rpc")) {
int i = menuContents.getRowCount();
menuContents.setWidget(i, 0, new Image(SmallIcons.INSTANCE.doorOutIcon()));
Anchor a = new Anchor(ApplicationMessages.INSTANCE.logout());
a.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Logout call = new Logout(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
Utils.clearFederationCookies();
History.newItem("logout");
RootLayoutPanel.get().clear();
RootLayoutPanel.get().add(new LogoutWidget());
}
});
call.retrieveData();
}
});
menuContents.setWidget(i, 1, a);
}
}
use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents 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;
}
Aggregations