use of com.haulmont.cuba.web.Connection.StateChangeEvent in project cuba by cuba-platform.
the class DefaultApp method connectionStateChanged.
protected void connectionStateChanged(StateChangeEvent event) {
Connection connection = event.getSource();
log.debug("connectionStateChanged connected: {}, authenticated: {}", connection.isConnected(), connection.isAuthenticated());
cleanupBackgroundTasks();
removeAllWindows();
clearSettingsCache();
if (connection.isConnected()) {
UserSession userSession = connection.getSessionNN();
setLocale(userSession.getLocale());
// substitution listeners are cleared by connection on logout
connection.addUserSubstitutionListener(this::userSubstituted);
preventSessionFixation(connection, userSession);
initExceptionHandlers(true);
AppUI currentUi = AppUI.getCurrent();
if (currentUi != null) {
UserSession oldUserSession = currentUi.getUserSession();
currentUi.setUserSession(connection.getSession());
getAppUIs().stream().filter(ui -> ui.hasAuthenticatedSession() && (Objects.equals(ui.getUserSession(), oldUserSession) || webConfig.getForceRefreshAuthenticatedTabs())).forEach(ui -> ui.setUserSession(userSession));
}
if (connection.isAuthenticated()) {
notifyMismatchedUIs(userSession);
}
initializeUi();
if (linkHandler != null && linkHandler.canHandleLink()) {
linkHandler.handle();
linkHandler = null;
}
RedirectHandler redirectHandler = currentUi != null && currentUi.getUrlChangeHandler() != null ? currentUi.getUrlChangeHandler().getRedirectHandler() : null;
if (redirectHandler != null && redirectHandler.scheduled()) {
redirectHandler.redirect();
}
publishAppLoggedInEvent();
} else {
initExceptionHandlers(false);
VaadinRequest currentRequest = VaadinService.getCurrentRequest();
if (currentRequest != null) {
Locale requestLocale = currentRequest.getLocale();
setLocale(resolveLocale(requestLocale));
}
try {
connection.login(new AnonymousUserCredentials(getLocale()));
} catch (LoginException e) {
throw new RuntimeException("Unable to login as anonymous!", e);
}
publishAppLoggedOutEvent(event.getPreviousSession());
}
}
Aggregations