Search in sources :

Example 1 with AnonymousUserCredentials

use of com.haulmont.cuba.web.security.AnonymousUserCredentials in project cuba by cuba-platform.

the class DefaultApp method connectionStateChanged.

@Override
public void connectionStateChanged(StateChangeEvent event) {
    Connection connection = event.getSource();
    log.debug("connectionStateChanged connected: {}, authenticated: {}", connection.isConnected(), connection.isAuthenticated());
    cleanupBackgroundTasks();
    closeAllWindows();
    clearSettingsCache();
    if (connection.isConnected()) {
        UserSession userSession = connection.getSessionNN();
        setLocale(userSession.getLocale());
        // substitution listeners are cleared by connection on logout
        connection.addUserSubstitutionListener(this);
        preventSessionFixation(connection, userSession);
        initExceptionHandlers(true);
        initializeUi();
        if (linkHandler != null && linkHandler.canHandleLink()) {
            linkHandler.handle();
            linkHandler = null;
        }
        afterLoggedIn();
        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!");
        }
        publishAppLoggedOutEvent(event.getPreviousSession());
    }
}
Also used : Locale(java.util.Locale) UserSession(com.haulmont.cuba.security.global.UserSession) Connection(com.haulmont.cuba.web.Connection) LoginException(com.haulmont.cuba.security.global.LoginException) AnonymousUserCredentials(com.haulmont.cuba.web.security.AnonymousUserCredentials)

Example 2 with AnonymousUserCredentials

use of com.haulmont.cuba.web.security.AnonymousUserCredentials in project cuba by cuba-platform.

the class AnonymousLoginProvider method login.

@SuppressWarnings("RedundantThrows")
@Nullable
@Override
public AuthenticationDetails login(Credentials credentials) throws LoginException {
    if (!(credentials instanceof AnonymousUserCredentials)) {
        throw new ClassCastException("Credentials cannot be cast to AnonymousUserCredentials");
    }
    AnonymousUserCredentials anonymousCredentials = (AnonymousUserCredentials) credentials;
    UserSession anonymousSession = anonymousSessionHolder.getAnonymousSession();
    Locale credentialsLocale = anonymousCredentials.getLocale();
    if (credentialsLocale != null) {
        anonymousSession.setLocale(credentialsLocale);
    }
    if (anonymousCredentials.getTimeZone() != null && Boolean.TRUE.equals(anonymousSession.getUser().getTimeZoneAuto())) {
        anonymousSession.setTimeZone(anonymousCredentials.getTimeZone());
    }
    anonymousSession.setAddress(anonymousCredentials.getIpAddress());
    anonymousSession.setClientInfo(anonymousCredentials.getClientInfo());
    if (anonymousCredentials.getSessionAttributes() != null) {
        for (Map.Entry<String, Serializable> attribute : anonymousCredentials.getSessionAttributes().entrySet()) {
            anonymousSession.setAttribute(attribute.getKey(), attribute.getValue());
        }
    }
    return new SimpleAuthenticationDetails(anonymousSession);
}
Also used : Locale(java.util.Locale) Serializable(java.io.Serializable) UserSession(com.haulmont.cuba.security.global.UserSession) SimpleAuthenticationDetails(com.haulmont.cuba.security.auth.SimpleAuthenticationDetails) Map(java.util.Map) AnonymousUserCredentials(com.haulmont.cuba.web.security.AnonymousUserCredentials) Nullable(javax.annotation.Nullable)

Aggregations

UserSession (com.haulmont.cuba.security.global.UserSession)2 AnonymousUserCredentials (com.haulmont.cuba.web.security.AnonymousUserCredentials)2 Locale (java.util.Locale)2 SimpleAuthenticationDetails (com.haulmont.cuba.security.auth.SimpleAuthenticationDetails)1 LoginException (com.haulmont.cuba.security.global.LoginException)1 Connection (com.haulmont.cuba.web.Connection)1 Serializable (java.io.Serializable)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1