protected void initializeAnonymousSession() { log.debug("Initialize anonymous session"); try { this.session = loginAnonymous(); log.debug("Anonymous session initialized with id {}", session.getId()); } catch (LoginException e) { // Server should not start in this case throw new RuntimeException("Unable to create anonymous session. It is required for system to start", e); } }
protected void initializeAnonymousSession() { log.debug("Loading anonymous session"); try { this.session = getAnonymousSessionFromService(); log.debug("Anonymous session loaded with id {}", session.getId()); } catch (LoginException e) { throw new RuntimeException("Unable to obtain anonymous session from middleware", e); } }
protected void checkSession(UserSession userSession) { if (userSession.isSystem()) throw new RuntimeException("Access to system session " + userSession.getId() + " is not allowed"); }
public RestUserSessionInfo(UserSession userSession) { this.id = userSession.getId(); this.locale = userSession.getLocale(); }
protected void ownerWindowRemoved(FrameOwner frameOwner) { if (log.isTraceEnabled()) { String windowClass = frameOwner.getClass().getCanonicalName(); log.trace("Window removed. User: {}. Window: {}", getUserSession().getId(), windowClass); } taskExecutor.cancelExecution(); }
@Override public List<UUID> findUserSessionsByAttribute(String attributeName, Object attributeValue) { Preconditions.checkNotNullArgument(attributeName); //noinspection UnnecessaryLocalVariable List<UUID> sessionIds = getSessionInfoStream() .filter(usInfo -> Objects.equals(usInfo.session.getAttribute(attributeName), attributeValue)) .map(userSessionInfo -> userSessionInfo.session.getId()) .collect(Collectors.toList()); return sessionIds; }
protected void setSessionInfo(HttpServletRequest request, UserSession userSession) { userSessionService.setSessionAddress(userSession.getId(), request.getRemoteAddr()); String serverInfo = "REST API (" + globalConfig.getWebHostName() + ":" + globalConfig.getWebPort() + "/" + globalConfig.getWebContextName() + ") "; userSessionService.setSessionClientInfo(userSession.getId(), serverInfo + request.getHeader("User-Agent")); }
protected void receiveClusterMessage(UserSessionInfo message) { UUID id = message.session.getId(); if (message.lastUsedTs == 0) { log.debug("Removing session due to cluster message: {}", message); removeSessionInfo(id); } else { UserSessionInfo usi = getSessionInfo(id); if (usi == null || usi.lastUsedTs < message.lastUsedTs) { putSessionInfo(id, message); } } }
protected String generateModelerUrl(ProcModel procModel) { return "dispatch" + bpmConfig.getModelerUrl() + "?modelId=" + procModel.getActModelId() + "&s=" + userSession.getId(); }
@Override public void remove(UserSession session) { UserSessionInfo usi = removeSessionInfo(session.getId()); if (usi != null) { log.debug("Removed session: {}", usi); if (!session.isSystem()) { usi.lastUsedTs = 0; clusterManager.send(usi); } } }
public SecurityContext(UserSession session) { Preconditions.checkNotNullArgument(session, "session is null"); this.session = session; this.sessionId = session.getId(); this.user = session.getUser().getLogin(); }
protected boolean isUserSessionAlive(Connection connection) { try { UserSession session = connection.getSession(); if (session instanceof ClientUserSession && ((ClientUserSession) session).isAuthenticated()) { userSessionService.getUserSession(session.getId()); } return true; } catch (NoUserSessionException e) { return false; } }
@Override public final void execute() { checkState(!started, "Task is already started. Task: " + taskExecutor.getTask().toString()); this.started = true; TimeSource timeSource = AppBeans.get(TimeSource.NAME); this.startTimeStamp = timeSource.currentTimestamp().getTime(); this.watchDog.manageTask(this); log.trace("Run task: {}. User: {}", taskExecutor.getTask(), getUserSession().getId()); taskExecutor.startExecution(); }
@Override public boolean isAlive() { if (!isConnected()) { return false; } UserSession session = getSession(); if (session == null) { return false; } try { userSessionService.getUserSession(session.getId()); } catch (NoUserSessionException ignored) { return false; } return true; }
@Override public void deleteForCurrentSession() { QueryRunner runner = new QueryRunner(persistence.getDataSource()); try { DbTypeConverter converter = persistence.getDbTypeConverter(); UUID userSessionId = userSessionSource.getUserSession().getId(); String userSessionIdStr = converter.getSqlObject(userSessionId).toString(); runner.update("delete from SYS_QUERY_RESULT where SESSION_ID = '" + userSessionIdStr + "'"); } catch (SQLException e) { throw new RuntimeException(e); } }
protected void setSecurityContext(ScheduledTask task, @Nullable UserSession userSession) throws LoginException { if (userSession == null) { UUID sessionId = userSessionIds.get(task.getUserName()); userSession = sessionId == null ? null : userSessions.getAndRefresh(sessionId); if (userSession == null) { userSession = authenticationManager.login(new SystemUserCredentials(task.getUserName())).getSession(); userSessionIds.put(task.getUserName(), userSession.getId()); } } AppContext.setSecurityContext(new SecurityContext(userSession)); }
@Override public void processEviction() { if (!AppContext.isStarted()) return; log.trace("Processing eviction"); long now = timeSource.currentTimeMillis(); getSessionInfoStream() .filter(info -> !info.session.isSystem() && now > (info.lastUsedTs + toMillis(expirationTimeout))) .forEach(usi -> { log.debug("Removing session due to timeout: {}", usi); userSessionLog.updateSessionLogRecord(usi.getSession(), SessionAction.EXPIRATION); removeSessionInfo(usi.session.getId()); usi.lastUsedTs = 0; clusterManager.send(usi); }); }
protected void disconnectSession(Set<UserSessionEntity> selected) { for (UserSessionEntity session : selected) { if (!session.getId().equals(userSessionSource.getUserSession().getId())) { uss.killSession(session.getId()); } else { showNotification(getMessage("killUnavailable"), NotificationType.WARNING); } } sessionsTable.getDatasource().refresh(); sessionsTable.focus(); } }
@Override public void add(UserSession session) { UserSessionInfo usi = new UserSessionInfo(session, timeSource.currentTimeMillis()); putSessionInfo(session.getId(), usi); if (!session.isSystem()) { if (serverConfig.getSyncNewUserSessionReplication()) clusterManager.sendSync(usi); else clusterManager.send(usi); } }
protected UserSessionEntity createUserSessionEntity(UserSession session, long since, long lastUsedTs) { UserSessionEntity use = metadata.create(UserSessionEntity.class); use.setId(session.getId()); use.setLogin(session.getUser().getLoginLowerCase()); use.setUserName(session.getUser().getName()); use.setAddress(session.getAddress()); use.setClientInfo(session.getClientInfo()); use.setSince(new Date(since)); use.setLastUsedTs(new Date(lastUsedTs)); use.setSystem(session.isSystem()); return use; }