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;
}
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;
}
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;
}
}
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) {
}
}
}
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();
}
}
Aggregations