Changeset 783 for TI07-MOLES/trunk


Ignore:
Timestamp:
13/04/06 17:19:14 (13 years ago)
Author:
lawrence
Message:

Scaffolding for connecting the browse portal to NDG security.

(Also includes a placeholder for putting the browse history by
using an xpath expression inside an elementtree of the output
from the xslt).

Location:
TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/browseCGI.py

    r772 r783  
    88import ElementTree 
    99from insecure import * 
     10from collections import deque # python 2.4 
     11from secure import * 
    1012 
    1113def EvaluateCredentials(ac,securityMetadata): 
     
    1315        return 1 
    1416 
     17class RingBuffer(deque): 
     18    #deque is a python 2.4 class! 
     19    #credit http://www.onlamp.com/pub/a/python/excerpt/pythonckbk_chap1/index1.html 
     20    def __init__(self, size_max): 
     21        deque.__init__(self) 
     22        self.size_max = size_max 
     23    def append(self, datum): 
     24        deque.append(self, datum) 
     25        if len(self) > self.size_max: 
     26            self.popleft( ) 
     27    def tolist(self): 
     28        return list(self) 
     29 
    1530class BrowseSession: 
    1631        ''' Holds the browse history and contact details for the NDG session manager ''' 
    17         def __init__(self,cookie): 
     32        def __init__(self,cookie,url): 
    1833                '''Instantiate and get security environment''' 
     34                # we should have two cookies, the NDG security cookie, and our browse history cookie! 
    1935                self.cookie=cookie 
    20                 self.history=[] 
     36                self.history=RingBuffer(10) 
     37                self.ndgGate=gateway2NDGsession(cookie,url) 
     38                self.__loadBrowseHistory() 
     39        def __loadBrowseHistory(self): 
     40                ''' get the string of URI values out of the cookie (if it's there)''' 
     41                try: 
     42                        strHistory=self.cookie['BrowseHistory'].value 
     43                except: 
     44                        strHistory='[]' 
     45                for uri in strHistory[1:-1].split(','): self.addToHistory(uri) 
    2146        def addToHistory(self,uri): 
    2247                ''' Add a URI to the session history''' 
    2348                self.history.append(uri) 
     49        def getHistory(self): 
     50                ''' Return a list of the items in the history ''' 
     51                return self.history.tolist() 
    2452        def getCredentials(self): 
    2553                '''Obtain the attribute certificate from the wallet ''' 
     
    6997                self.cookie=self.env.get('HTTP_COOKIE',None) 
    7098 
    71                 self.session=BrowseSession(self.cookie) 
     99                self.session=BrowseSession(self.cookie,self.path) 
    72100                 
    73101                #Handle authorisation 
Note: See TracChangeset for help on using the changeset viewer.