use of cz.metacentrum.perun.webgui.model.PerunPrincipal 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.model.PerunPrincipal in project perun by CESNET.
the class PasswordResetGui method loadPerunPrincipal.
/**
* Performs a login into the RPC, loads user and his roles into session and enables GUI.
*/
private void loadPerunPrincipal() {
// show loading box
final PopupPanel loadingBox = session.getUiElements().perunLoadingBox();
loadingBox.show();
// events after getting PerunPrincipal from RPC
final JsonCallbackEvents events = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// store perun principal into session for future use
PerunPrincipal pp = (PerunPrincipal) jso;
session.setPerunPrincipal(pp);
// check if user exists
if (session.getUser() != null && !pp.getRoles().hasAnyRole() && !session.getRpcUrl().startsWith("/non/rpc")) {
// if not and no role, redraw page body
RootLayoutPanel body = RootLayoutPanel.get();
loadingBox.hide();
body.clear();
body.add(new NotUserOfPerunWidget());
return;
}
if (session.getUser() != null && !pp.getRoles().hasAnyRole()) {
// store users roles and editable entities into session
session.setRoles(pp.getRoles());
// display logged user
session.getUiElements().setLoggedUserInfo(pp);
}
GetGuiConfiguration getConf = new GetGuiConfiguration(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
session.setConfiguration((BasicOverlayType) jso.cast());
// hides the loading box
loadingBox.hide();
if (session.getRpcUrl().startsWith("/non/rpc")) {
// CHALLENGE WITH CAPTCHA
FlexTable ft = new FlexTable();
ft.setSize("100%", "500px");
// captcha with public key
String key = Utils.getReCaptchaPublicKey();
if (key == null) {
PerunError error = new JSONObject().getJavaScriptObject().cast();
error.setErrorId("0");
error.setName("Missing public key");
error.setErrorInfo("Public key for Re-Captcha service is missing. Please add public key to GUIs configuration file.");
error.setRequestURL("");
UiElements.generateError(error, "Missing public key", "Public key for Re-Captcha service is missing.<br />Accessing password reset without authorization is not possible.");
loadingBox.hide();
return;
}
final RecaptchaWidget captcha = new RecaptchaWidget(key, LocaleInfo.getCurrentLocale().getLocaleName(), "clean");
final CustomButton cb = new CustomButton();
cb.setIcon(SmallIcons.INSTANCE.arrowRightIcon());
cb.setText(ApplicationMessages.INSTANCE.captchaSendButton());
cb.setImageAlign(true);
final TextBox response = new TextBox();
captcha.setOwnTextBox(response);
Scheduler.get().scheduleDeferred(new Command() {
@Override
public void execute() {
response.setFocus(true);
}
});
response.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
cb.click();
}
}
});
cb.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
VerifyCaptcha req = new VerifyCaptcha(captcha.getChallenge(), captcha.getResponse(), JsonCallbackEvents.disableButtonEvents(cb, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
BasicOverlayType bt = jso.cast();
if (bt.getBoolean()) {
// OK captcha answer - load GUI
// add menu item and load content
contentPanel.setWidget(new PasswordResetFormPage().getContent());
//Anchor a = leftMenu.addMenuContents("Password reset", SmallIcons.INSTANCE.keyIcon(), new PasswordResetFormPage().getContent());
//a.fireEvent(new ClickEvent(){});
} else {
// wrong captcha answer
UiElements.generateAlert(ApplicationMessages.INSTANCE.captchaErrorHeader(), ApplicationMessages.INSTANCE.captchaErrorMessage());
}
}
}));
req.retrieveData();
}
});
// set layout
int row = 0;
ft.getFlexCellFormatter().setAlignment(row, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
ft.setHTML(row, 0, "<h2>In order to continue to the password reset page, please, use CAPTCHA below.</h2>");
ft.setWidget(row + 1, 0, captcha);
ft.getFlexCellFormatter().setHorizontalAlignment(row + 1, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(row + 1, 0, HasVerticalAlignment.ALIGN_BOTTOM);
FlexTable sendFt = new FlexTable();
sendFt.setStyleName("inputFormFlexTable");
sendFt.setWidget(0, 0, response);
sendFt.setWidget(0, 1, cb);
ft.setWidget(row + 2, 0, sendFt);
ft.getFlexCellFormatter().setHorizontalAlignment(row + 2, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(row + 2, 0, HasVerticalAlignment.ALIGN_TOP);
ft.setHeight("100%");
ft.getFlexCellFormatter().setHeight(row, 0, "50%");
ft.getFlexCellFormatter().setHeight(row + 2, 0, "50%");
// finish loading GUI
loadingBox.hide();
contentPanel.setWidget(ft);
} else {
// add menu item and load content
contentPanel.setWidget(new PasswordResetFormPage().getContent());
//Anchor a = leftMenu.addMenuContents("Password reset", SmallIcons.INSTANCE.keyIcon(), new PasswordResetFormPage().getContent());
//a.fireEvent(new ClickEvent(){});
}
}
@Override
public void onError(PerunError error) {
// hides the loading box
loadingBox.hide();
// shows error box
PopupPanel loadingFailedBox;
if (error == null) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("Request timeout exceeded.");
} else {
if (error.getName().contains("UserNotExistsException")) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("You are not registered to any Virtual Organization.</br></br>" + error.getErrorInfo());
} else {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
}
}
loadingFailedBox.show();
leftMenu.addItem("Password reset", SmallIcons.INSTANCE.keyIcon(), null);
}
});
getConf.retrieveData();
}
@Override
public void onError(PerunError error) {
// hides the loading box
loadingBox.hide();
// shows error box
PopupPanel loadingFailedBox;
if (error == null) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("Request timeout exceeded.");
} else {
if (error.getName().contains("UserNotExistsException")) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("You are not registered to any Virtual Organization.</br></br>" + error.getErrorInfo());
} else {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
}
}
loadingFailedBox.show();
leftMenu.addItem("Password reset", SmallIcons.INSTANCE.keyIcon(), null);
}
};
GetPerunPrincipal loggedUserRequest = new GetPerunPrincipal(events);
loggedUserRequest.retrieveData();
}
use of cz.metacentrum.perun.webgui.model.PerunPrincipal in project perun by CESNET.
the class GetPerunPrincipal method onFinished.
/**
* When successfully finishes
*/
public void onFinished(JavaScriptObject jso) {
PerunPrincipal pp = (PerunPrincipal) jso;
pp.setObjectType("PerunPrincipal");
session.getUiElements().setLogText("Logged as: " + pp.getActor() + " with Ext source: " + pp.getExtSource());
events.onFinished(jso);
}
use of cz.metacentrum.perun.webgui.model.PerunPrincipal in project perun by CESNET.
the class WebGui method loadPerunPrincipal.
/**
* Performs a login into the RPC, loads user and his roles into session and enables GUI.
*/
private void loadPerunPrincipal() {
// WEB PAGE SPLITTER
final DockLayoutPanel bodySplitter = new DockLayoutPanel(Unit.PX);
body.add(bodySplitter);
// MAIN CONTENT WRAPPER - make content resize-able
final ResizeLayoutPanel contentWrapper = new ResizeLayoutPanel();
contentWrapper.setSize("100%", "100%");
// MAIN CONTENT
AbsolutePanel contentPanel = new AbsolutePanel();
contentPanel.setSize("100%", "100%");
// put content into wrapper
contentWrapper.setWidget(contentPanel);
// SETUP SESSION
// store handler for main contetn's elements (tabs etc.) into session
session.setUiElements(new UiElements(contentPanel));
// Store TabManager into session for handling tabs (add/remove/close...)
session.setTabManager(new TabManager());
// Store this class into session
session.setWebGui(webgui);
// Set this class as browser's History handler
History.addValueChangeHandler(webgui);
// show loading box
final PopupPanel loadingBox = session.getUiElements().perunLoadingBox();
loadingBox.show();
// events after getting PerunPrincipal from RPC
final JsonCallbackEvents events = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// store perun principal into session for future use
final PerunPrincipal pp = (PerunPrincipal) jso;
session.setPerunPrincipal(pp);
GetGuiConfiguration getConfig = new GetGuiConfiguration(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
session.setConfiguration((BasicOverlayType) jso.cast());
String newGuiAlertContent = session.getConfiguration().getCustomProperty("newAdminGuiAlert");
if (newGuiAlertContent != null && !newGuiAlertContent.isEmpty()) {
DOM.getElementById("perun-new-gui-alert").setInnerHTML(newGuiAlertContent);
DOM.getElementById("perun-new-gui-alert").setClassName("newGuiAlertActive");
}
// check if user exists
if (session.getUser() == null && !pp.getRoles().hasAnyRole()) {
// if not and no role, redraw page body
RootLayoutPanel body = RootLayoutPanel.get();
loadingBox.hide();
body.clear();
body.add(new NotUserOfPerunWidget());
return;
}
// check if user exists
if (session.getUser().isServiceUser()) {
// if not and no role, redraw page body
RootLayoutPanel body = RootLayoutPanel.get();
loadingBox.hide();
body.clear();
body.add(new CantLogAsServiceUserWidget());
return;
}
// Sets URL mapper for loading proper tabs
urlMapper = new UrlMapper();
// MENU WRAPPER
VerticalPanel menuWrapper = new VerticalPanel();
menuWrapper.setHeight("100%");
// add menu
menuWrapper.add(session.getUiElements().getMenu().getWidget());
menuWrapper.setCellVerticalAlignment(session.getUiElements().getMenu().getWidget(), HasVerticalAlignment.ALIGN_TOP);
// Put all panels into web page splitter
// bodySplitter.addNorth(session.getUiElements().getHeader(), 78);
bodySplitter.addNorth(session.getUiElements().getHeader(), 64);
bodySplitter.addSouth(session.getUiElements().getFooter(), 30);
bodySplitter.addWest(menuWrapper, 202);
// content must be added as last !!
bodySplitter.add(contentWrapper);
// Append more GUI elements from UiElements class which are not part of splitted design
if ("true".equalsIgnoreCase(Location.getParameter("log"))) {
// log
bodySplitter.getElement().appendChild(session.getUiElements().getLog().getElement());
}
// status
bodySplitter.getElement().appendChild(session.getUiElements().getStatus().getElement());
// keep alive
VerticalPanel vp = new VerticalPanel();
vp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
vp.add(new HTML("<h2>Connection to Perun has been lost.</h2><strong>Please check your internet connection.</strong>"));
final FlexTable layout = new FlexTable();
layout.setVisible(false);
layout.setHTML(0, 0, "<p>You can also try to <strong>refresh the browser window</strong>. However, all <strong>unsaved changes will be lost</strong>.");
layout.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_TOP);
vp.add(layout);
vp.setSpacing(10);
final Confirm c = new Confirm("", vp, true);
c.setAutoHide(false);
c.setHideOnButtonClick(false);
c.setOkIcon(SmallIcons.INSTANCE.arrowRefreshIcon());
c.setOkButtonText("Re-connect");
c.setNonScrollable(true);
c.setOkClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
KeepAlive call = new KeepAlive(JsonCallbackEvents.disableButtonEvents(c.getOkButton(), new JsonCallbackEvents() {
@Override
public void onLoadingStart() {
checkPending = true;
}
@Override
public void onFinished(JavaScriptObject jso) {
BasicOverlayType type = jso.cast();
checkPending = false;
connected = true;
keepAliveCounter = 0;
if (type.getString().equals("OK")) {
if (c.isShowing()) {
c.hide();
}
}
// If ok, append new keepalive checker
appendKeepAliveChecker(c);
}
@Override
public void onError(PerunError error) {
checkPending = false;
// connection lost only IF TIMEOUT
if (error != null && error.getErrorId().equals("0")) {
keepAliveCounter++;
if (keepAliveCounter >= keepAliveTreshold) {
connected = false;
if (!c.isShowing()) {
c.show();
}
layout.setVisible(true);
c.getOkButton().setText("Reload");
c.getOkButton().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.Location.reload();
}
});
} else {
// not connected but under treshold
appendKeepAliveChecker(c);
}
}
}
}));
call.retrieveData();
}
});
appendKeepAliveChecker(c);
// store users roles and editable entities into session
session.setRoles(pp.getRoles());
// display logged user
session.getUiElements().setLoggedUserInfo(pp);
session.getUiElements().setLogText("Welcome " + pp.getUser().getFullNameWithTitles());
// show extended info ?
boolean showExtendedInfo = false;
// is perun admin ?
if (session.isPerunAdmin()) {
showExtendedInfo = true;
}
// replace by local storage if possible
Storage localStorage = Storage.getLocalStorageIfSupported();
if (localStorage != null) {
String value = localStorage.getItem("urn:perun:gui:preferences:extendedInfo");
if (value != null) {
showExtendedInfo = Boolean.parseBoolean(value);
}
}
// finally set it
JsonUtils.setExtendedInfoVisible(showExtendedInfo);
// set extended info button
session.getUiElements().getExtendedInfoButtonWidget().setDown(showExtendedInfo);
// Specific GDPR approval is required only from admins
if (session.isFacilityAdmin() || session.isVoAdmin() || session.isVoObserver() || session.isGroupAdmin() || session.isPerunAdmin() || session.isSecurityAdmin()) {
checkGdprApproval(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// FINISH LOADING UI ONCE ITS CHECKED
// perun loaded = true
perunLoaded = true;
// loads the page based on URL or default
loadPage();
// hides the loading box
loadingBox.hide();
// load proper parts of menu (based on roles)
session.getUiElements().getMenu().prepare();
}
@Override
public void onError(PerunError error) {
// hides the loading box
loadingBox.hide();
// shows error box
PopupPanel loadingFailedBox;
if (error != null) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
} else {
String checkFailed = session.getConfiguration().getGDPRproperty("check_failed");
loadingFailedBox = session.getUiElements().perunLoadingFailedBox(checkFailed);
}
loadingFailedBox.show();
}
});
} else {
// NO GDPR CHECK NEEDED
// perun loaded = true
perunLoaded = true;
// loads the page based on URL or default
loadPage();
// hides the loading box
loadingBox.hide();
// load proper parts of menu (based on roles)
session.getUiElements().getMenu().prepare();
}
}
@Override
public void onError(PerunError error) {
// hides the loading box
loadingBox.hide();
// shows error box
PopupPanel loadingFailedBox;
if (error != null) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("Request timeout exceeded.");
} else {
if (error.getName().contains("UserNotExistsException")) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("You are not registered to any Virtual Organization.</br></br>" + error.getErrorInfo());
} else {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
}
}
if (!error.getErrorId().equals("0")) {
loadingFailedBox.show();
}
}
});
getConfig.retrieveData();
}
@Override
public void onError(PerunError error) {
// hides the loading box
loadingBox.hide();
// shows error box
PopupPanel loadingFailedBox;
if (error == null) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("Request timeout exceeded.");
} else {
if (error.getName().contains("UserNotExistsException")) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("You are not registered to any Virtual Organization.</br></br>" + error.getErrorInfo());
} else {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
}
}
loadingFailedBox.show();
}
};
GetPerunPrincipal loggedUserRequst = new GetPerunPrincipal(events);
loggedUserRequst.retrieveData();
}
Aggregations