WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] [XEND] Xen API Auth Manager for handling

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] [XEND] Xen API Auth Manager for handling sessions
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 02 Nov 2006 22:08:21 +0000
Delivery-date: Thu, 02 Nov 2006 21:40:29 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User acnt2@xxxxxxxxxxxxxxxxxxxxxxxx
# Node ID 48c5a79c4fbf7ef1472cbf2f95bd2f4f42f3c9fc
# Parent  5fe8e9ebcf5c1da30e0da4e7f66a81de37406dc1
[XEND] Xen API Auth Manager for handling sessions

Signed-off-by: Alastair Tse <atse@xxxxxxxxxxxxx>
---
 tools/python/xen/xend/XendAuthSessions.py |   86 ++++++++++++++++++++++++++++++
 1 files changed, 86 insertions(+)

diff -r 5fe8e9ebcf5c -r 48c5a79c4fbf tools/python/xen/xend/XendAuthSessions.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/python/xen/xend/XendAuthSessions.py Thu Oct 05 17:29:19 2006 +0100
@@ -0,0 +1,86 @@
+#============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd.
+#============================================================================
+
+import time
+
+from xen.xend import uuid
+from xen.xend.XendError import *
+from xen.xend.XendLogging import log
+
+class XendAuthSessions:
+    """Keeps track of Xen API Login Sessions. (Example only)"""
+
+    def __init__(self):
+        self.sessions = {}
+        self.users = {'atse': 'passwd'}
+
+    def init(self):
+        pass
+
+    def login_with_password(self, username, password):
+        if self.is_authorized(username, password):
+            new_session = uuid.createString()
+            self.sessions[new_session] = (username, time.time())
+            return new_session
+
+        raise XendError("Login failed")
+
+    def logout(self, session):
+        if self.is_session_valid(session):
+            del self.sessions[session]
+
+    def is_session_valid(self, session):
+        log.debug('isSessionValid: %s' % session)
+        if type(session) == type(str()):
+            return (session in self.sessions)
+        return False
+    
+    def is_authorized(self, username, password):
+        if username in self.users and self.users[username] == password:
+            return True
+        return False
+
+    def get_user(self, session):
+        try:
+            return self.sessions[session][0]
+        except (KeyError, IndexError):
+            return None
+
+
+def instance():
+    """Singleton constructor. Use this instead of the class constructor.
+    """
+    global inst
+    try:
+        inst
+    except:
+        inst = XendAuthSessions()
+        inst.init()
+    return inst
+
+# Handy Authentication Decorators
+# -------------------------------
+def session_required(func):
+    def check_session(self, session, *args, **kwargs):
+        if instance().is_session_valid(session):
+            return func(self, session, *args, **kwargs)
+        else:
+            return {'Status': 'Failure',
+                    'ErrorDescription': XEND_ERROR_SESSION_INVALID}
+    return check_session
+
+

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] [XEND] Xen API Auth Manager for handling sessions, Xen patchbot-unstable <=