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

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

This version calls documents from exist, loads and transforms them
using xalan.
To-do:

(1) results are not yet acceptable,
(2) need to get and parse the security metadata
(3) need to connect to Phil's security code.

  • 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                #self.xml=uri
36                #except:
37                #       raise 'NotFound'
38                self.xsltMethod=xsltMethod
39       
40        def getSecurityDetails(self):
41                '''Obtain the roles and attribute authority address'''
42                #issue an xquery on the stub-b
43                #parse for roles
44                #parse for AA WSDL
45                #tree=ElementTree.fromstring(self.xml)
46                #sec=tree.findall('//ndgSecurity')
47                roles=[]
48                AAaddress=''
49                return roles, AAaddress
50       
51        def toHTML(self):
52                x=doXSLT(self.xml,xsltMethod=self.xsltMethod)
53                #return '<p>%s</p>'%x
54                return x
55       
56class CGIcontroller:
57        ''' Currently holds the cgi environment and controls '''
58       
59        def __init__(self):
60                ''' Instantiate the CGI environment'''
61                self.env=os.environ
62                self.path=self.env.get('PATH_INFO','/')
63                self.FieldStorage=cgi.FieldStorage()
64
65        def goforit(self):
66                ''' This method actually responds to the user'''
67               
68                #Instantiate the Session Environment
69                self.cookie=self.env.get('HTTP_COOKIE',None)
70
71                self.session=BrowseSession(self.cookie)
72               
73                #Handle authorisation
74                self.ac=self.session.getCredentials()
75       
76                #this will do for the moment, although I'd rather the whole
77                #URI was self consistent ...
78                if self.FieldStorage.has_key('uri'):
79                        self.uri=self.FieldStorage['uri'].value
80                else: 
81                        return self.error('No valid URI')
82                try:
83                        self.b=StubB(self.uri)
84                except 'NotFound':
85                        return self.error('URI cannot be retrieved from DataBase')
86                       
87                if EvaluateCredentials(self.ac,self.uri):
88                        #we can show the user the page
89                        return self.b.toHTML()
90                else:
91                        return self.error('Not Allowed')
92               
93        def error(self,message):
94                ''' Construct a nice formal response with appropriate HTML headers '''
95                return '<error>%s</error>'%message
96               
Note: See TracBrowser for help on using the repository browser.