source: TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/browseCGI.py @ 765

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/browseCGI.py@765
Revision 765, 2.5 KB checked in by lawrence, 13 years ago (diff)

This version of the browse portal simply gets the stub-b
document and shows it to the user. No security. No xslt
transformation.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2# CGI Script to support prototype NDG MOLES_Portal (Browse) functionality
3# Bryan Lawrence, April, 2006
4
5import cgi
6#import cgitb;ctitb.enable()
7import os
8import ElementTree
9from insecure import *
10
11def EvaluateCredentials(ac,securityMetadata):
12        ''' Take Moles security metadata and compare with attribute certificate '''
13        return 1
14
15class BrowseSession:
16        ''' Holds the browse history and contact details for the NDG session manager '''
17        def __init__(self,cookie):
18                '''Instantiate and get security environment'''
19                self.cookie=cookie
20                self.history=[]
21        def addToHistory(self,uri):
22                ''' Add a URI to the session history'''
23                self.history.append(uri)
24        def getCredentials(self):
25                '''Obtain the attribute certificate from the wallet '''
26                return 'empty attribute certificate'
27
28class StubB:
29        ''' Holds the stub-b document and provides methods which get and manipulate it '''
30       
31        def __init__(self,uri,xsltMethod='JavaXalan'):
32                '''Instantiate by getting URI from exist database'''
33                #try:
34                self.xml=insecureGetDoc(uri)
35                #except:
36                #       raise 'NotFound'
37                self.xsltMethod=xsltMethod
38       
39        def getSecurityDetails(self):
40                '''Obtain the roles and attribute authority address'''
41                #issue an xquery on the stub-b
42                #parse for roles
43                #parse for AA WSDL
44                #tree=ElementTree.fromstring(self.xml)
45                #sec=tree.findall('//ndgSecurity')
46                roles=[]
47                AAaddress=''
48                return roles, AAaddress
49       
50        def toHTML(self):
51                return doXSLT(self.xml,self.xsltMethod)
52               
53class CGIcontroller:
54        ''' Currently holds the cgi environment and controls '''
55       
56        def __init__(self):
57                ''' Instantiate the CGI environment'''
58                self.env=os.environ
59                self.path=self.env.get('PATH_INFO','/')
60                self.FieldStorage=cgi.FieldStorage()
61
62        def goforit(self):
63                ''' This method actually responds to the user'''
64               
65                #Instantiate the Session Environment
66                self.cookie=self.env.get('HTTP_COOKIE',None)
67
68                self.session=BrowseSession(self.cookie)
69               
70                #Handle authorisation
71                self.ac=self.session.getCredentials()
72       
73                #this will do for the moment, although I'd rather the whole
74                #URI was self consistent ...
75                if self.FieldStorage.has_key('uri'):
76                        self.uri=self.FieldStorage['uri'].value
77                else: 
78                        return self.error('No valid URI')
79                try:
80                        self.b=StubB(self.uri)
81                except 'NotFound':
82                        return self.error('URI cannot be retrieved from DataBase')
83                       
84                if EvaluateCredentials(self.ac,self.uri):
85                        #we can show the user the page
86                        return self.b.toHTML()
87                else:
88                        return self.error('Not Allowed')
89               
90        def error(self,message):
91                ''' Construct a nice formal response with appropriate HTML headers '''
92                return '<error>%s</error>'%message
93               
Note: See TracBrowser for help on using the repository browser.