Search in sources :

Example 1 with ClientUserSession

use of com.haulmont.cuba.client.ClientUserSession in project cuba by cuba-platform.

the class Connection method login.

public void login(String login, String password, Locale locale) throws LoginException {
    UserSession userSession = doLogin(login, password, locale, getLoginParams());
    ClientUserSession clientUserSession = new ClientUserSession(userSession);
    clientUserSession.setAuthenticated(true);
    session = clientUserSession;
    AppContext.setSecurityContext(new SecurityContext(session));
    log.info("Logged in: {}", session);
    updateSessionClientInfo();
    connected = true;
    fireConnectionListeners();
}
Also used : ClientUserSession(com.haulmont.cuba.client.ClientUserSession) ClientUserSession(com.haulmont.cuba.client.ClientUserSession) UserSession(com.haulmont.cuba.security.global.UserSession) SecurityContext(com.haulmont.cuba.core.sys.SecurityContext)

Example 2 with ClientUserSession

use of com.haulmont.cuba.client.ClientUserSession in project cuba by cuba-platform.

the class AppUI method refresh.

@Override
protected void refresh(VaadinRequest request) {
    super.refresh(request);
    boolean sessionIsAlive = true;
    Connection connection = app.getConnection();
    if (connection.isAuthenticated()) {
        // Ping middleware session if connected
        log.debug("Ping middleware session");
        try {
            UserSession session = connection.getSession();
            if (session instanceof ClientUserSession && ((ClientUserSession) session).isAuthenticated()) {
                userSessionService.getUserSession(session.getId());
            }
        } catch (Exception e) {
            sessionIsAlive = false;
            app.exceptionHandlers.handle(new com.vaadin.server.ErrorEvent(e));
        }
        if (sessionIsAlive) {
            events.publish(new SessionHeartbeatEvent(app));
        }
    }
    if (sessionIsAlive) {
        events.publish(new UIRefreshEvent(this));
    }
}
Also used : ClientUserSession(com.haulmont.cuba.client.ClientUserSession) SessionHeartbeatEvent(com.haulmont.cuba.web.security.events.SessionHeartbeatEvent) ClientUserSession(com.haulmont.cuba.client.ClientUserSession) UserSession(com.haulmont.cuba.security.global.UserSession) LoginException(com.haulmont.cuba.security.global.LoginException) UIRefreshEvent(com.haulmont.cuba.web.events.UIRefreshEvent)

Example 3 with ClientUserSession

use of com.haulmont.cuba.client.ClientUserSession in project cuba by cuba-platform.

the class ConnectionImpl method substituteUser.

@Override
public void substituteUser(User substitutedUser) {
    UserSession previousSession = getSession();
    UserSession session = authenticationService.substituteUser(substitutedUser);
    ClientUserSession clientUserSession = createSession(session);
    clientUserSession.setAuthenticated(true);
    setSessionInternal(clientUserSession);
    publishUserSessionSubstitutedEvent(previousSession, clientUserSession);
    fireSubstitutionListeners();
}
Also used : ClientUserSession(com.haulmont.cuba.client.ClientUserSession) ClientUserSession(com.haulmont.cuba.client.ClientUserSession)

Example 4 with ClientUserSession

use of com.haulmont.cuba.client.ClientUserSession in project cuba by cuba-platform.

the class ConnectionImpl method logout.

@Override
public void logout() {
    backgroundWorker.checkUIAccess();
    ClientUserSession session = getSessionInternal();
    if (session == null) {
        throw new IllegalStateException("There is no active session");
    }
    if (!session.isAuthenticated()) {
        throw new IllegalStateException("Active session is not authenticated");
    }
    if (session.isAuthenticated()) {
        authenticationService.logout();
    }
    publishUserSessionFinishedEvent(session);
    UserSession previousSession = getSession();
    setSessionInternal(null);
    removeListeners(UserSubstitutionListener.class);
    publishDisconnectedEvent(previousSession);
    fireStateChangeListeners(previousSession, null);
}
Also used : ClientUserSession(com.haulmont.cuba.client.ClientUserSession) ClientUserSession(com.haulmont.cuba.client.ClientUserSession)

Example 5 with ClientUserSession

use of com.haulmont.cuba.client.ClientUserSession in project cuba by cuba-platform.

the class ConnectionImpl method login.

@Override
public void login(Credentials credentials) throws LoginException {
    backgroundWorker.checkUIAccess();
    preprocessCredentials(credentials);
    AuthenticationDetails authenticationDetails = loginInternal(credentials);
    ClientUserSession clientUserSession = createSession(authenticationDetails.getSession());
    if (credentials instanceof AnonymousUserCredentials) {
        clientUserSession.setAuthenticated(false);
    } else {
        clientUserSession.setAuthenticated(true);
    }
    UserSession previousSession = getSession();
    setSessionInternal(clientUserSession);
    publishUserConnectedEvent(credentials);
    fireStateChangeListeners(previousSession, clientUserSession);
}
Also used : ClientUserSession(com.haulmont.cuba.client.ClientUserSession) ClientUserSession(com.haulmont.cuba.client.ClientUserSession) AuthenticationDetails(com.haulmont.cuba.security.auth.AuthenticationDetails)

Aggregations

ClientUserSession (com.haulmont.cuba.client.ClientUserSession)6 UserSession (com.haulmont.cuba.security.global.UserSession)3 SecurityContext (com.haulmont.cuba.core.sys.SecurityContext)1 AuthenticationDetails (com.haulmont.cuba.security.auth.AuthenticationDetails)1 LoginException (com.haulmont.cuba.security.global.LoginException)1 UIRefreshEvent (com.haulmont.cuba.web.events.UIRefreshEvent)1 SessionHeartbeatEvent (com.haulmont.cuba.web.security.events.SessionHeartbeatEvent)1