/** * Updates all session info objects, so that invalid projects * are replaced by the Online project.<p> * * @param cms the cms context */ public void updateSessionInfos(CmsObject cms) { // get all sessions List<CmsSessionInfo> userSessions = getSessionInfos(); Iterator<CmsSessionInfo> i = userSessions.iterator(); while (i.hasNext()) { CmsSessionInfo sessionInfo = i.next(); // check is the project stored in this session is not existing anymore // if so, set it to the online project CmsUUID projectId = sessionInfo.getProject(); try { cms.readProject(projectId); } catch (CmsException e) { // the project does not longer exist, update the project information with the online project sessionInfo.setProject(CmsProject.ONLINE_PROJECT_ID); addSessionInfo(sessionInfo); } } }
/** * @see java.lang.Object#toString() */ @Override public String toString() { StringBuffer output = new StringBuffer(); Iterator i = m_sessionStorageProvider.getAll().iterator(); output.append("[CmsSessions]:\n"); while (i.hasNext()) { CmsSessionInfo sessionInfo = (CmsSessionInfo)i.next(); output.append(sessionInfo.getSessionId().toString()); output.append(" : "); output.append(sessionInfo.getUserId().toString()); output.append('\n'); } return output.toString(); }
if ((sessionInfo != null) && (m_sessions.get(sessionId) != null)) { if (sessionInfo.isExpired()) {
while (itSessions.hasNext()) { CmsSessionInfo sessionInfo = itSessions.next(); CmsListItem item = getList().newItem(sessionInfo.getSessionId().toString()); CmsUser user = getCms().readUser(sessionInfo.getUserId()); CmsOrganizationalUnit userOu = OpenCms.getOrgUnitManager().readOrganizationalUnit( getCms(), item.set(LIST_COLUMN_CREATION, new Date(sessionInfo.getTimeCreated())); item.set(LIST_COLUMN_INACTIVE, new Long(System.currentTimeMillis() - sessionInfo.getTimeUpdated())); try { item.set(LIST_COLUMN_PROJECT, getCms().readProject(sessionInfo.getProject()).getName()); } catch (Exception e) { item.set(LIST_COLUMN_SITE, sessionInfo.getSiteRoot()); ret.add(item);
CmsUUID project = sessionInfo.getProject(); siteroot = sessionInfo.getSiteRoot(); CmsUser user = m_securityManager.readUser(null, sessionInfo.getUserId()); return initCmsObject(req, user, siteroot, project, sessionInfo.getOrganizationalUnitFqn());
if (sessionInfo != null) { sessionInfo.update(cms.getRequestContext()); addSessionInfo(sessionInfo); } else { sessionInfo = new CmsSessionInfo( cms.getRequestContext(), new CmsUUID(), session.getMaxInactiveInterval()); session.setAttribute(CmsSessionInfo.ATTRIBUTE_SESSION_ID, sessionInfo.getSessionId().clone());
/** * Sends a broadcast to all sessions of a given user.<p> * * The user sending the message may be a real user like * <code>cms.getRequestContext().currentUser()</code> or * <code>null</code> for a system message.<p> * * @param fromUser the user sending the broadcast * @param message the message to broadcast * @param toUser the target (receiver) of the broadcast */ public void sendBroadcast(CmsUser fromUser, String message, CmsUser toUser) { if (CmsStringUtil.isEmptyOrWhitespaceOnly(message)) { // don't broadcast empty messages return; } // create the broadcast CmsBroadcast broadcast = new CmsBroadcast(fromUser, message); List<CmsSessionInfo> userSessions = getSessionInfos(toUser.getId()); Iterator<CmsSessionInfo> i = userSessions.iterator(); // send the broadcast to all sessions of the selected user while (i.hasNext()) { CmsSessionInfo sessionInfo = i.next(); if (m_sessionStorageProvider.get(sessionInfo.getSessionId()) != null) { // double check for concurrent modification sessionInfo.getBroadcastQueue().add(broadcast); } } }
CmsSessionInfo newInfo = new CmsSessionInfo(context, info.getSessionId(), info.getMaxInactiveInterval()); addSessionInfo(newInfo);
/** * Allows sorting session info according to the user names.<p> * * @see java.lang.Comparable#compareTo(java.lang.Object) */ public int compareTo(CmsSessionInfo obj) { if (obj == this) { return 0; } return m_userId.compareTo(obj.getUserId()); }
/** * @see org.opencms.main.I_CmsSessionStorageProvider#put(org.opencms.main.CmsSessionInfo) */ public CmsSessionInfo put(CmsSessionInfo sessionInfo) { return (CmsSessionInfo)m_sessions.put(sessionInfo.getSessionId(), sessionInfo); }
/** * Returns the broadcast queue for the given OpenCms session id.<p> * * @param sessionId the OpenCms session id to get the broadcast queue for * * @return the broadcast queue for the given OpenCms session id */ public Buffer getBroadcastQueue(String sessionId) { CmsSessionInfo sessionInfo = getSessionInfo(getSessionUUID(sessionId)); if (sessionInfo == null) { // return empty message buffer if the session is gone or not available return BufferUtils.synchronizedBuffer(new CircularFifoBuffer(CmsSessionInfo.QUEUE_SIZE)); } return sessionInfo.getBroadcastQueue(); }
/** * Updates the session info object with the information from * the given request context.<p> * * @param context the request context to update the session with */ protected void update(CmsRequestContext context) { m_timeUpdated = System.currentTimeMillis(); m_siteRoot = context.getSiteRoot(); setProject(context.getCurrentProject().getUuid()); m_ouFqn = context.getOuFqn(); } }
if (!user.isGuestUser() && !OpenCms.getDefaultUsers().isUserExport(user.getName())) { CmsSessionInfo sessionInfo = new CmsSessionInfo( cms.getRequestContext(), new CmsUUID(),
CmsUUID project = sessionInfo.getProject(); siteroot = sessionInfo.getSiteRoot(); } else if (getSiteManager().isWorkplaceRequest(req)) { siteroot = sessionInfo.getSiteRoot(); } else if (site.hasSecureServer() && getSiteManager().getWorkplaceSiteMatcher().getUrl().equals(site.getSecureUrl())) { siteroot = sessionInfo.getSiteRoot(); } else { siteroot = site.getSiteRoot(); CmsUser user = m_securityManager.readUser(null, sessionInfo.getUserId()); return initCmsObject(req, user, siteroot, project, sessionInfo.getOrganizationalUnitFqn());
if (sessionInfo != null) { sessionInfo.update(cms.getRequestContext()); addSessionInfo(sessionInfo); } else { sessionInfo = new CmsSessionInfo( cms.getRequestContext(), new CmsUUID(), session.getMaxInactiveInterval()); session.setAttribute(CmsSessionInfo.ATTRIBUTE_SESSION_ID, sessionInfo.getSessionId().clone());
/** * Sends a broadcast to all sessions of all currently authenticated users.<p> * * @param cms the OpenCms user context of the user sending the broadcast * * @param message the message to broadcast */ public void sendBroadcast(CmsObject cms, String message) { if (CmsStringUtil.isEmptyOrWhitespaceOnly(message)) { // don't broadcast empty messages return; } // create the broadcast CmsBroadcast broadcast = new CmsBroadcast(cms.getRequestContext().currentUser(), message); // send the broadcast to all authenticated sessions Iterator i = m_sessionStorageProvider.getAll().iterator(); while (i.hasNext()) { CmsSessionInfo sessionInfo = (CmsSessionInfo)i.next(); if (m_sessionStorageProvider.get(sessionInfo.getSessionId()) != null) { // double check for concurrent modification sessionInfo.getBroadcastQueue().add(broadcast); } } }
CmsSessionInfo newInfo = new CmsSessionInfo(context, info.getSessionId(), info.getMaxInactiveInterval()); addSessionInfo(newInfo);
/** * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof CmsSessionInfo) { return m_userId.equals(((CmsSessionInfo)obj).getUserId()); } return false; }
/** * @see org.opencms.main.I_CmsSessionStorageProvider#put(org.opencms.main.CmsSessionInfo) */ public CmsSessionInfo put(CmsSessionInfo sessionInfo) { return (CmsSessionInfo)m_sessions.put(sessionInfo.getSessionId(), sessionInfo); }
/** * Returns the broadcast queue for the given OpenCms session id.<p> * * @param sessionId the OpenCms session id to get the broadcast queue for * * @return the broadcast queue for the given OpenCms session id */ public Buffer getBroadcastQueue(String sessionId) { CmsSessionInfo sessionInfo = getSessionInfo(getSessionUUID(sessionId)); if (sessionInfo == null) { // return empty message buffer if the session is gone or not available return BufferUtils.synchronizedBuffer(new CircularFifoBuffer(CmsSessionInfo.QUEUE_SIZE)); } return sessionInfo.getBroadcastQueue(); }