use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class ExecutionsImpl method startExecution.
public ExecutionContext startExecution(String key, String group) {
if (ExecutionContextHolder.getCurrentContext() != null) {
throw new IllegalStateException("Execution context already started");
}
log.debug("Start execution context: group={}, key={}", group, key);
ExecutionContextImpl context = new ExecutionContextImpl(Thread.currentThread(), key, group, timeSource.currentTimestamp());
UserSession userSession = userSessionSource.getUserSession();
CopyOnWriteArrayList<ExecutionContextImpl> executions = userSession.getLocalAttribute(EXECUTIONS_ATTR);
if (executions == null) {
userSession.setLocalAttributeIfAbsent(EXECUTIONS_ATTR, new CopyOnWriteArrayList<>());
executions = userSession.getLocalAttribute(EXECUTIONS_ATTR);
}
executions.add(context);
ExecutionContextHolder.setCurrentContext(context);
return context;
}
use of com.haulmont.cuba.security.global.UserSession 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.UserSession in project cuba by cuba-platform.
the class FileUploadController method upload.
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void upload(HttpServletRequest request, HttpServletResponse response) throws IOException {
UserSession userSession = getSession(request, response);
if (userSession == null)
return;
AppContext.setSecurityContext(new SecurityContext(userSession));
try {
InputStream is = request.getInputStream();
if (is == null) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
FileDescriptor fd = getFileDescriptor(request, response);
if (fd == null)
return;
try {
fileStorage.saveStream(fd, is);
} catch (FileStorageException e) {
log.error("Unable to upload file", e);
response.sendError(e.getType().getHttpStatus());
} finally {
IOUtils.closeQuietly(is);
}
} finally {
AppContext.setSecurityContext(null);
}
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class FileUploadController method getSession.
private UserSession getSession(HttpServletRequest request, HttpServletResponse response) throws IOException {
UUID sessionId;
try {
sessionId = UUID.fromString(request.getParameter("s"));
} catch (Exception e) {
log.error("Error parsing sessionId from URL param", e);
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return null;
}
UserSession session = userSessions.getAndRefresh(sessionId);
if (session == null)
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return session;
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class LogDownloadController method getSession.
protected UserSession getSession(String sessionId, HttpServletResponse response) throws IOException {
UUID sessionUUID;
try {
sessionUUID = UUID.fromString(sessionId);
} catch (Exception e) {
log.error("Error parsing sessionId from URL param", e);
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return null;
}
UserSession session = userSessions.getAndRefresh(sessionUUID);
if (session == null)
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return session;
}
Aggregations