Search in sources :

Example 1 with PerunAttributeTableWidget

use of cz.metacentrum.perun.webgui.widgets.PerunAttributeTableWidget 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 &gt;&gt;</a> and select \"Using personal certificate\" option.<br />&nbsp;");
    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();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) Attribute(cz.metacentrum.perun.webgui.model.Attribute) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) PerunAttributeTableWidget(cz.metacentrum.perun.webgui.widgets.PerunAttributeTableWidget) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) RemoveUserExtSource(cz.metacentrum.perun.webgui.json.usersManager.RemoveUserExtSource) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetLogins(cz.metacentrum.perun.webgui.json.attributesManager.GetLogins) GetListOfAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) UserExtSource(cz.metacentrum.perun.webgui.model.UserExtSource) RemoveUserExtSource(cz.metacentrum.perun.webgui.json.usersManager.RemoveUserExtSource) GetUserExtSources(cz.metacentrum.perun.webgui.json.usersManager.GetUserExtSources) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 2 with PerunAttributeTableWidget

use of cz.metacentrum.perun.webgui.widgets.PerunAttributeTableWidget in project perun by CESNET.

the class TestAttributeTableTabItem method draw.

public Widget draw() {
    PerunAttributeTableWidget.SaveEvent saveEvent = new PerunAttributeTableWidget.SaveEvent() {

        public void save(ArrayList<Attribute> attrs) {
            for (Attribute attr : attrs) {
                session.getUiElements().setLogText("New value OK: " + attr.getValue().toString());
            }
        }
    };
    PerunAttributeTableWidget table = new PerunAttributeTableWidget(null, saveEvent, false, listOfAttributes());
    this.contentWidget.setWidget(table);
    return getWidget();
}
Also used : Attribute(cz.metacentrum.perun.webgui.model.Attribute) ArrayList(java.util.ArrayList) PerunAttributeTableWidget(cz.metacentrum.perun.webgui.widgets.PerunAttributeTableWidget)

Aggregations

Attribute (cz.metacentrum.perun.webgui.model.Attribute)2 PerunAttributeTableWidget (cz.metacentrum.perun.webgui.widgets.PerunAttributeTableWidget)2 ArrayList (java.util.ArrayList)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetListOfAttributes (cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes)1 GetLogins (cz.metacentrum.perun.webgui.json.attributesManager.GetLogins)1 GetUserExtSources (cz.metacentrum.perun.webgui.json.usersManager.GetUserExtSources)1 RemoveUserExtSource (cz.metacentrum.perun.webgui.json.usersManager.RemoveUserExtSource)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 UserExtSource (cz.metacentrum.perun.webgui.model.UserExtSource)1 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 HashMap (java.util.HashMap)1