View Javadoc

1   /**
2    * 
3    */
4   package org.appfuse.webapp.client.ui.logout;
5   
6   import org.appfuse.webapp.client.application.Application;
7   import org.appfuse.webapp.client.application.base.activity.AbstractBaseActivity;
8   import org.appfuse.webapp.client.application.base.security.LogoutEvent;
9   
10  import com.google.gwt.event.shared.EventBus;
11  import com.google.gwt.user.client.Cookies;
12  import com.google.gwt.user.client.ui.AcceptsOneWidget;
13  import com.google.inject.Inject;
14  import com.google.web.bindery.requestfactory.shared.Receiver;
15  import com.google.web.bindery.requestfactory.shared.ServerFailure;
16  
17  /**
18   * @author ivangsa
19   *
20   */
21  public class LogoutActivity extends AbstractBaseActivity {
22  
23      @Inject
24      public LogoutActivity(final Application application) {
25          super(application);
26      }
27  
28      /**
29       * @see com.google.gwt.activity.shared.Activity#start(com.google.gwt.user.client.ui.AcceptsOneWidget,
30       *      com.google.gwt.event.shared.EventBus)
31       */
32      @Override
33      public void start(final AcceptsOneWidget panel, final EventBus eventBus) {
34          application.setCurrentUser(null);
35          requests.userRequest().logout().fire(new Receiver<Boolean>() {
36  
37              @Override
38              public void onSuccess(final Boolean response) {
39                  eventBus.fireEvent(new LogoutEvent());
40              }
41  
42              @Override
43              public void onFailure(final ServerFailure error) {
44                  Cookies.removeCookie("JSESSIONID");
45                  Cookies.removeCookie("SPRING_SECURITY_REMEMBER_ME_COOKIE");
46                  eventBus.fireEvent(new LogoutEvent());
47              }
48          });
49      }
50  
51  }