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

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

Introduction

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

Prototype

public static Collection<String> getCookieNames() 

Source Link

Document

Gets the names of all cookies in this page's domain.

Usage

From source file:org.jboss.bpm.console.client.LoginView.java

License:Open Source License

private void requestSessionID() {
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,
            config.getConsoleServerUrl() + "/rs/identity/sid");

    try {//from  w w  w  . j  a  v  a 2  s.  com
        rb.sendRequest(null, new RequestCallback() {

            public void onResponseReceived(Request request, Response response) {
                ConsoleLog.debug("SID: " + response.getText());
                ConsoleLog.debug("Cookies: " + Cookies.getCookieNames());
                final String sid = response.getText();

                auth = new Authentication(config, sid, URLBuilder.getInstance().getUserInRoleURL(KNOWN_ROLES));

                auth.setCallback(new Authentication.AuthCallback() {

                    public void onLoginSuccess(Request request, Response response) {
                        // clear the form
                        usernameInput.setText("");
                        passwordInput.setText("");

                        // display main console
                        window.hide();

                        // assemble main layout
                        DeferredCommand.addCommand(new Command() {
                            public void execute() {
                                // move the loading div to foreground
                                DOM.getElementById("splash").getStyle().setProperty("zIndex", "1000");
                                DOM.getElementById("ui_loading").getStyle().setProperty("visibility",
                                        "visible");

                                // launch workspace
                                GWT.runAsync(new RunAsyncCallback() {
                                    public void onFailure(Throwable throwable) {
                                        GWT.log("Code splitting failed", throwable);
                                        MessageBox.error("Code splitting failed", throwable.getMessage());
                                    }

                                    public void onSuccess() {

                                        List<String> roles = auth.getRolesAssigned();
                                        StringBuilder roleString = new StringBuilder();
                                        int index = 1;
                                        for (String s : roles) {
                                            roleString.append(s);
                                            if (index < roles.size())
                                                roleString.append(",");
                                            index++;

                                        }

                                        // populate authentication context
                                        // this will trigger the AuthenticaionModule
                                        // and finally initialize the workspace UI

                                        Registry.get(SecurityService.class).setDeferredNotification(false);

                                        MessageBuilder.createMessage().toSubject("AuthorizationListener")
                                                .signalling().with(SecurityParts.Name, auth.getUsername())
                                                .with(SecurityParts.Roles, roleString.toString())
                                                .noErrorHandling().sendNowWith(ErraiBus.get());

                                        Timer t = new Timer() {

                                            public void run() {
                                                // hide the loading div
                                                DeferredCommand.addCommand(new Command() {
                                                    public void execute() {
                                                        DOM.getElementById("ui_loading").getStyle()
                                                                .setProperty("visibility", "hidden");
                                                        DOM.getElementById("splash").getStyle()
                                                                .setProperty("visibility", "hidden");
                                                    }
                                                });

                                            }
                                        };
                                        t.schedule(2000);

                                    }
                                });

                            }
                        });

                        window = null;
                    }

                    public void onLoginFailed(Request request, Throwable t) {
                        usernameInput.setText("");
                        passwordInput.setText("");
                        messagePanel.setHTML(
                                "<div style='color:#CC0000;'>Authentication failed. Please try again:</div>");
                    }
                });

                Registry.set(Authentication.class, auth);

                createLayoutWindowPanel();
                window.pack();
                window.center();

                // focus
                usernameInput.setFocus(true);

            }

            public void onError(Request request, Throwable t) {
                ConsoleLog.error("Failed to initiate session", t);
            }
        });
    } catch (RequestException e) {
        ConsoleLog.error("Request error", e);
    }
}

From source file:org.sakaiproject.sgs2.client.Sgs2.java

License:Educational Community License

private Command getMenuScriptsCookies() {
    return new Command() {
        public void execute() {
            Collection<String> cookyNames = Cookies.getCookieNames();
            if (cookyNames.size() == 0) {
                addConsoleMessage(i18nC.commandCookiesMsg1() + new Date().toString());
            } else {
                addConsoleMessage(i18nC.commandCookiesMsg2() + new Date().toString());
                for (String cookyName : cookyNames) {
                    addConsoleMessage(i18nC.commandCookiesName() + cookyName + "<br/>"
                            + i18nC.commandCookiesValue() + Cookies.getCookie(cookyName));
                }/*from   w  w w .j a v a 2s . co m*/
            }
        }
    };
}

From source file:votes.client.oauth.CookieStoreImpl.java

License:Apache License

@Override
public void clear() {
    for (String key : Cookies.getCookieNames()) {
        if (key.startsWith(COOKIE_PREFIX)) {
            Cookies.removeCookie(key);/*  ww w.j  av a 2  s  .  co  m*/
        }
    }
}