Search in sources :

Example 1 with RedirectHandler

use of com.haulmont.cuba.web.sys.RedirectHandler 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());
    }
}
Also used : AppLoginWindow(com.haulmont.cuba.web.app.loginwindow.AppLoginWindow) com.vaadin.server(com.vaadin.server) UI(com.vaadin.ui.UI) LoggerFactory(org.slf4j.LoggerFactory) LoginException(com.haulmont.cuba.security.global.LoginException) RedirectHandler(com.haulmont.cuba.web.sys.RedirectHandler) StringUtils(org.apache.commons.lang3.StringUtils) Scope(org.springframework.context.annotation.Scope) UserSession(com.haulmont.cuba.security.global.UserSession) ExternalUserCredentials.isLoggedInWithExternalAuth(com.haulmont.cuba.web.security.ExternalUserCredentials.isLoggedInWithExternalAuth) Strings(com.google.common.base.Strings) AppStartedEvent(com.haulmont.cuba.web.security.events.AppStartedEvent) AppLoggedOutEvent(com.haulmont.cuba.web.security.events.AppLoggedOutEvent) Locale(java.util.Locale) Screens(com.haulmont.cuba.gui.Screens) OpenMode(com.haulmont.cuba.gui.screen.OpenMode) Nullable(javax.annotation.Nullable) HttpSession(javax.servlet.http.HttpSession) UserSubstitutedEvent(com.haulmont.cuba.web.Connection.UserSubstitutedEvent) AppLoggedInEvent(com.haulmont.cuba.web.security.events.AppLoggedInEvent) Logger(org.slf4j.Logger) IOException(java.io.IOException) Messages(com.haulmont.cuba.core.global.Messages) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) AnonymousUserCredentials(com.haulmont.cuba.web.security.AnonymousUserCredentials) StateChangeEvent(com.haulmont.cuba.web.Connection.StateChangeEvent) Notifications(com.haulmont.cuba.gui.Notifications) VaadinSessionScope(com.haulmont.cuba.web.sys.VaadinSessionScope) Locale(java.util.Locale) RedirectHandler(com.haulmont.cuba.web.sys.RedirectHandler) UserSession(com.haulmont.cuba.security.global.UserSession) LoginException(com.haulmont.cuba.security.global.LoginException) AnonymousUserCredentials(com.haulmont.cuba.web.security.AnonymousUserCredentials)

Example 2 with RedirectHandler

use of com.haulmont.cuba.web.sys.RedirectHandler in project cuba by cuba-platform.

the class UrlChangeHandler method redirect.

public void redirect(NavigationState navigationState) {
    String loginScreenId = webConfig.getLoginScreenId();
    Screen loginScreen = ui.getScreens().create(loginScreenId, OpenMode.ROOT);
    loginScreen.show();
    RedirectHandler redirectHandler = beanLocator.getPrototype(RedirectHandler.NAME, ui);
    redirectHandler.schedule(navigationState);
    setRedirectHandler(redirectHandler);
}
Also used : Screen(com.haulmont.cuba.gui.screen.Screen) RedirectHandler(com.haulmont.cuba.web.sys.RedirectHandler)

Aggregations

RedirectHandler (com.haulmont.cuba.web.sys.RedirectHandler)2 Strings (com.google.common.base.Strings)1 Messages (com.haulmont.cuba.core.global.Messages)1 Notifications (com.haulmont.cuba.gui.Notifications)1 Screens (com.haulmont.cuba.gui.Screens)1 OpenMode (com.haulmont.cuba.gui.screen.OpenMode)1 Screen (com.haulmont.cuba.gui.screen.Screen)1 LoginException (com.haulmont.cuba.security.global.LoginException)1 UserSession (com.haulmont.cuba.security.global.UserSession)1 StateChangeEvent (com.haulmont.cuba.web.Connection.StateChangeEvent)1 UserSubstitutedEvent (com.haulmont.cuba.web.Connection.UserSubstitutedEvent)1 AppLoginWindow (com.haulmont.cuba.web.app.loginwindow.AppLoginWindow)1 AnonymousUserCredentials (com.haulmont.cuba.web.security.AnonymousUserCredentials)1 ExternalUserCredentials.isLoggedInWithExternalAuth (com.haulmont.cuba.web.security.ExternalUserCredentials.isLoggedInWithExternalAuth)1 AppLoggedInEvent (com.haulmont.cuba.web.security.events.AppLoggedInEvent)1 AppLoggedOutEvent (com.haulmont.cuba.web.security.events.AppLoggedOutEvent)1 AppStartedEvent (com.haulmont.cuba.web.security.events.AppStartedEvent)1 VaadinSessionScope (com.haulmont.cuba.web.sys.VaadinSessionScope)1 com.vaadin.server (com.vaadin.server)1 UI (com.vaadin.ui.UI)1