Author: justi9
Date: 2009-10-07 10:55:57 -0400 (Wed, 07 Oct 2009)
New Revision: 3669
Modified:
mgmt/trunk/cumin/python/cumin/main.py
mgmt/trunk/cumin/python/cumin/server.py
mgmt/trunk/cumin/python/cumin/test.py
mgmt/trunk/cumin/python/cumin/widgets.py
mgmt/trunk/wooly/python/wooly/server.py
Log:
Move auth checking into CuminPage
Modified: mgmt/trunk/cumin/python/cumin/main.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/main.py 2009-10-05 18:34:36 UTC (rev 3668)
+++ mgmt/trunk/cumin/python/cumin/main.py 2009-10-07 14:55:57 UTC (rev 3669)
@@ -70,15 +70,11 @@
self.add_page(StatFlashPage(self, "chart.json"))
self.add_page(FlashFullPage(self, "flashpage.html"))
- unprotected = set()
+ self.login_page.protected = False
+ self.login_page.css_page.protected = False
+ self.login_page.javascript_page.protected = False
+ self.resource_page.protected = False
- unprotected.add(self.resource_page)
- unprotected.add(self.login_page)
- unprotected.add(self.login_page.css_page)
- unprotected.add(self.login_page.javascript_page)
-
- self.unprotected_pages = unprotected
-
self.user_sessions_by_id = dict()
self.user_session_expire_thread = UserSessionExpireThread(self)
Modified: mgmt/trunk/cumin/python/cumin/server.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/server.py 2009-10-05 18:34:36 UTC (rev 3668)
+++ mgmt/trunk/cumin/python/cumin/server.py 2009-10-07 14:55:57 UTC (rev 3669)
@@ -11,43 +11,4 @@
class CuminServer(WebServer):
def authorized(self, session):
- auth = False
- page = session.page
-
- if page in self.app.unprotected_pages:
- return True
-
- id = session.get_cookie("session")
-
- if id is not None:
- usess = self.app.user_sessions_by_id.get(id)
-
- if usess is not None:
- timeout = timedelta(seconds=3600)
- now = datetime.now()
-
- if now > usess.created and now < usess.created + timeout:
- setattr(session, "user_session", usess)
-
- return True
-
- if self.app.config.user:
- user = Subject.getByName(self.app.config.user)
-
- assert user
-
- usess = UserSession(self.app, user)
- session.set_cookie("session", usess.id)
-
- page.redirect.set(session, session.marshal())
-
- return False
-
- lpage = self.app.login_page
-
- lsess = Session(lpage)
- lpage.origin.set(lsess, session.marshal())
-
- page.redirect.set(session, lsess.marshal())
-
- return False
+ return True
Modified: mgmt/trunk/cumin/python/cumin/test.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/test.py 2009-10-05 18:34:36 UTC (rev 3668)
+++ mgmt/trunk/cumin/python/cumin/test.py 2009-10-07 14:55:57 UTC (rev 3669)
@@ -1,6 +1,8 @@
+from mint import Subject
from parsley.test import *
from wooly import *
+from user import *
from util import *
log = logging.getLogger("cumin.test")
@@ -10,6 +12,7 @@
super(CuminTest, self).__init__("cumin", None)
self.app = app
+ self.user = None
def init(self):
for module in self.app.modules:
@@ -30,6 +33,12 @@
if not connected:
raise Exception("Failed to connect to broker")
+ self.user = Subject.getByName("tester")
+
+ if not self.user:
+ self.user = Subject(name="tester")
+ self.user.syncUpdate()
+
super(CuminTest, self).do_run(session)
class TaskFormTest(Test):
@@ -66,6 +75,9 @@
def __init__(self, harness):
super(MainPageSession, self).__init__(harness.test.app.main_page)
+ usess = UserSession(harness.test.app, harness.test.user)
+ self.user_session = usess
+
def retry(fn):
result = None
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2009-10-05 18:34:36 UTC (rev 3668)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2009-10-07 14:55:57 UTC (rev 3669)
@@ -12,6 +12,7 @@
from widgets import *
from charts import *
from formats import *
+from user import *
from util import *
import time
@@ -135,11 +136,6 @@
self.show_object(branch, object)
return branch.marshal()
- def do_process(self, session, *args):
- self.page.get_frames(session).append(self)
-
- super(CuminFrame, self).do_process(session, *args)
-
def render_href(self, session, *args):
branch = session.branch()
@@ -175,9 +171,12 @@
def render_frames(self, session):
writer = Writer()
- for frame in self.page.get_frames(session):
- self.__frame_tmpl.render(writer, session, frame)
+ for frame in reversed(self.frame.ancestors):
+ if isinstance(frame, CuminFrame):
+ self.__frame_tmpl.render(writer, session, frame)
+ self.__frame_tmpl.render(writer, session, self.frame)
+
return writer.to_string()
def render_frame(self, session, frame):
@@ -1297,33 +1296,59 @@
def __init__(self, app, name):
super(CuminPage, self).__init__(app, name)
- self.__frames = self.FramesAttribute(app, "frames")
- self.add_attribute(self.__frames)
+ self.protected = True
- self.__modal = Attribute(app, "modal")
- self.add_attribute(self.__modal)
-
self.user = UserAttribute(app, "user")
self.add_attribute(self.user)
- def save_session(self, session):
- if self.app.debug:
- self.app.debug.sessions.append(session)
+ def do_process(self, session):
+ if self.authorized(session):
+ super(CuminPage, self).do_process(session)
- def set_modal(self, session, modal):
- self.__modal.set(session, modal)
+ def authorized(self, session):
+ if not self.protected:
+ return True
- def get_frames(self, session):
- return self.__frames.get(session)
+ id = session.get_cookie("session")
- def render_class(self, session):
- return self.__modal.get(session) and "modal" or "_"
+ if id is not None:
+ usess = self.app.user_sessions_by_id.get(id)
- class FramesAttribute(Attribute):
- def get_default(self, session):
- return list()
+ if usess is not None:
+ timeout = timedelta(seconds=3600)
+ now = datetime.now()
-class CuminFormPage(HtmlPage):
+ if now > usess.created and now < usess.created + timeout:
+ setattr(session, "user_session", usess)
+
+ return True
+
+ if self.app.config.user:
+ user = Subject.getByName(self.app.config.user)
+
+ assert user
+
+ usess = UserSession(self.app, user)
+ session.set_cookie("session", usess.id)
+
+ self.redirect.set(session, session.marshal())
+
+ return True
+
+ lpage = self.app.login_page
+
+ lsess = Session(lpage)
+ lpage.origin.set(lsess, session.marshal())
+
+ self.redirect.set(session, lsess.marshal())
+
+ return False
+
+ def save_session(self, session):
+ if self.app.debug:
+ self.app.debug.sessions.append(session)
+
+class CuminFormPage(CuminPage):
def __init__(self, app, name):
super(CuminFormPage, self).__init__(app, name)
Modified: mgmt/trunk/wooly/python/wooly/server.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/server.py 2009-10-05 18:34:36 UTC (rev 3668)
+++ mgmt/trunk/wooly/python/wooly/server.py 2009-10-07 14:55:57 UTC (rev 3669)
@@ -50,7 +50,7 @@
self.adapt_request_environment(env, session)
if not self.authorized(session):
- url = page.get_redirect_url(session)
+ url = page.redirect.get(session)
if url:
return self.send_redirect(response, headers, session, url)
@@ -62,7 +62,7 @@
except:
return self.send_error(response, headers, session)
- url = page.get_redirect_url(session)
+ url = page.redirect.get(session)
if url:
return self.send_redirect(response, headers, session, url)