There are couple of ways how to do this. What is correct answer for you depends whether you are already using security framework, like Spring Security in your app or not. If you use such, then it is recommended to implement this at that level.
However if you are using vanilla Vaadin, then one approach is to implement BeforeEnterObserver interface in your MainLayou and do something like (naturally you need to implement notLoggedIn() condition specific to your app):
@Override
public void beforeEnter(BeforeEnterEvent event) {
if (notLoggedIn()) {
event.rerouteTo("login");
}
...
}