Logout based on authentication tutorial for vaadin in wiki

hi,

Based on http://vaadin.com/wiki/-/wiki/Main/Authenticating%20Vaadin-based%20applications/pop_up;jsessionid=606539F14A8E4EBB09CCBBC280869522
I’m trying to implement a logout button.

So under my LogoutButton I make a call to myApp (using threadlocal) . logout()

In the logout method It seems mandatory to remove all component included inside my mainWindow :
public void logout() {
this.user = “”;
this.password = “”;

	bannerMenu.removeAllComponents();
	mainView.removeAllComponents();
	myWindow.removeAllComponents();
	myForm.removeAllProperties();
	    	
	removeWindow(myWindow);
	setMainWindow(loginWindow);    	
}    

Indeed, else after a successfull new login, I’m redirected to the myWindow which is still filled with my old datas.
For information, the myWindow is constructed inside the loadProtectedResource() method.

private void loadProtectedResources () {
workeyWindow = new Window(“TestVaadin”);
SplitPanel vertSplit = new SplitPanel();

vertSplit.setLocked(true);
vertSplit.setHeight("100%");
vertSplit.setWidth("100%");
vertSplit.setSplitPosition(58, SplitPanel.UNITS_PIXELS);

vertSplit.addComponent(bannerMenu);
vertSplit.addComponent(mainView);

mainView.addComponent(workeyForm);

viewTable = new TView(mainView);
cbAvailableDocuments = new CBAvailableDocuments(bannerMenu);
btCreateDocument = new BTCreateDocument(bannerMenu);
cbViews = new CBViews(bannerMenu);
btGetViews = new BTGetViews(bannerMenu);				
btGetDoc = new BTGetDoc(bannerMenu);
btLogout = new BTLogout(bannerMenu);
userName = new Label(user);
bannerMenu.addComponent(userName);

myWindow.setContent(vertSplit);

    setMainWindow ( myWindow );

}

The CB & BT component dynamically fetch informations based on login & password of the connected user.

What I don’t understand is that I’m creating a new instance of myWindow but this is the old one that it is used if I don’t remove all the underlying component. Perhaps there is a better way to handle my concern ? Do you need more source code ?

Regards,
Denis.

Hello Denis,

The easiest and most common way to implement logout functionality is to just call Application.close() when the user clicks the “logout” button. Application.close() discards the current session and all data loaded into it and redirects to the URL set by calling Application.setLogoutURL(). By default the logout url is the url of your application.

HTH,
/Jonatan

Thanks it is working perfectly :slight_smile: