Search in sources :

Example 6 with NoUserSessionException

use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.

the class UserSessionSourceImpl method getUserSession.

@Override
public UserSession getUserSession() {
    SecurityContext securityContext = AppContext.getSecurityContextNN();
    if (securityContext.getSession() != null && securityContext.getSession().isSystem()) {
        return securityContext.getSession();
    }
    UserSession session = userSessions.getAndRefresh(securityContext.getSessionId());
    if (session == null) {
        throw new NoUserSessionException(securityContext.getSessionId());
    }
    return session;
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException)

Example 7 with NoUserSessionException

use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.

the class TestUserSessionSource method getUserSession.

@Override
public synchronized UserSession getUserSession() {
    if (exceptionOnGetUserSession) {
        throw new NoUserSessionException(UUID.fromString(USER_ID));
    }
    if (session == null) {
        User user = new User();
        user.setId(UUID.fromString(USER_ID));
        user.setLogin("test_admin");
        user.setName("Test Administrator");
        user.setPassword(DigestUtils.md5Hex("test_admin"));
        session = new UserSession(UUID.randomUUID(), user, Collections.<Role>emptyList(), Locale.forLanguageTag("en"), false);
    }
    return session;
}
Also used : Role(com.haulmont.cuba.security.entity.Role) User(com.haulmont.cuba.security.entity.User) UserSession(com.haulmont.cuba.security.global.UserSession) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException)

Example 8 with NoUserSessionException

use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.

the class ConfigCacheStrategy method updateCacheInBackground.

protected void updateCacheInBackground() {
    UserSession userSession = cacheUserSessionProvider.getUserSession();
    if (userSession == null) {
        // cache user session unavailable
        return;
    }
    try {
        AppContext.setSecurityContext(new SecurityContext(userSession));
        Map<String, String> cachedPropertiesFromServer = Collections.unmodifiableMap(configStorageService.getDbProperties());
        readWriteLock.writeLock().lock();
        try {
            cachedProperties = cachedPropertiesFromServer;
            lastUsedTs = System.currentTimeMillis();
        } finally {
            readWriteLock.writeLock().unlock();
        }
    } catch (NoUserSessionException e) {
        log.warn("Cache user session expired", e);
    } catch (Exception e) {
        log.error("Unable to update config storage cache", e);
    } finally {
        AppContext.setSecurityContext(null);
        backgroundUpdateTriggered = false;
    }
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession) SecurityContext(com.haulmont.cuba.core.sys.SecurityContext) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException)

Example 9 with NoUserSessionException

use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.

the class ServerTokenStoreImpl method removeAccessTokenFromMemory.

protected void removeAccessTokenFromMemory(String tokenValue) {
    RestUserSessionInfo sessionInfo;
    lock.writeLock().lock();
    try {
        accessTokenValueToAccessTokenStore.remove(tokenValue);
        accessTokenValueToAuthenticationStore.remove(tokenValue);
        accessTokenValueToUserLoginStore.remove(tokenValue);
        String authenticationKey = accessTokenValueToAuthenticationKeyStore.remove(tokenValue);
        if (authenticationKey != null) {
            authenticationToAccessTokenStore.remove(authenticationKey);
        }
        sessionInfo = accessTokenValueToSessionInfoStore.remove(tokenValue);
    } finally {
        lock.writeLock().unlock();
    }
    if (sessionInfo != null) {
        try {
            UserSession session = userSessions.get(sessionInfo.getId());
            if (session != null) {
                AppContext.setSecurityContext(new SecurityContext(session));
                try {
                    authenticationManager.logout();
                } finally {
                    AppContext.setSecurityContext(null);
                }
            }
        } catch (NoUserSessionException ignored) {
        }
    }
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession) SecurityContext(com.haulmont.cuba.core.sys.SecurityContext) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException)

Example 10 with NoUserSessionException

use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.

the class SessionMessagesNotifier method syncMessages.

protected void syncMessages() {
    Connection connection = App.getInstance().getConnection();
    if (connection.isConnected()) {
        log.trace("Check session messages");
        asyncMessageLoader = new SwingWorker<String, Void>() {

            @Override
            protected String doInBackground() throws Exception {
                try {
                    UserSessionService uss = AppBeans.get(UserSessionService.NAME);
                    return uss.getMessages();
                } catch (NoUserSessionException e) {
                    log.warn("Unable to get messages for session, user session not found");
                } catch (Exception e) {
                    log.warn("Session messages exception: " + e.toString());
                }
                return null;
            }

            @Override
            protected void done() {
                try {
                    if (!isCancelled()) {
                        processServerMessage(get());
                    }
                } catch (InterruptedException | ExecutionException ignored) {
                // do nothing
                } finally {
                    asyncMessageLoader = null;
                }
            }
        };
        asyncMessageLoader.execute();
    }
}
Also used : UserSessionService(com.haulmont.cuba.security.app.UserSessionService) Connection(com.haulmont.cuba.desktop.Connection) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException) ExecutionException(java.util.concurrent.ExecutionException) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException)

Aggregations

NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)17 UserSession (com.haulmont.cuba.security.global.UserSession)9 SecurityContext (com.haulmont.cuba.core.sys.SecurityContext)6 IOException (java.io.IOException)3 UUID (java.util.UUID)3 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)2 RemoteException (com.haulmont.cuba.core.global.RemoteException)2 UserSessionService (com.haulmont.cuba.security.app.UserSessionService)2 HttpSession (javax.servlet.http.HttpSession)2 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 Messages (com.haulmont.cuba.core.global.Messages)1 Connection (com.haulmont.cuba.desktop.Connection)1 Type (com.haulmont.cuba.gui.components.DialogAction.Type)1 IllegalConcurrentAccessException (com.haulmont.cuba.gui.executors.IllegalConcurrentAccessException)1 Icons (com.haulmont.cuba.gui.icons.Icons)1 App (com.haulmont.cuba.portal.App)1 Connection (com.haulmont.cuba.portal.Connection)1 PortalSession (com.haulmont.cuba.portal.security.PortalSession)1