From 44d003cb57c33bcb08804c49f5374fb87dc10600 Mon Sep 17 00:00:00 2001
From: Sinisa Veseli <sveseli@aps.anl.gov>
Date: Thu, 8 Oct 2015 07:04:49 +0000
Subject: [PATCH] added SSO interfaces

---
 .../service/impl/authSessionControllerImpl.py | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/python/dm/ds_web_service/service/impl/authSessionControllerImpl.py b/src/python/dm/ds_web_service/service/impl/authSessionControllerImpl.py
index 12ac9cd0..44a9db0f 100755
--- a/src/python/dm/ds_web_service/service/impl/authSessionControllerImpl.py
+++ b/src/python/dm/ds_web_service/service/impl/authSessionControllerImpl.py
@@ -4,10 +4,14 @@
 # Implementation for user info controller.
 #
 
+import datetime
+import cherrypy
 from dm.common.constants import dmRole
 from dm.common.objects.authorizationPrincipal import AuthorizationPrincipal 
 from dm.common.objects.dmObjectManager import DmObjectManager
+from dm.common.objects.dmSession import DmSession
 from dm.common.db.api.userDbApi import UserDbApi
+from dm.common.exceptions.objectNotFound import ObjectNotFound
 
 class AuthSessionControllerImpl(DmObjectManager):
     """ User info controller implementation class. """
@@ -26,4 +30,22 @@ class AuthSessionControllerImpl(DmObjectManager):
                 principal.setRole(dmRole.DM_ADMIN_ROLE)
         return principal
 
+    def addSession(self, sessionId, sessionInfo):
+        sessionCache = cherrypy.session.cache
+        self.logger.debug('Session cache length: %s' % (len(sessionCache)))
+        sessionCache[sessionId] = (sessionInfo, datetime.datetime.now())
+        self.logger.debug('Session cache: %s' % (sessionCache))
+        return DmSession(sessionInfo)
+
+    def checkSession(self, sessionId):
+        sessionCache = cherrypy.session.cache
+        sessionTuple = sessionCache.get(sessionId)
+        if not sessionTuple:
+            raise ObjectNotFound('Session %s not found in cache.' % sessionId)
+        sessionInfo = sessionTuple[0]
+        oldTimestamp = sessionTuple[1]
+        newTimestamp = datetime.datetime.now()
+        self.logger.debug('Updated timestamp from %s to %s for session id %s' % (oldTimestamp, newTimestamp, sessionId))
+        sessionCache[sessionId] = (sessionInfo, newTimestamp)
+        return DmSession(sessionInfo)
 
-- 
GitLab