#authenticateUser!/usr/bin/env python import json import cherrypy from dm.common.utility.encoder import Encoder from dm.common.exceptions.invalidRequest import InvalidRequest from dm.common.service.dmSessionController import DmSessionController from dm.ds_web_service.service.impl.authSessionControllerImpl import AuthSessionControllerImpl class AuthSessionController(DmSessionController): def __init__(self): DmSessionController.__init__(self) self.authSessionControllerImpl = AuthSessionControllerImpl() @cherrypy.expose @DmSessionController.require(DmSessionController.isAdministrator()) @DmSessionController.execute def getAuthorizationPrincipal(self, username, **kwargs): if not len(username): raise InvalidRequest('Invalid username provided.') response = self.authSessionControllerImpl.getAuthorizationPrincipal(username).getFullJsonRep() self.logger.debug('Returning authorization principal for %s' % (username)) return response @cherrypy.expose @DmSessionController.require(DmSessionController.isAdministrator()) @DmSessionController.execute def addSession(self, sessionId, **kwargs): if not len(sessionId): raise InvalidRequest('Invalid session id provided.') sessionInfo = kwargs.get('sessionInfo') if not sessionInfo: raise InvalidRequest('Missing session object.') sessionInfo = json.loads(Encoder.decode(sessionInfo)) response = self.authSessionControllerImpl.addSession(sessionId, sessionInfo).getFullJsonRep() self.logger.debug('Session %s added to cache' % (sessionInfo)) return response @cherrypy.expose @DmSessionController.require(DmSessionController.isAdministrator()) @DmSessionController.execute def checkSession(self, sessionId, **kwargs): if not len(sessionId): raise InvalidRequest('Invalid session id provided.') response = self.authSessionControllerImpl.checkSession(sessionId).getFullJsonRep() self.logger.debug('Verified session %s' % (sessionId)) return response