Search in sources :

Example 11 with BasicOverlayType

use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.

the class IsServiceDeniedOnFacility method onFinished.

/**
	 * Called when loading successfully finishes
	 *
	 * @param jso javascript object (array) returned from RPC
	 */
public void onFinished(JavaScriptObject jso) {
    BasicOverlayType bot = jso.cast();
    this.update(bot);
    session.getUiElements().setLogText("Loading denied info about service finished.");
    events.onFinished(bot);
}
Also used : BasicOverlayType(cz.metacentrum.perun.webgui.model.BasicOverlayType)

Example 12 with BasicOverlayType

use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.

the class GetNewExtendMembershipLoa method onFinished.

/**
 * When successfully finishes
 */
public void onFinished(JavaScriptObject jso) {
    BasicOverlayType basic = jso.cast();
    if (!basic.isNull()) {
        widget.setText(basic.getString());
    }
    events.onFinished(jso);
}
Also used : BasicOverlayType(cz.metacentrum.perun.webgui.model.BasicOverlayType)

Example 13 with BasicOverlayType

use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.

the class GetNewExtendMembership method onFinished.

/**
 * When successfully finishes
 */
public void onFinished(JavaScriptObject jso) {
    BasicOverlayType basic = jso.cast();
    if (jso != null) {
        widget.setText(basic.getString());
    }
    events.onFinished(jso);
}
Also used : BasicOverlayType(cz.metacentrum.perun.webgui.model.BasicOverlayType)

Example 14 with BasicOverlayType

use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.

the class SelfPasswordTabItem method draw.

public Widget draw() {
    String actionText = "Change";
    if (action.equals(Actions.CREATE)) {
        actionText = "Create";
    } else if (action.equals(Actions.DELETE)) {
        actionText = "Delete";
    }
    // set tab name
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": " + actionText + " password");
    // main panel
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    // widgets
    final Label namespaceLabel = new Label();
    namespaceLabel.setText(namespace);
    final Label loginLabel = new Label();
    loginLabel.setText(login);
    final ExtendedPasswordBox newPass = new ExtendedPasswordBox();
    final ExtendedPasswordBox confPass = new ExtendedPasswordBox();
    final ExtendedPasswordBox oldPass = new ExtendedPasswordBox();
    final CustomButton changeButton = new CustomButton("Change password", "Changes your password in selected namespace", SmallIcons.INSTANCE.keyIcon());
    final CustomButton createButton = new CustomButton("Create password", "Creates your password in selected namespace", SmallIcons.INSTANCE.keyAddIcon());
    final CustomButton deleteButton = new CustomButton("Delete password", "Deletes your password in selected namespace", SmallIcons.INSTANCE.keyDeleteIcon());
    final TabItem tab = this;
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (newPass.getTextBox().getValue().trim().equals("")) {
                newPass.setError("Password can't be empty!");
                return false;
            }
            // einfra check
            if ("einfra".equals(namespace)) {
                RegExp regExp2 = RegExp.compile("^[\\x20-\\x7E]{1,}$");
                if (regExp2.exec(newPass.getTextBox().getValue()) == null) {
                    newPass.setError("Password <b>can`t contain accented characters (diacritics)</b> or non-printing and control characters!");
                    return false;
                }
                // check on login in password if login is longer than 2 chars
                if (login.length() > 2) {
                    String pass = newPass.getTextBox().getValue();
                    if (Utils.normalizeString(pass).contains(Utils.normalizeString(login)) || Utils.normalizeString(pass).contains(Utils.normalizeString(Utils.reverseString((login))))) {
                        newPass.setError("Password <b>can't contain login, name or surname</b>, not even backwards!");
                        return false;
                    }
                }
                // Check that password contains at least 3 of 4 character groups
                RegExp regExpDigit = RegExp.compile("^.*[0-9].*$");
                RegExp regExpLower = RegExp.compile("^.*[a-z].*$");
                RegExp regExpUpper = RegExp.compile("^.*[A-Z].*$");
                RegExp regExpSpec = RegExp.compile("^.*[\\x20-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E].*$");
                int matchCounter = 0;
                if (regExpDigit.exec(newPass.getTextBox().getValue()) != null)
                    matchCounter++;
                if (regExpLower.exec(newPass.getTextBox().getValue()) != null)
                    matchCounter++;
                if (regExpUpper.exec(newPass.getTextBox().getValue()) != null)
                    matchCounter++;
                if (regExpSpec.exec(newPass.getTextBox().getValue()) != null)
                    matchCounter++;
                if (matchCounter < 3) {
                    newPass.setError("Password must consist of <b>at least 3 of 4</b> character groups<ul><li>lower-case letters</li><li>upper-case letters</li><li>digits</li><li>special characters</li></ul>");
                    return false;
                }
                // check length
                if (newPass.getTextBox().getValue().length() < 10) {
                    newPass.setError("Password must be <b>at least 10 characters</b> long!");
                    return false;
                }
            }
            if (!newPass.getTextBox().getValue().equals(confPass.getTextBox().getValue())) {
                newPass.setOk();
                confPass.setError("Password in both textboxes must be the same!");
                return false;
            }
            newPass.setOk();
            return true;
        }
    };
    final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!confPass.getTextBox().getValue().equals(newPass.getTextBox().getValue())) {
                confPass.setError("Password in both textboxes must be the same!");
                return false;
            } else {
                confPass.setOk();
                return true;
            }
        }
    };
    final ExtendedTextBox.TextBoxValidator oldValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (oldPass.getTextBox().getValue().trim().equals("")) {
                oldPass.setError("Password can't be empty!");
                return false;
            } else {
                oldPass.setOk();
                return true;
            }
        }
    };
    newPass.setValidator(validator);
    confPass.setValidator(validator2);
    oldPass.setValidator(oldValidator);
    // save changes
    changeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if ("mu".equals(namespace) && !JsonUtils.checkParseInt(login)) {
                UiElements.generateAlert("Operation not supported", "Password change/reset is not supported for non-numeric logins (UČO).");
            }
            if (session.isPerunAdmin() || user.isServiceUser()) {
                if (!validator.validateTextBox() && !validator2.validateTextBox())
                    return;
                ChangePassword changepw = new ChangePassword(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab, true), false);
                changepw.changePassword(user, namespace, oldPass.getTextBox().getValue(), newPass.getTextBox().getValue());
            } else {
                if (!validator.validateTextBox() && !validator2.validateTextBox() && !oldValidator.validateTextBox())
                    return;
                ChangePassword changepw = new ChangePassword(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab, true), true);
                changepw.changePassword(user, namespace, oldPass.getTextBox().getValue(), newPass.getTextBox().getValue());
            }
        }
    });
    if (user.isServiceUser()) {
        // for service users it's reset since they don't provide old password
        changeButton.setText("Reset password…");
    }
    createButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            if (validator.validateTextBox() && validator2.validateTextBox()) {
                if ("mu".equals(namespace)) {
                    final GenerateAccount generateAccount = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            BasicOverlayType basic = jso.cast();
                            final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
                            SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                                @Override
                                public void onFinished(JavaScriptObject jso) {
                                    UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
                                    // VALIDATE PASSWORD - SET EXT SOURCES
                                    CreatePassword req = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab, true));
                                    req.validatePassword(user.getId(), login, namespace);
                                }
                            }));
                            setLogin.setLogin(user.getId(), "mu", login);
                        }
                    }));
                    final Map<String, String> params = new HashMap<String, String>();
                    GetEntityById get = new GetEntityById(PerunEntity.RICH_USER_WITH_ATTRS, user.getId(), JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            User usr = jso.cast();
                            params.put("urn:perun:user:attribute-def:core:firstName", usr.getFirstName());
                            params.put("urn:perun:user:attribute-def:core:lastName", usr.getLastName());
                            params.put("urn:perun:member:attribute-def:def:mail", usr.getAttribute("urn:perun:user:attribute-def:def:preferredMail").getValue());
                            generateAccount.generateAccount(namespace, newPass.getTextBox().getValue(), params);
                        }
                    }));
                    get.retrieveData();
                } else {
                    // NORMAL PWD LOGIC
                    CreatePassword create = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab, true));
                    create.createPassword(userId, login, namespace, newPass.getTextBox().getValue());
                }
            }
        }
    });
    deleteButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            UiElements.generateAlert("Not yet implemented", "Not yet implemented");
        }
    });
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    // change layout
    if (action.equals(Actions.CHANGE)) {
        int row = 0;
        layout.setHTML(row, 0, "Namespace:");
        layout.setWidget(row, 1, namespaceLabel);
        row++;
        layout.setHTML(row, 0, "Login:");
        layout.setWidget(row, 1, loginLabel);
        row++;
        // mu namespace can change without knowing old
        if (!session.isPerunAdmin()) {
            if (!user.isServiceUser()) {
                layout.setHTML(row, 0, "Old password: ");
                layout.setWidget(row, 1, oldPass);
                row++;
            }
        }
        layout.setHTML(row, 0, "New password:");
        layout.setWidget(row, 1, newPass);
        row++;
        layout.setHTML(row, 0, "Retype new pass:");
        layout.setWidget(row, 1, confPass);
        menu.addWidget(changeButton);
        vp.add(layout);
    } else if (action.equals(Actions.CREATE)) {
        layout.setHTML(0, 0, "Namespace:");
        layout.setWidget(0, 1, namespaceLabel);
        if ("mu".equals(namespace)) {
            loginLabel.setText("Will be generated...");
            loginLabel.addStyleName("inputFormInlineComment");
        }
        layout.setHTML(1, 0, "Login:");
        layout.setWidget(1, 1, loginLabel);
        layout.setHTML(2, 0, "New password:");
        layout.setWidget(2, 1, newPass);
        layout.setHTML(3, 0, "Retype new pass:");
        layout.setWidget(3, 1, confPass);
        final CustomButton skip = new CustomButton("Skip", "Will set random/empty password", SmallIcons.INSTANCE.arrowRightIcon());
        skip.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                if ("mu".equals(namespace)) {
                    final GenerateAccount generateAccount = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            BasicOverlayType basic = jso.cast();
                            final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
                            SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                                @Override
                                public void onFinished(JavaScriptObject jso) {
                                    UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
                                    // VALIDATE PASSWORD - SET EXT SOURCES
                                    CreatePassword req = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab, true));
                                    req.validatePassword(user.getId(), login, namespace);
                                }
                            }));
                            setLogin.setLogin(user.getId(), "mu", login);
                        }
                    }));
                    final Map<String, String> params = new HashMap<String, String>();
                    GetEntityById get = new GetEntityById(PerunEntity.RICH_USER_WITH_ATTRS, user.getId(), JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            User usr = jso.cast();
                            params.put("urn:perun:user:attribute-def:core:firstName", usr.getFirstName());
                            params.put("urn:perun:user:attribute-def:core:lastName", usr.getLastName());
                            params.put("urn:perun:member:attribute-def:def:mail", usr.getAttribute("urn:perun:user:attribute-def:def:preferredMail").getValue());
                            generateAccount.generateAccount(namespace, newPass.getTextBox().getValue(), params);
                        }
                    }));
                    get.retrieveData();
                } else {
                    CreatePassword create = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(skip, tab, true));
                    create.createRandomPassword(userId, login, namespace);
                }
            }
        });
        menu.addWidget(skip);
        menu.addWidget(createButton);
        vp.add(layout);
    } else if (action.equals(Actions.DELETE)) {
        layout.setHTML(0, 0, "Namespace:");
        layout.setWidget(0, 1, namespaceLabel);
        layout.setHTML(1, 0, "Login:");
        layout.setWidget(1, 1, loginLabel);
        menu.addWidget(deleteButton);
        vp.add(layout);
    }
    for (int i = 0; i < layout.getRowCount(); i++) {
        layout.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }
    int row = layout.getRowCount();
    if ("einfra".equals(namespace)) {
        layout.setHTML(row, 0, "Password must <ul><li>contain only printing (non-accented) characters<li>be at least 10 characters long<li>consist of at least 3 of 4 character groups<ul><li>lower-case letters<li>upper-case letters<li>digits<li>special characters</ul></ul>");
    } else {
        layout.setHTML(row, 0, "Please <b>avoid using accented characters</b>. It might not be supported by all backend components and services.");
    }
    layout.getFlexCellFormatter().setColSpan(row, 0, 2);
    layout.getCellFormatter().setStyleName(row, 0, "inputFormInlineComment");
    layout.setWidth("400px");
    if (!action.equals(Actions.CREATE)) {
        menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                session.getTabManager().closeTab(tab, isRefreshParentOnClose());
            }
        }));
    }
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : ChangePassword(cz.metacentrum.perun.webgui.json.usersManager.ChangePassword) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) User(cz.metacentrum.perun.webgui.model.User) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) BasicOverlayType(cz.metacentrum.perun.webgui.model.BasicOverlayType) GenerateAccount(cz.metacentrum.perun.webgui.json.usersManager.GenerateAccount) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById) CreatePassword(cz.metacentrum.perun.webgui.json.usersManager.CreatePassword) RegExp(com.google.gwt.regexp.shared.RegExp) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) SetLogin(cz.metacentrum.perun.webgui.json.usersManager.SetLogin) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) HashMap(java.util.HashMap) Map(java.util.Map) ExtendedPasswordBox(cz.metacentrum.perun.webgui.widgets.ExtendedPasswordBox)

Example 15 with BasicOverlayType

use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.

the class GetResourcesCount method onFinished.

/**
 * Called when loading successfully finishes.
 */
public void onFinished(JavaScriptObject jso) {
    BasicOverlayType count = (BasicOverlayType) jso;
    session.getUiElements().setLogText("Loading resources count finished: " + count.getInt());
    resourcesCountLabel.setText(String.valueOf(count.getInt()));
    hyp.setText(String.valueOf(count.getInt()));
    events.onFinished(jso);
}
Also used : BasicOverlayType(cz.metacentrum.perun.webgui.model.BasicOverlayType)

Aggregations

BasicOverlayType (cz.metacentrum.perun.webgui.model.BasicOverlayType)18 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)8 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)8 PerunError (cz.metacentrum.perun.webgui.model.PerunError)6 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 RegExp (com.google.gwt.regexp.shared.RegExp)4 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)4 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)3 GetGuiConfiguration (cz.metacentrum.perun.webgui.json.GetGuiConfiguration)2 GetPerunPrincipal (cz.metacentrum.perun.webgui.json.authzResolver.GetPerunPrincipal)2 KeepAlive (cz.metacentrum.perun.webgui.json.authzResolver.KeepAlive)2 IsLoginAvailable (cz.metacentrum.perun.webgui.json.usersManager.IsLoginAvailable)2 SetLogin (cz.metacentrum.perun.webgui.json.usersManager.SetLogin)2 PerunPrincipal (cz.metacentrum.perun.webgui.model.PerunPrincipal)2 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)2 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)2 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)2 Scheduler (com.google.gwt.core.client.Scheduler)1 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1