Example usage for com.google.gwt.user.client Cookies getCookie

List of usage examples for com.google.gwt.user.client Cookies getCookie

Introduction

In this page you can find the example usage for com.google.gwt.user.client Cookies getCookie.

Prototype

public static String getCookie(String name) 

Source Link

Document

Gets the cookie associated with the given name.

Usage

From source file:org.olanto.TranslationText.client.QuoteWidget.java

License:Open Source License

private void setHeader() {
    initWidget(mainWidget);//ww w.j  a v  a  2  s .c  om
    mainWidget.setStyleName("mainContent");
    mainWidget.add(headerContainer);
    mainWidget.setCellHorizontalAlignment(headerContainer, VerticalPanel.ALIGN_CENTER);
    mainWidget.add(refpanel);
    mainWidget.setCellHorizontalAlignment(refpanel, VerticalPanel.ALIGN_CENTER);
    mainWidget.add(mainContainer);
    mainWidget.setCellHorizontalAlignment(mainContainer, VerticalPanel.ALIGN_LEFT);
    mainWidget.add(statusContainer);
    mainWidget.setCellHorizontalAlignment(statusContainer, VerticalPanel.ALIGN_CENTER);

    headerContainer.setBodyBorder(true);
    headerContainer.setHeaderVisible(false);
    headerContainer.add(headPanel);
    headerContainer.setStylePrimaryName("searchHeader");
    headPanel.setStylePrimaryName("searchHeader");
    headPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);

    headerPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
    headerPanel.add(fileUpload);
    headerPanel.add(GoSrch);
    headerPanel.add(langS);
    headerPanel.add(langT);
    headerPanel.add(coll);
    headerPanel.add(minLn);
    headerPanel.add(minLength);
    headerPanel.add(prev);
    headerPanel.add(next);
    headerPanel.add(refIndic);
    headerPanel.add(TextAligner);
    headerPanel.add(help);
    if (GuiConstant.SAVE_ON) {
        headerPanel.add(save);
    }
    if (GuiConstant.AUTO_ON) {
        headerPanel.add(resize);
    }
    headerPanel.setStylePrimaryName("searchHeader");

    headPanel.add(leftheadPanel);
    headPanel.add(QDText);
    headPanel.setCellHorizontalAlignment(QDText, HorizontalPanel.ALIGN_RIGHT);
    headPanel.add(new HTML(" "));
    if ((!GuiConstant.LOGO_PATH.isEmpty()) && (!GuiConstant.LOGO_PATH.isEmpty())) {
        if ((!GuiConstant.LOGO_PATH.equalsIgnoreCase(" ")) && (!GuiConstant.LOGO_PATH.equalsIgnoreCase(" "))) {
            headPanel.add(im);
            headPanel.setCellHorizontalAlignment(im, HorizontalPanel.ALIGN_RIGHT);
        }
    }
    topJobsSet.setTabBarPosition(Side.TOP);
    topJobsSet.setDefaultHeight(H_Unit);
    topJobsSet.setPaneContainerClassName("searchHeader");
    leftheadPanel.add(topJobsSet);
    leftheadPanel.add(headerPanel);

    mainContainer.setBodyBorder(true);
    mainContainer.setHeaderVisible(false);
    mainContainer.add(resultsPanel);
    mainContainer.setStylePrimaryName("mainContent");

    statusContainer.setBodyBorder(true);
    statusContainer.setHeaderVisible(false);
    statusContainer.add(statusPanel);
    statusPanel.setHeight(H_Unit + "px");
    statusPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
    statusPanel.add(msg);
    statusPanel.setCellHorizontalAlignment(msg, HorizontalPanel.ALIGN_LEFT);
    statusPanel.add(contact);
    statusPanel.setCellHorizontalAlignment(contact, HorizontalPanel.ALIGN_RIGHT);
    contact.setPixelSize(GuiConstant.DOC_LIST_WIDTH, 25);
    contact.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
    Anchor poweredBy = new Anchor(GuiConstant.OLANTO_URL.substring(0, GuiConstant.OLANTO_URL.indexOf("|")),
            true,
            GuiConstant.OLANTO_URL.substring(GuiConstant.OLANTO_URL.indexOf("|") + 1,
                    GuiConstant.OLANTO_URL.lastIndexOf("|")),
            GuiConstant.OLANTO_URL.substring(GuiConstant.OLANTO_URL.lastIndexOf("|") + 1));
    contact.add(poweredBy);
    poweredBy.setStylePrimaryName("contactInfo");
    contact.setCellHorizontalAlignment(poweredBy, HorizontalPanel.ALIGN_LEFT);
    contact.add(new HTML("||"));
    Anchor feedback = new Anchor(
            GuiConstant.FEEDBACK_MAIL.substring(0, GuiConstant.FEEDBACK_MAIL.indexOf("|")));
    contact.add(feedback);
    feedback.setStylePrimaryName("contactInfo");
    contact.setCellHorizontalAlignment(feedback, HorizontalPanel.ALIGN_RIGHT);
    contact.add(new HTML(" "));

    statusContainer.setStylePrimaryName("statusPanel");
    statusPanel.setStylePrimaryName("statusPanel");

    refpanel.setBodyBorder(true);
    refpanel.setHeaderVisible(false);
    refpanel.add(htmlWrapper);
    htmlWrapper.add(refArea);

    docListContainer.setBodyBorder(true);
    resultsPanel.add(docListContainer);
    resultsPanel.setCellHorizontalAlignment(docListContainer, HorizontalPanel.ALIGN_LEFT);
    docListContainer.add(staticDecorator);
    tS = new QuoteBitextWidget(msg);
    resultsPanel.add(tS);

    refArea.setVisible(true);
    refArea.setStyleName("TextBlock");
    fileUpload.addOnStartUploadHandler(onStartUploaderHandler);
    fileUpload.addOnFinishUploadHandler(onFinishUploaderHandler);
    help.addListener(Events.OnClick, new Listener<BaseEvent>() {
        @Override
        public void handleEvent(BaseEvent be) {
            Window.open(GuiConstant.QD_HELP_URL, "", GuiConstant.W_OPEN_FEATURES);
        }
    });
    resize.addListener(Events.OnClick, new Listener<BaseEvent>() {
        @Override
        public void handleEvent(BaseEvent be) {
            resizeAll();
            resizeAll();
            reselectDocument();
        }
    });
    staticDecorator.setStyleName("doclist");
    staticDecorator.setWidget(staticTreeWrapper);
    fileUpload.setAutoSubmit(true);
    setMessage("info", "");
    for (int i = GuiConstant.MIN_OCCU; i < GuiConstant.MAX_OCCU; i++) {
        minLength.addItem("" + i);
    }
    minLength.setSelectedIndex(Integer.parseInt(Cookies.getCookie(CookiesNamespace.MyQuoteMinLength)));
    minLength.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            GoSrch.enable();
            MyCatCookies.updateCookie(CookiesNamespace.MyQuoteMinLength, "" + minLength.getSelectedIndex());
        }
    });
    langS.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            GoSrch.enable();
            MyCatCookies.updateCookie(CookiesNamespace.MyQuotelangS,
                    langS.getItemText(langS.getSelectedIndex()));
        }
    });
    langT.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            GoSrch.enable();
            MyCatCookies.updateCookie(CookiesNamespace.MyQuotelangT,
                    langT.getItemText(langT.getSelectedIndex()));
        }
    });
    if ((!GuiConstant.LOGO_PATH.isEmpty()) && (!GuiConstant.LOGO_PATH.isEmpty())) {
        im.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Window.open(GuiConstant.LOGO_URL, "", GuiConstant.W_OPEN_FEATURES);
            }
        });
    }
    feedback.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            mailto(GuiConstant.FEEDBACK_MAIL.substring(GuiConstant.FEEDBACK_MAIL.lastIndexOf("|") + 1),
                    GuiMessageConst.MSG_39 + GuiConstant.QUOTE_DETECTOR_LBL);
        }
    });
}

From source file:org.olanto.TranslationText.client.ResearchWidget.java

License:Open Source License

public void draWidget() {
    setbuttonstyle(GoSrch, GoSrch.getText().length() * 2 * CHAR_W, H_Unit);
    setbuttonstyle(myQuote, myQuote.getText().length() * CHAR_W, H_Unit);
    setbuttonstyle(coll, coll.getText().length() * CHAR_W, H_Unit);
    setbuttonstyle(help, help.getText().length() * CHAR_W, H_Unit);
    setbuttonstyle(resize, resize.getText().length() * CHAR_W, H_Unit);
    GoSrch.setAutoWidth(true);/*from  w w  w  . j  a v  a 2s .c  o m*/
    myQuote.setAutoWidth(true);
    coll.setAutoWidth(true);
    help.setAutoWidth(true);
    resize.setAutoWidth(true);

    search.setWidth("300px");
    search.setStyleName("x-form-text");
    TAText.setText(GuiConstant.TEXT_ALIGNER_LBL);
    TAText.setStyleName("gwt-im-text");
    chooseLang.setStyleName("gwt-w-label");

    setMessage("info", "");
    for (int i = 0; i < SORT_BY.length; i++) {
        sortBy.addItem(SORT_BY[i]);
    }
    langS.setWidth(3 * W_Unit + "px");
    langT.setWidth(3 * W_Unit + "px");
    sortBy.setWidth(6 * W_Unit + "px");
    sortBy.setSelectedIndex(Utility.getIndex(SORT_BY_Eff, Cookies.getCookie(CookiesNamespace.SortBy)));

    for (int i = 0; i < INT_LANG.length; i++) {
        langInterface.addItem(INT_LANG[i]);
    }
    langInterface.setWidth(2 * W_Unit + "px");
    langInterface.setSelectedIndex(
            Utility.getIndex(INT_LANG, Cookies.getCookie(CookiesNamespace.InterfaceLanguage)));

    docListContainer.setSize(MainEntryPoint.IMeasures.DOC_LIST_WIDTH, MainEntryPoint.IMeasures.DOC_LIST_HEIGHT);
    staticDecorator.setStyleName("doclist");
    staticDecorator.setWidget(staticTreeWrapper);
    staticTreeWrapper.setAlwaysShowScrollBars(true);
    staticTreeWrapper.setPixelSize(MainEntryPoint.IMeasures.DOC_LIST_WIDTH,
            MainEntryPoint.IMeasures.DOC_LIST_HEIGHT - H_Unit);
    if ((GuiConstant.JOBS_ITEMS != null) && (GuiConstant.JOBS_ITEMS.length() > 1)) {
        String jobs = GuiConstant.JOBS_ITEMS;
        String[] tablist = jobs.split("\\;");
        Tab tinv = new Tab();
        topJobsSet.addTab(tinv);
        tinv.setTitle("Select Tab : ");
        tinv.setID("Empty");
        tinv.setDisabled(true);
        if (tablist.length > 0) {
            for (int i = 0; i < tablist.length; i++) {
                Tab tTab = new Tab();
                tTab.setIcon("./icons/16/folder_document.png");
                tTab.setTitle(tablist[i].substring(0, tablist[i].indexOf("|")));
                tTab.setAttribute("URL",
                        tablist[i].substring(tablist[i].indexOf("|") + 1, tablist[i].lastIndexOf("|")));
                tTab.setAttribute("MODE", tablist[i].substring(tablist[i].lastIndexOf("|") + 1));
                topJobsSet.addTab(tTab);
            }
        }
        topJobsSet.setSelectedTab(0);
        topJobsSet.addTabSelectedHandler(new TabSelectedHandler() {
            @Override
            public void onTabSelected(TabSelectedEvent event) {
                if (!(event.getTab().getID().contains("Empty"))) {
                    //                        Window.alert("URL: " + event.getTab().getAttribute("URL") + "mode: " + event.getTab().getAttribute("MODE"));
                    Window.open(event.getTab().getAttribute("URL"), event.getTab().getAttribute("MODE"), "");
                }
            }
        });
        topJobsSet.setWidth(headerPanel.getOffsetWidth());
        topJobsSet.draw();
        topJobsSet.setCursor(Cursor.HAND);
    } else {
        leftheadPanel.remove(topJobsSet);
    }
}

From source file:org.onebusaway.webapp.gwt.notification.NotificationStateDAO.java

License:Apache License

private List<NotificationStateNode> loadState() {

    List<NotificationStateNode> nodes = new ArrayList<NotificationStateNode>();

    String cookieValue = Cookies.getCookie(COOKIE_NAME);

    if (cookieValue != null) {

        System.out.println("loading=" + cookieValue);

        JSONValue p = JSONParser.parse(cookieValue);
        JSONArray array = p.isArray();//from w w w .ja va 2 s . c  o  m
        if (array != null) {
            for (int i = 0; i < array.size(); i++) {
                JSONValue entryValue = array.get(i);
                NotificationStateNode node = getJSONValueAsNode(entryValue);
                if (node != null)
                    nodes.add(node);
            }
        }
    }

    return nodes;
}

From source file:org.onecmdb.ui.gwt.desktop.client.mvc.contoller.DesktopContoller.java

License:Open Source License

@Override
public void handleEvent(AppEvent<?> event) {
    switch (event.type) {
    // Main entry point.
    case CMDBEvents.DESKTOP_CHECK_SESSION:
        // Save URL arguments
        urlMap = com.google.gwt.user.client.Window.Location.getParameterMap();

        // Check for autologin.
        List<String> alids = urlMap.get("alid");
        if (alids != null && alids.size() > 0) {
            String alid = alids.get(0);
            // Need to validate this token.
            ModelServiceFactory.get().autoLogin(alid, new AsyncCallback<CMDBSession>() {
                public void onFailure(Throwable arg0) {
                    Dispatcher.get().dispatch(CMDBEvents.DESKTOP_LOGIN);
                    return;
                }/*ww w. j  a va  2  s.c om*/

                public void onSuccess(CMDBSession arg0) {
                    arg0.setURLValues(urlMap);
                    CMDBSession.get().setSession(arg0);
                    initDesktop();
                    setupDesktop(arg0.getDesktopConfig());
                }
            });
            return;
        }

        // Check if we have a cookie set.
        String token = Cookies.getCookie("auth_token");
        if (token != null) {
            // Need to validate this token.
            ModelServiceFactory.get().validateToken(token, new AsyncCallback<CMDBSession>() {
                public void onFailure(Throwable arg0) {
                    Dispatcher.get().dispatch(CMDBEvents.DESKTOP_LOGIN);
                    return;
                }

                public void onSuccess(CMDBSession arg0) {
                    arg0.setUsername(Cookies.getCookie("auth_username"));
                    arg0.setURLValues(urlMap);
                    CMDBSession.get().setSession(arg0);
                    initDesktop();
                    setupDesktop(arg0.getDesktopConfig());
                }

            });
            return;
        }

        // Normal login.
        Dispatcher.get().dispatch(CMDBEvents.DESKTOP_LOGIN);
        break;
    case CMDBEvents.DESKTOP_MENU_SELECTED:
        CMDBDesktopMenuItem item = (CMDBDesktopMenuItem) event.data;
        CMDBDesktopWindowItem wItem = item.getWindowItem();
        Window window = WindowFactory.showWindow(desktop, wItem);
        break;
    case CMDBEvents.DESKTOP_LOCK_TIMEOUT:
        stopActivityTimer();
        LoginWidget.login(true, new AsyncCallback<CMDBSession>() {

            public void onFailure(Throwable arg0) {
                if (arg0 instanceof CMDBLoginException) {
                    CMDBLoginException ex = (CMDBLoginException) arg0;
                    MessageBox.alert(ex.getHeader(), ex.getMessage(), new Listener<WindowEvent>() {

                        public void handleEvent(WindowEvent be) {
                            Dispatcher.get().dispatch(CMDBEvents.DESKTOP_LOCK_TIMEOUT);
                        }

                    });

                    return;
                }
                ExceptionErrorDialog.showError("Login Failed!", arg0, new Listener<WindowEvent>() {

                    public void handleEvent(WindowEvent be) {
                    }
                });
            }

            public void onSuccess(CMDBSession arg0) {
                Date date = new Date();
                long dateLong = date.getTime();
                dateLong += (1000 * 60 * 60 * 8);// 8h convert days to ms
                date.setTime(dateLong); // Set the new date

                Cookies.setCookie("auth_token", arg0.getToken(), date);
                Cookies.setCookie("auth_username", arg0.getUsername(), date);
                arg0.setURLValues(urlMap);
                CMDBSession.get().setSession(arg0);
                startActivityTimeout(CMDBSession.get().getConfig().getDesktopLockTimeout());
            }
        });

        break;
    case CMDBEvents.DESKTOP_LOGIN:
        LoginWidget.login(false, new AsyncCallback<CMDBSession>() {

            public void onFailure(Throwable arg0) {
                if (arg0 instanceof CMDBLoginException) {
                    CMDBLoginException ex = (CMDBLoginException) arg0;
                    MessageBox.alert(ex.getHeader(), ex.getMessage(), new Listener<WindowEvent>() {

                        public void handleEvent(WindowEvent be) {
                            Dispatcher.get().dispatch(CMDBEvents.DESKTOP_LOGIN);
                        }

                    });

                    return;
                }
                ExceptionErrorDialog.showError("Login Failed!", arg0, new Listener<WindowEvent>() {

                    public void handleEvent(WindowEvent be) {
                    }
                });
            }

            public void onSuccess(CMDBSession arg0) {
                Date date = new Date();
                long dateLong = date.getTime();
                dateLong += (1000 * 60 * 60 * 8);// 8h convert days to ms
                date.setTime(dateLong); // Set the new date

                Cookies.setCookie("auth_token", arg0.getToken(), date);
                Cookies.setCookie("auth_username", arg0.getUsername(), date);
                arg0.setURLValues(urlMap);
                CMDBSession.get().setSession(arg0);
                initDesktop();
                setupDesktop(arg0.getDesktopConfig());
            }
        });
        break;
    case CMDBEvents.DESKTOP_LOGOUT:
        // close all windows.
        clearWindow();

        // Logout
        ModelServiceFactory.get().logout(CMDBSession.get().getToken(), new AsyncCallback<Boolean>() {

            public void onFailure(Throwable caught) {
            }

            public void onSuccess(Boolean result) {
            }

        });

        // Clear session...
        CMDBSession.setSession(null);

        // Stop Lock timer
        stopActivityTimer();

        // Clear Cookies.
        Cookies.removeCookie("auth_token");
        Cookies.removeCookie("auth_username");

        // Call login.
        // Reload application....
        reloadApplication();
        //Dispatcher.get().dispatch(CMDBEvents.DESKTOP_LOGIN);
        break;
    case CMDBEvents.DESKTOP_ABOUT:
        CMDBDesktopWindowItem about = new CMDBDesktopWindowItem();
        about.setID(CMDBURLFrameWidget.ID);
        about.getParams().set("url", GWT.getModuleBaseURL() + "/about.html");
        about.getParams().set("newWindow", "true");
        about.setHeading("About - OneCMDB");
        WindowFactory.showWindow(desktop, about);
        break;
    case CMDBEvents.DESKTOP_CHANGE_ROLE:
        final String role = (String) event.data;
        //desktop.getStartMenu().hide();
        final MessageBox info = MessageBox.wait("Progress", "Change Role to " + role, "Wait...");

        ModelServiceFactory.get().getDesktopConfig(CMDBSession.get().getUsername(),
                CMDBSession.get().getToken(), role, new CMDBAsyncCallback<CMDBDesktopConfig>() {

                    @Override
                    public void onFailure(Throwable t) {
                        info.close();
                        super.onFailure(t);
                    }

                    @Override
                    public void onSuccess(CMDBDesktopConfig arg0) {
                        info.close();
                        clearWindow();
                        CMDBSession.get().setDesktopConfig(arg0);
                        CMDBSession.get().setDefaultRole(role);
                        initDesktop();
                        setupDesktop(arg0);
                    }
                });
        break;

    }
}

From source file:org.onecmdb.ui.gwt.desktop.client.widget.LoginWidget.java

License:Open Source License

public static void login(boolean lock, final AsyncCallback<CMDBSession> callback) {
    String cookieUser = Cookies.getCookie("auth_username");
    if (cookieUser != null) {
        user = cookieUser;//www .jav  a2s .  c  om
    }
    final Dialog login = new Dialog();
    login.setClosable(false);
    login.setButtons("");
    login.setBodyBorder(true);
    login.setInsetBorder(true);
    //login.setButtons(Dialog.OK);  
    login.setIconStyle("icon-app-side");
    if (lock) {
        login.setHeading("OneCMDB Desktop - Locked");
    } else {
        login.setHeading("Login - OneCMDB Desktop");
    }
    //<br><a style='font-size:8px'><i>V" + Version.VERSION_STRING + "</i></a></br>");  
    login.setWidth(240);
    login.setHeight(140);
    login.setHideOnButtonClick(true);

    FormPanel panel = new FormPanel();
    panel.setLabelWidth(60);
    panel.setFieldWidth(100);
    panel.setHeaderVisible(false);

    final TextField username = new TextField();
    username.setFieldLabel("Username");
    username.setEmptyText("username");
    if (user != null) {
        username.setValue(user);
    }
    if (lock) {
        username.setEnabled(false);
    }
    panel.add(username);

    final TextField password = new TextField();
    password.setFieldLabel("Password");
    password.setPassword(true);
    password.addKeyListener(new KeyListener() {

        @Override
        public void componentKeyUp(ComponentEvent event) {
            if (event.getKeyCode() == KeyboardListener.KEY_ENTER) {
                doLogin(login, (String) username.getValue(), (String) password.getValue(), callback);
            }
        }

    });
    panel.add(password);

    login.setLayout(new RowLayout());
    login.add(panel, new RowData(1, 1));
    HTML version = new HTML();
    version.setText("Version " + Version.VERSION_STRING);
    version.setStyleName("cmdb-version-text");
    login.add(version, new RowData(1, -1));
    login.addButton(new Button("Login", new SelectionListener<ComponentEvent>() {

        @Override
        public void componentSelected(ComponentEvent ce) {
            doLogin(login, (String) username.getValue(), (String) password.getValue(), callback);
        }
    }));
    login.setModal(true);
    login.show();
}

From source file:org.onecmdb.ui.gwt.toolkit.client.control.OneCMDBSession.java

License:Open Source License

/**
 * Helper function to get the value from the cookie
 * //w  ww. j  ava  2  s.c  om
 * @param cookieName
 *            Name of the cookie
 * @return value of the cookie
 */
public static String getCookie(String cookieName) {
    return Cookies.getCookie(cookieName);
}

From source file:org.onecmdb.ui.gwt.toolkit.client.view.screen.BaseScreen.java

License:Apache License

/**
 * Helper function to get the value from the cookie
 * //from  w w  w. jav a  2s . c o  m
 * @param cookieName
 *            Name of the cookie
 * @return value of the cookie
 */
public String getCookie(String cookieName) {
    return Cookies.getCookie(cookieName);
}

From source file:org.opendatakit.aggregate.client.AggregateUI.java

License:Apache License

private void initializeUserAndPreferences() {
    lastUserInfoUpdateAttemptTimestamp = lastRealmInfoUpdateAttemptTimestamp = System.currentTimeMillis();

    // the first realm request will often fail because the cookie
    // should/could be null (e.g., for anonymous users).
    SecureGWT.getSecurityService().getRealmInfo(Cookies.getCookie("JSESSIONID"),
            new AsyncCallback<RealmSecurityInfo>() {

                @Override//from w  ww  . j  av a 2s.  c  o  m
                public void onFailure(Throwable caught) {
                    if (caught instanceof RequestFailureException) {
                        RequestFailureException e = (RequestFailureException) caught;
                        if (e.getMessage().equals(QUOTA_EXCEEDED)) {
                            return; // Don't retry -- we have a quota problem...
                        }
                    }
                    // OK. So it failed. If it did, just try doing everything
                    // again. We should have a valid session cookie after the
                    // first failure, so these should all then work.
                    SecureGWT.getSecurityService().getUserInfo(new AsyncCallback<UserSecurityInfo>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            reportError(caught);
                        }

                        @Override
                        public void onSuccess(UserSecurityInfo result) {
                            userInfo = result;
                            if (realmInfo != null && userInfo != null) {
                                Preferences.updatePreferences(new PreferencesCompletionCallback() {

                                    @Override
                                    public void refreshFromUpdatedPreferences() {
                                        commonUserInfoUpdateCompleteAction();
                                    }

                                    @Override
                                    public void failedRefresh() {
                                        commonUserInfoUpdateCompleteAction();
                                    }
                                });
                            }
                        }
                    });

                    SecureGWT.getSecurityService().getRealmInfo(Cookies.getCookie("JSESSIONID"),
                            new AsyncCallback<RealmSecurityInfo>() {

                                @Override
                                public void onFailure(Throwable caught) {
                                    reportError(caught);
                                }

                                @Override
                                public void onSuccess(RealmSecurityInfo result) {
                                    realmInfo = result;
                                    updateNotSecureInfo();
                                    if (realmInfo != null && userInfo != null) {
                                        commonUserInfoUpdateCompleteAction();
                                    }
                                }
                            });
                }

                @Override
                public void onSuccess(RealmSecurityInfo result) {
                    realmInfo = result;
                    updateNotSecureInfo();
                    // it worked the first time! Now do the user info request.
                    SecureGWT.getSecurityService().getUserInfo(new AsyncCallback<UserSecurityInfo>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            reportError(caught);
                        }

                        @Override
                        public void onSuccess(UserSecurityInfo result) {
                            userInfo = result;
                            if (realmInfo != null && userInfo != null) {
                                Preferences.updatePreferences(new PreferencesCompletionCallback() {

                                    @Override
                                    public void refreshFromUpdatedPreferences() {
                                        commonUserInfoUpdateCompleteAction();
                                    }

                                    @Override
                                    public void failedRefresh() {
                                        commonUserInfoUpdateCompleteAction();
                                    }
                                });
                            }
                        }
                    });
                }
            });
}

From source file:org.opendatakit.aggregate.client.AggregateUI.java

License:Apache License

public RealmSecurityInfo getRealmInfo() {
    if (realmInfo == null) {
        GWT.log("AggregateUI.getRealmInfo: realmInfo is null");
    }//from w  ww  .ja  v  a  2  s  .com
    if (lastRealmInfoUpdateAttemptTimestamp + RefreshTimer.SECURITY_REFRESH_INTERVAL < System
            .currentTimeMillis()) {
        // record the attempt
        lastRealmInfoUpdateAttemptTimestamp = System.currentTimeMillis();
        GWT.log("AggregateUI.getRealmInfo: triggering refresh of realmInfo");
        SecureGWT.getSecurityService().getRealmInfo(Cookies.getCookie("JSESSIONID"),
                new AsyncCallback<RealmSecurityInfo>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        reportError(caught);
                    }

                    @Override
                    public void onSuccess(RealmSecurityInfo result) {
                        realmInfo = result;
                        updateNotSecureInfo();
                    }
                });
    }
    return realmInfo;
}

From source file:org.opendatakit.aggregate.client.permissions.AccessConfigurationSheet.java

License:Apache License

public void updateUsersOnServer() {
    ArrayList<GrantedAuthorityName> allGroups = new ArrayList<GrantedAuthorityName>();
    allGroups.add(GrantedAuthorityName.GROUP_SITE_ADMINS);
    allGroups.add(GrantedAuthorityName.GROUP_ADMINISTER_TABLES);
    allGroups.add(GrantedAuthorityName.GROUP_SYNCHRONIZE_TABLES);
    allGroups.add(GrantedAuthorityName.GROUP_FORM_MANAGERS);
    allGroups.add(GrantedAuthorityName.GROUP_DATA_VIEWERS);
    allGroups.add(GrantedAuthorityName.GROUP_DATA_COLLECTORS);
    allGroups.add(GrantedAuthorityName.USER_IS_ANONYMOUS);

    final ArrayList<UserSecurityInfo> users = new ArrayList<UserSecurityInfo>();
    users.addAll(dataProvider.getList());
    for (UserSecurityInfo i : users) {
        if (i.getType() == UserType.ANONYMOUS) {
            if (anonymousAttachmentBoolean) {
                i.getAssignedUserGroups().add(GrantedAuthorityName.ROLE_ATTACHMENT_VIEWER);
            } else {
                i.getAssignedUserGroups().remove(GrantedAuthorityName.ROLE_ATTACHMENT_VIEWER);
            }/*from w ww.  ja va  2 s . c o m*/
            break;
        } else {
            if (i.getUsername() == null) {
                // don't allow Google users to be data collectors
                i.getAssignedUserGroups().remove(GrantedAuthorityName.GROUP_DATA_COLLECTORS);
            } else {
                // TODO: relax this
                // don't allow non-Google users to synchronize tables
                i.getAssignedUserGroups().remove(GrantedAuthorityName.GROUP_SYNCHRONIZE_TABLES);
            }
        }
    }
    SecureGWT.getSecurityAdminService().setUsersAndGrantedAuthorities(Cookies.getCookie("JSESSIONID"), users,
            allGroups, new AsyncCallback<Void>() {

                @Override
                public void onFailure(Throwable caught) {
                    AggregateUI.getUI().reportError("Incomplete security update: ", caught);
                }

                @Override
                public void onSuccess(Void result) {
                    SecureGWT.getSecurityAdminService().getAllUsers(true, new UpdateUserDisplay());
                    if (newUsers) {
                        assignNewPasswords(preUsers);
                    }
                }
            });
}